]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Set correctly the spacing between atoms in MathData
[lyx.git] / src / Cursor.cpp
index b13b6a56f7f497e973e237770159cecfa834e94d..43984de9c80c78b01f2adceacbed16b06d8870fd 100644 (file)
@@ -194,13 +194,37 @@ void Cursor::reset()
 }
 
 
-// this (intentionally) does neither touch anchor nor selection status
 void Cursor::setCursor(DocIterator const & cur)
 {
        DocIterator::operator=(cur);
 }
 
 
+void Cursor::setCursorSelectionTo(DocIterator dit)
+{
+       size_t i = 0;
+       // normalise dit
+       while (i < dit.depth() && i < anchor_.depth() && dit[i] == anchor_[i])
+               ++i;
+       if (i != dit.depth()) {
+               // otherwise the cursor is already normal
+               if (i == anchor_.depth())
+                       // dit is a proper extension of the anchor_
+                       dit.cutOff(i - 1);
+               else if (i + 1 < dit.depth()) {
+                       // one has dit[i] != anchor_[i] but either dit[i-1] == anchor_[i-1]
+                       // or i == 0. Remove excess.
+                       dit.cutOff(i);
+                       if (dit[i] > anchor_[i])
+                               // place dit after the inset it was in
+                               ++dit.pos();
+               }
+       }
+       setCursor(dit);
+       setSelection();
+}
+
+
 void Cursor::setCursorToAnchor()
 {
        if (selection()) {
@@ -1455,7 +1479,7 @@ bool Cursor::macroModeClose()
        bool keep_mathmode = it != words.end() && (it->second.inset == "font"
                                                || it->second.inset == "oldfont"
                                                || it->second.inset == "mbox");
-       bool ert_macro = !user_macro && it == words.end();
+       bool ert_macro = !user_macro && it == words.end() && atomAsMacro;
 
        if (in && in->currentMode() == Inset::TEXT_MODE
            && atom.nucleus()->currentMode() == Inset::MATH_MODE
@@ -2097,6 +2121,7 @@ Font Cursor::getFont() const
        // The logic here should more or less match to the
        // Cursor::setCurrentFont logic, i.e. the cursor height should
        // give a hint what will happen if a character is entered.
+       // FIXME: this is not the case, what about removing this method ? (see #10478).
 
        // HACK. far from being perfect...