]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Make the fake sequence for braces highly unlikely (addressing #6478).
[lyx.git] / src / Cursor.cpp
index 5e8843245f89ec0e298d3309ce5c5eb2b97cdd25..acc3f0e8e59a4d3b783bd94003371dac0f532c73 100644 (file)
@@ -254,8 +254,8 @@ bool bruteFind3(Cursor & cur, int x, int y, bool up)
 Cursor::Cursor(BufferView & bv)
        : DocIterator(&bv.buffer()), bv_(&bv), anchor_(),
          x_target_(-1), textTargetOffset_(0),
-         selection_(false), mark_(false), logicalpos_(false),
-         current_font(inherit_font)
+         selection_(false), mark_(false), word_selection_(false),
+         logicalpos_(false), current_font(inherit_font)
 {}
 
 
@@ -336,8 +336,10 @@ void Cursor::dispatch(FuncRequest const & cmd0)
                LYXERR(Debug::DEBUG, "Cursor::dispatch: (AtPoint) cmd: "
                        << cmd0 << endl << *this);
                nextInset()->dispatch(*this, tmpcmd);
-               if (result().dispatched())
+               if (result().dispatched()) {
+                       buffer()->undo().endUndoGroup();
                        return;
+               }
        }
 
        // store some values to be used inside of the handlers
@@ -483,8 +485,14 @@ void Cursor::resetAnchor()
 
 void Cursor::setCursorToAnchor()
 {
-       if (selection())
-               setCursor(anchor_);
+       if (selection()) {
+               DocIterator normal = anchor_;
+               while (depth() < normal.depth())
+                       normal.pop_back();
+               if (depth() < anchor_.depth() && top() <= anchor_[depth() - 1])
+                       ++normal.pos();
+               setCursor(normal);
+       }
 }
 
 
@@ -1059,6 +1067,7 @@ void Cursor::setSelection(DocIterator const & where, int n)
 void Cursor::clearSelection()
 {
        setSelection(false);
+       setWordSelection(false);
        setMark(false);
        resetAnchor();
 }
@@ -1303,7 +1312,7 @@ void Cursor::niceInsert(docstring const & t, Parse::flags f, bool enter)
 {
        MathData ar(buffer());
        asArray(t, ar, f);
-       if (ar.size() == 1 && (selection() || enter))
+       if (ar.size() == 1 && (enter || selection()))
                niceInsert(ar[0]);
        else
                insert(ar);
@@ -1336,6 +1345,8 @@ void Cursor::insert(MathData const & ar)
                cap::eraseSelection(*this);
        cell().insert(pos(), ar);
        pos() += ar.size();
+       // FIXME audit setBuffer/updateLabels calls
+       inset().setBuffer(bv_->buffer());
 }
 
 
@@ -2135,9 +2146,12 @@ Font Cursor::getFont() const
 
 bool Cursor::fixIfBroken()
 {
-       if (DocIterator::fixIfBroken()) {
-                       clearSelection();
-                       return true;
+       bool const broken_cursor = DocIterator::fixIfBroken();
+       bool const broken_anchor = anchor_.fixIfBroken();
+       
+       if (broken_cursor || broken_anchor) {
+               clearSelection();
+               return true;
        }
        return false;
 }