]> git.lyx.org Git - features.git/blobdiff - src/Text3.cpp
Do not allow pasting backslashes in macro names
[features.git] / src / Text3.cpp
index bacc808b06518185be97141e35dd2157ed4fc7be..8bbac0eee23d72130b13b5e8ce6e143c98c623bb 100644 (file)
@@ -915,12 +915,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_UP:
        case LFUN_DOWN: {
                // stop/start the selection
-               bool const select = cmd.action() == LFUN_DOWN_SELECT
-                                       || cmd.action() == LFUN_UP_SELECT;
+               bool select = cmd.action() == LFUN_DOWN_SELECT ||
+                       cmd.action() == LFUN_UP_SELECT;
+
                // move cursor up/down
-               bool const up = cmd.action() == LFUN_UP_SELECT || cmd.action() == LFUN_UP;
+               bool up = cmd.action() == LFUN_UP_SELECT || cmd.action() == LFUN_UP;
+               bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
 
-               if (!cur.atFirstOrLastRow(up)) {
+               if (!atFirstOrLastRow) {
                        needsUpdate |= cur.selHandle(select);
                        cur.upDownInText(up, needsUpdate);
                        needsUpdate |= cur.beforeDispatchCursor().inMathed();
@@ -936,35 +938,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                        cur.forceBufferUpdate();
                                break;
                        }
-                       needsUpdate |= cur.selHandle(select);
-                       bool const can_move = cur.upDownInText(up, needsUpdate);
-                       // if the cursor can be moved up or down at an upper level,
-                       // delegate the dispatch to next level. Otherwise, we are
-                       // done.
-                       if (can_move) {
-                               cmd = FuncRequest(up ? LFUN_FINISHED_UP : LFUN_FINISHED_DOWN);
-                               cur.undispatched();
-                       }
-               }
-
-               break;
-       }
-
-       case LFUN_FINISHED_UP:
-       case LFUN_FINISHED_DOWN: {
-               // move cursor up/down
-               bool const up = cmd.action() == LFUN_FINISHED_UP;
 
-               if (!cur.atFirstOrLastRow(up)) {
+                       // if the cursor cannot be moved up or down do not remove
+                       // the selection right now, but wait for the next dispatch.
+                       if (select)
+                               needsUpdate |= cur.selHandle(select);
                        cur.upDownInText(up, needsUpdate);
-                       needsUpdate |= cur.beforeDispatchCursor().inMathed();
-               } else {
-                       bool const can_move = cur.upDownInText(up, needsUpdate);
-                       // if the cursor can be moved up or down and we are not
-                       // moving cusor at top level, wait for the next dispatch.
-                       // Otherwise, we are done.
-                       if (can_move)
-                               cur.undispatched();
+                       cur.undispatched();
                }
 
                break;
@@ -1875,8 +1855,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                bvcur.resetAnchor();
                        if (!bv->mouseSetCursor(cur, cmd.modifier() == ShiftModifier))
                                cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
-                       if (bvcur.wordSelection())
-                               selectWord(bvcur, WHOLE_WORD);
+                       // FIXME: move this to mouseSetCursor?
+                       if (bvcur.wordSelection() && bvcur.inTexted())
+                               expandWordSel(bvcur);
                        break;
 
                case mouse_button::button2:
@@ -1944,6 +1925,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                // We continue with our existing selection or start a new one, so don't
                // reset the anchor.
                bvcur.setCursor(cur);
+               if (bvcur.wordSelection() && bvcur.inTexted())
+                       expandWordSel(bvcur);
                bvcur.selection(true);
                bvcur.setCurrentFont();
                if (cur.top() == old) {
@@ -3181,15 +3164,22 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                break;
        case LFUN_FLEX_INSERT: {
                code = FLEX_CODE;
-               string s = cmd.getArg(0);
-               InsetLayout il =
-                       cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
-               if (il.lyxtype() != InsetLyXType::CHARSTYLE &&
-                   il.lyxtype() != InsetLyXType::CUSTOM &&
-                   il.lyxtype ()!= InsetLyXType::STANDARD)
+               docstring s = from_utf8(cmd.getArg(0));
+               // Prepend "Flex:" prefix if not there
+               if (!prefixIs(s, from_ascii("Flex:")))
+                       s = from_ascii("Flex:") + s;
+               if (!cur.buffer()->params().documentClass().hasInsetLayout(s))
                        enable = false;
-               break;
+               else {
+                       InsetLyXType ilt =
+                               cur.buffer()->params().documentClass().insetLayout(s).lyxtype();
+                       if (ilt != InsetLyXType::CHARSTYLE
+                           && ilt != InsetLyXType::CUSTOM
+                           && ilt != InsetLyXType::STANDARD)
+                               enable = false;
                }
+               break;
+       }
        case LFUN_BOX_INSERT:
                code = BOX_CODE;
                break;
@@ -3575,8 +3565,10 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                docstring const req_layout = ignoreautonests ? from_utf8(cmd.getArg(0)) : cmd.argument();
                docstring const layout = resolveLayout(req_layout, cur);
 
-               enable = !owner_->forcePlainLayout() && !layout.empty();
-               status.setOnOff(!owner_->forcePlainLayout() && isAlreadyLayout(layout, cur));
+               // FIXME: make this work in multicell selection case
+               enable = !owner_->forcePlainLayout() && !layout.empty() && !cur.selIsMultiCell();
+               status.setOnOff(!owner_->forcePlainLayout() && !cur.selIsMultiCell()
+                               && isAlreadyLayout(layout, cur));
                break;
        }