]> git.lyx.org Git - features.git/commitdiff
More fixes to cursor handling with boundary
authorJürgen Vigna <jug@sad.it>
Sat, 16 Jul 2005 23:54:32 +0000 (23:54 +0000)
committerJürgen Vigna <jug@sad.it>
Sat, 16 Jul 2005 23:54:32 +0000 (23:54 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10263 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/text2.C
src/text3.C

index 2a8e2d075c0d7993e9a236e1e063689f316b301a..93495cd67f1cd33fc975966b4c0e469c5c7628cc 100644 (file)
@@ -1,3 +1,12 @@
+2005-07-17  Juergen Vigna  <jug@lyx.org>
+
+       * text2.C (getColumnNearX, cursorRight, cursorLeft, cursorHome,
+                  cursorEnd):
+       more fixes for boundary handling
+
+       * text3.C (dispatch): don't reset cursor if boundary has changed
+       on cursor movement.
+
 2005-07-16  Juergen Vigna  <jug@lyx.org>
 
        * text2.C (getColumnNearX): hopefully got it right now,
index 4e9b9fd00a8cfde0d332fdab40bc1f422ac2edff..d4e7666b10aedc6ffb55f764e8a03cf7f75abe7b 100644 (file)
@@ -481,7 +481,11 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
 void LyXText::cursorHome(LCursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
-       setCursor(cur, cur.pit(), cur.textRow().pos());
+       Paragraph const & par = cur.paragraph();
+       if (cur.boundary() && cur.pos())
+               setCursor(cur, cur.pit(), par.getRow(cur.pos()-1).pos());
+       else
+               setCursor(cur, cur.pit(), cur.textRow().pos());
 }
 
 
@@ -489,10 +493,17 @@ void LyXText::cursorEnd(LCursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
        // if not on the last row of the par, put the cursor before
-       // the final space
-// FIXME: does this final space exist?
-       pos_type const end = cur.textRow().endpos();
-       setCursor(cur, cur.pit(), end == cur.lastpos() ? end : end - 1);
+       // the final space exept if I have a spanning inset or one string
+       // is so long that we force a break.
+       pos_type end = cur.textRow().endpos();
+       bool boundary = false;
+       if (!cur.paragraph().isLineSeparator(end-1) &&
+           !cur.paragraph().isNewline(end-1))
+       {
+               boundary = true;
+       } else if (end != cur.lastpos())
+               --end;
+       setCursor(cur, cur.pit(), end, true, boundary);
 }
 
 
@@ -830,6 +841,8 @@ pos_type LyXText::getColumnNearX(pit_type const pit,
                }
        }
 
+// I believe this code is not needed anymore (Jug 20050717)
+#if 0
        // The following code is necessary because the cursor position past
        // the last char in a row is logically equivalent to that before
        // the first char in the next row. That's why insets causing row
@@ -854,14 +867,15 @@ pos_type LyXText::getColumnNearX(pit_type const pit,
            && par.getInset(end - 1)->display()) {
                c = end - 1;
        }
+#endif
 
        x = int(tmpx) + xo;
        int const col = c - row.pos();
 
-        if (end == par.size())
+        if (!c || end == par.size())
                 return col;
 
-       if (!col && !par.isLineSeparator(c-1) && !par.isNewline(c-1)) {
+       if (c==end && !par.isLineSeparator(c-1) && !par.isNewline(c-1)) {
                boundary = true;
                return col;
        }
@@ -979,6 +993,13 @@ bool LyXText::checkAndActivateInset(LCursor & cur, bool front)
 
 bool LyXText::cursorLeft(LCursor & cur)
 {
+       if (!cur.boundary() &&
+           cur.textRow().pos() == cur.pos() &&
+           !cur.paragraph().isLineSeparator(cur.pos()-1) &&
+           !cur.paragraph().isNewline(cur.pos()-1))
+       {
+               return setCursor(cur, cur.pit(), cur.pos(), true, true);
+       }
        if (cur.pos() != 0) {
                bool boundary = cur.boundary();
                bool updateNeeded = setCursor(cur, cur.pit(), cur.pos() - 1, true, false);
@@ -1008,7 +1029,13 @@ bool LyXText::cursorRight(LCursor & cur)
        if (cur.pos() != cur.lastpos()) {
                bool updateNeeded = false;
                if (!checkAndActivateInset(cur, true)) {
-                       updateNeeded |= setCursor(cur, cur.pit(), cur.pos() + 1, true, false);
+                       if (cur.textRow().endpos() == (cur.pos() + 1) &&
+                           !cur.paragraph().isLineSeparator(cur.pos()) &&
+                           !cur.paragraph().isNewline(cur.pos()))
+                       {
+                               cur.boundary(true);
+                       }
+                       updateNeeded |= setCursor(cur, cur.pit(), cur.pos() + 1, true, cur.boundary());
                        if (false && bidi.isBoundary(cur.buffer(), cur.paragraph(),
                                                         cur.pos()))
                                updateNeeded |= setCursor(cur, cur.pit(), cur.pos(), true, true);
index caf6509701ecd8f4e3f95cc22538e7c9cb6b9b31..b69c806566298b5a1f7b0a860cc93e9e4a2dae21 100644 (file)
@@ -429,7 +429,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                        needsUpdate = cursorRight(cur);
                else
                        needsUpdate = cursorLeft(cur);
-               if (oldTopSlice == cur.top()) {
+               if (!needsUpdate && oldTopSlice == cur.top() &&
+                   cur.boundary() == oldBoundary)
+               {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_LEFT);
                }
@@ -441,7 +443,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
                cur.selHandle(cmd.action == LFUN_UPSEL);
                needsUpdate = cursorUp(cur);
-               if (oldTopSlice == cur.top()) {
+               if (!needsUpdate && oldTopSlice == cur.top() &&
+                   cur.boundary() == oldBoundary)
+               {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_UP);
                }
@@ -453,7 +457,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
                cur.selHandle(cmd.action == LFUN_DOWNSEL);
                needsUpdate = cursorDown(cur);
-               if (oldTopSlice == cur.top()) {
+               if (!needsUpdate && oldTopSlice == cur.top() &&
+                   cur.boundary() == oldBoundary)
+               {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_DOWN);
                }