]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Update notes.
[lyx.git] / src / Cursor.cpp
index 14e31f922cd4731c8b8820f6c8379df5907b8400..0017e1ae149576b29cdc42ccf9475156691dc127 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)
 {}
 
 
@@ -483,8 +483,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 +1065,7 @@ void Cursor::setSelection(DocIterator const & where, int n)
 void Cursor::clearSelection()
 {
        setSelection(false);
+       setWordSelection(false);
        setMark(false);
        resetAnchor();
 }
@@ -1299,11 +1306,11 @@ void Cursor::insert(Inset * inset0)
 }
 
 
-void Cursor::niceInsert(docstring const & t, Parse::flags f)
+void Cursor::niceInsert(docstring const & t, Parse::flags f, bool enter)
 {
        MathData ar(buffer());
        asArray(t, ar, f);
-       if (ar.size() == 1)
+       if (ar.size() == 1 && (enter || selection()))
                niceInsert(ar[0]);
        else
                insert(ar);
@@ -1315,7 +1322,7 @@ void Cursor::niceInsert(MathAtom const & t)
        macroModeClose();
        docstring const safe = cap::grabAndEraseSelection(*this);
        plainInsert(t);
-       // enter the new inset and move the contents of the selection if possible
+       // If possible, enter the new inset and move the contents of the selection
        if (t->isActive()) {
                posBackward();
                // be careful here: don't use 'pushBackward(t)' as this we need to
@@ -2163,9 +2170,9 @@ bool notifyCursorLeavesOrEnters(Cursor const & old, Cursor & cur)
        // notify everything on top of the common part in old cursor,
        // but stop if the inset claims the cursor to be invalid now
        for (size_type j = i; j < old.depth(); ++j) {
-               Cursor insetPos = old;
-               insetPos.cutOff(j);
-               if (old[j].inset().notifyCursorLeaves(insetPos, cur))
+               Cursor inset_pos = old;
+               inset_pos.cutOff(j);
+               if (old[j].inset().notifyCursorLeaves(inset_pos, cur))
                        return true;
        }