]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
* Text3.cpp (doDispatch): fix the behaviour of word-delete-forward,
[lyx.git] / src / Text3.cpp
index d3a4d376e69bc3b22f63a56b7c65c83fa749916f..1b9618654a85f9fdc2e46449c196e463d0d5e59a 100644 (file)
@@ -79,7 +79,6 @@ using cap::cutSelection;
 using cap::pasteFromStack;
 using cap::pasteClipboard;
 using cap::replaceSelection;
-using cap::saveSelection;
 
 using support::isStrUnsignedInt;
 using support::token;
@@ -119,8 +118,6 @@ namespace {
        {
                if (selecting || cur.mark())
                        cur.setSelection();
-               saveSelection(cur);
-               cur.bv().switchKeyMap();
        }
 
 
@@ -438,20 +435,26 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_WORD_DELETE_FORWARD:
-               cur.clearSelection();
-               deleteWordForward(cur);
+               if (cur.selection()) {
+                       cutSelection(cur, true, false);
+               } else
+                       deleteWordForward(cur);
                finishChange(cur, false);
                break;
 
        case LFUN_WORD_DELETE_BACKWARD:
-               cur.clearSelection();
-               deleteWordBackward(cur);
+               if (cur.selection()) {
+                       cutSelection(cur, true, false);
+               } else
+                       deleteWordBackward(cur);
                finishChange(cur, false);
                break;
 
        case LFUN_LINE_DELETE:
-               cur.clearSelection();
-               deleteLineForward(cur);
+               if (cur.selection()) {
+                       cutSelection(cur, true, false);
+               } else
+                       deleteLineForward(cur);
                finishChange(cur, false);
                break;
 
@@ -489,8 +492,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                && cur.boundary() == oldBoundary) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
-               } else if (cur.selection())
-                       saveSelection(cur);
+               }
                break;
 
        case LFUN_CHAR_BACKWARD:
@@ -507,31 +509,30 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_LEFT);
                }
-               if (cur.selection())
-                       saveSelection(cur);
                break;
 
+       case LFUN_UP_SELECT:
+       case LFUN_DOWN_SELECT:
        case LFUN_UP:
-       case LFUN_UP_SELECT: {
-               //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
-               needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
-               bool const successful = cur.upDownInText(true, needsUpdate);
-               if (!successful)
-                       cur.undispatched();
-               if (cur.selection())
-                       saveSelection(cur);
-               break;
-       }
-
-       case LFUN_DOWN:
-       case LFUN_DOWN_SELECT: {
-               //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
-               needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
-               bool const successful = cur.upDownInText(false, needsUpdate);
-               if (!successful)
+       case LFUN_DOWN: {
+               // stop/start the selection
+               bool select = cmd.action == LFUN_DOWN_SELECT ||
+                       cmd.action == LFUN_UP_SELECT;
+               cur.selHandle(select);
+               
+               // move cursor up/down
+               bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
+               bool const successful = cur.upDownInText(up, needsUpdate);
+               if (successful) {
+                       // notify insets which were left and get their update flags 
+                       notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
+                       cur.fixIfBroken();
+                       
+                       // redraw if you leave mathed (for the decorations)
+                       needsUpdate |= cur.beforeDispatchCursor().inMathed();
+               } else
                        cur.undispatched();
-               if (cur.selection())
-                       saveSelection(cur);
+               
                break;
        }
 
@@ -539,16 +540,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_PARAGRAPH_UP_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
                needsUpdate |= cursorUpParagraph(cur);
-               if (cur.selection())
-                       saveSelection(cur);
                break;
 
        case LFUN_PARAGRAPH_DOWN:
        case LFUN_PARAGRAPH_DOWN_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
                needsUpdate |= cursorDownParagraph(cur);
-               if (cur.selection())
-                       saveSelection(cur);
                break;
 
        case LFUN_SCREEN_UP:
@@ -559,8 +556,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                else {
                        cursorPrevious(cur);
                }
-               if (cur.selection())
-                       saveSelection(cur);
                break;
 
        case LFUN_SCREEN_DOWN:
@@ -572,8 +567,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                else {
                        cursorNext(cur);
                }
-               if (cur.selection())
-                       saveSelection(cur);
                break;
 
        case LFUN_LINE_BEGIN:
@@ -586,8 +579,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_LINE_END_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
                needsUpdate |= cursorEnd(cur);
-               if (cur.selection())
-                       saveSelection(cur);
                break;
 
        case LFUN_WORD_FORWARD:
@@ -597,8 +588,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        needsUpdate |= cursorLeftOneWord(cur);
                else
                        needsUpdate |= cursorRightOneWord(cur);
-               if (cur.selection())
-                       saveSelection(cur);
                break;
 
        case LFUN_WORD_BACKWARD:
@@ -608,8 +597,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        needsUpdate |= cursorRightOneWord(cur);
                else
                        needsUpdate |= cursorLeftOneWord(cur);
-               if (cur.selection())
-                       saveSelection(cur);
                break;
 
        case LFUN_WORD_SELECT: {
@@ -679,7 +666,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        cutSelection(cur, true, false);
                        singleParUpdate = false;
                }
-               bv->switchKeyMap();
                break;
 
        case LFUN_DELETE_BACKWARD_SKIP:
@@ -700,14 +686,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                cap::replaceSelection(cur);
                breakParagraph(cur, 0);
                cur.resetAnchor();
-               bv->switchKeyMap();
                break;
 
        case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
                cap::replaceSelection(cur);
                breakParagraph(cur, 1);
                cur.resetAnchor();
-               bv->switchKeyMap();
                break;
 
        case LFUN_BREAK_PARAGRAPH_SKIP: {
@@ -719,7 +703,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                else
                        breakParagraph(cur, 0);
                cur.resetAnchor();
-               bv->switchKeyMap();
                break;
        }
 
@@ -862,7 +845,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                }
                bv->buffer()->errors("Paste");
                cur.clearSelection(); // bug 393
-               bv->switchKeyMap();
                finishUndo();
                break;
 
@@ -949,11 +931,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                }
 
                if (change_layout) {
-                       current_layout = layout;
                        setLayout(cur, layout);
                        // inform the GUI that the layout has changed.
                        bv->layoutChanged(layout);
-                       bv->switchKeyMap();
                }
                break;
        }
@@ -976,7 +956,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                docstring hexstring = cmd.argument();
                if (lyx::support::isHex(hexstring)) {
                        char_type c = lyx::support::hexToInt(hexstring);
-                       if (c > 32 && c < 0x10ffff) {
+                       if (c >= 32 && c < 0x10ffff) {
                                lyxerr << "Inserting c: " << c << endl;
                                docstring s = docstring(1, c);
                                lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
@@ -1037,7 +1017,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        cursorEnd(cur);
                        cur.setSelection();
                        bv->cursor() = cur;
-                       saveSelection(cur);
                }
                break;
 
@@ -1075,7 +1054,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
                                bv->buffer()->errors("Paste");
                                cur.clearSelection(); // bug 393
-                               bv->switchKeyMap();
                                bv->buffer()->markDirty();
                                finishUndo();
                        } else {
@@ -1150,13 +1128,11 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                // but bvcur is current mouse position
                                Cursor & bvcur = cur.bv().cursor();
                                bvcur.selection() = true;
-                               saveSelection(bvcur);
                        }
                        needsUpdate = false;
                        cur.noUpdate();
                }
 
-               bv->switchKeyMap();
                break;
        }
 
@@ -1170,9 +1146,17 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                // "auto_region_delete", which defaults to
                // true (on).
 
-               if (lyxrc.auto_region_delete)
-                       if (cur.selection())
-                               cutSelection(cur, false, false);
+               if (lyxrc.auto_region_delete && cur.selection()) {
+                       cutSelection(cur, false, false);
+                       // When change tracking is set to off, the metrics update
+                       // mechanism correctly detects if a full update is needed or not.
+                       // This detection fails when a selection spans multiple rows and
+                       // change tracking is enabled because the paragraph metrics stays
+                       // the same. In this case, we force the full update:
+                       // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
+                       if (cur.buffer().params().trackChanges)
+                               cur.updateFlags(Update::Force);
+               }
 
                cur.clearSelection();
                Font const old_font = real_current_font;
@@ -1180,8 +1164,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                docstring::const_iterator cit = cmd.argument().begin();
                docstring::const_iterator end = cmd.argument().end();
                for (; cit != end; ++cit)
-                       bv->getIntl().getTransManager().
-                               translateAndInsert(*cit, this, cur);
+                       bv->translateAndInsert(*cit, this, cur);
 
                cur.resetAnchor();
                moveCursor(cur, false);
@@ -1449,7 +1432,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                Font font(Font::ALL_IGNORE);
                font.setLanguage(lang);
                toggleAndShow(cur, this, font);
-               bv->switchKeyMap();
                break;
        }
 
@@ -1524,8 +1506,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                theLyXFunc().handleKeyFunc(cmd.action);
                if (!cmd.argument().empty())
                        // FIXME: Are all these characters encoded in one byte in utf8?
-                       bv->getIntl().getTransManager()
-                               .translateAndInsert(cmd.argument()[0], this, cur);
+                       bv->translateAndInsert(cmd.argument()[0], this, cur);
                break;
 
        case LFUN_FLOAT_LIST: {
@@ -1598,7 +1579,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_ESCAPE:
                if (cur.selection()) {
                        cur.selection() = false;
-                       saveSelection(cur);
                } else {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
@@ -1979,6 +1959,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_MATH_MATRIX:
        case LFUN_MATH_DELIM:
        case LFUN_MATH_BIGDELIM:
+       case LFUN_MATH_INSERT:
        case LFUN_MATH_SUBSCRIPT:
        case LFUN_MATH_SUPERSCRIPT:
        case LFUN_FONT_DEFAULT: