]> git.lyx.org Git - features.git/commitdiff
Fixes to input method handling
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 5 Jul 2018 12:01:56 +0000 (14:01 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 9 Sep 2018 17:43:18 +0000 (19:43 +0200)
The goal of this patch is to make "self-insert <string>" act as a
sequence of individual self-insert calls. Once it is done, the
insertion of the commit string in GuiWorkArea can use that, which
fixes the issues described in bug 11183.

1/ in InsetMathNest, SELF_INSERT is rewritten to be a proper loop of
   interpretChar, instead of inserting the string as characters. This
   solves the issue of interpreting ^ properly.

2/ the text version does not need to be changed (the loop is rewritten
   using a range, though).

3/ Then {{{GuiWorkArea::inputMethodEvent}}} is changed to invoke
   directly self-insert. This removes the update issues.

Fixes bug 11183.

(cherry picked from commit ad5548cfe39a17389ca721aab896e876f2cd4124)

src/Text3.cpp
src/frontends/qt4/GuiWorkArea.cpp
src/mathed/InsetMathNest.cpp
src/mathed/InsetMathNest.h
status.23x

index e13160b2e1d44728d2c9777cbf39f69d3660cdc2..41760b5a7cbf64225f28040c04e9f0efa248ac6d 100644 (file)
@@ -1912,13 +1912,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
                if (lyxrc.auto_region_delete && cur.selection())
                        cutSelection(cur, false, false);
-
                cur.clearSelection();
 
-               docstring::const_iterator cit = cmd.argument().begin();
-               docstring::const_iterator const end = cmd.argument().end();
-               for (; cit != end; ++cit)
-                       bv->translateAndInsert(*cit, this, cur);
+               for (char_type c : cmd.argument())
+                       bv->translateAndInsert(c, this, cur);
 
                cur.resetAnchor();
                moveCursor(cur, false);
index 5835cbd9b63e061f4fa38025978fab506c460d41..4adb155fa2573b2b49bd1d18b53b7ddc5d8daf95 100644 (file)
@@ -1290,12 +1290,13 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
 
        // insert the processed text in the document (handles undo)
        if (!e->commitString().isEmpty()) {
-               d->buffer_view_->cursor().beginUndoGroup();
-               d->buffer_view_->cursor().insert(qstring_to_ucs4(e->commitString()));
+               FuncRequest cmd(LFUN_SELF_INSERT,
+                               qstring_to_ucs4(e->commitString()),
+                               FuncRequest::KEYBOARD);
+               dispatch(cmd);
+               // FIXME: this is supposed to remove traces from preedit
+               // string. Can we avoid calling it explicitely?
                d->buffer_view_->updateMetrics();
-               d->buffer_view_->cursor().endUndoGroup();
-               d->updateCaretGeometry();
-               viewport()->update();
        }
 
        // Hide the caret during the test transformation.
index afe4f062cdc4610e40fca095b361529cc72c8e02..d871660d516620901d563cb8eaaf304452567c23 100644 (file)
@@ -854,40 +854,41 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_SELF_INSERT:
-               if (cmd.argument().size() != 1) {
-                       cur.recordUndoSelection();
-                       docstring const arg = cmd.argument();
-                       if (!interpretString(cur, arg))
-                               cur.insert(arg);
+               // special case first for big delimiters
+               if (cmd.argument().size() != 1 && interpretString(cur, cmd.argument()))
                        break;
-               }
-               // Don't record undo steps if we are in macro mode and thus
-               // cmd.argument is the next character of the macro name.
-               // Otherwise we'll get an invalid cursor if we undo after
-               // the macro was finished and the macro is a known command,
-               // e.g. sqrt. Cursor::macroModeClose replaces in this case
-               // the InsetMathUnknown with name "frac" by an empty
-               // InsetMathFrac -> a pos value > 0 is invalid.
-               // A side effect is that an undo before the macro is finished
-               // undoes the complete macro, not only the last character.
-               // At the time we hit '\' we are not in macro mode, still.
-               if (!cur.inMacroMode())
-                       cur.recordUndoSelection();
 
-               // spacial handling of space. If we insert an inset
-               // via macro mode, we want to put the cursor inside it
-               // if relevant. Think typing "\frac<space>".
-               if (cmd.argument()[0] == ' '
-                   && cur.inMacroMode() && cur.macroName() != "\\"
-                   && cur.macroModeClose() && cur.pos() > 0) {
-                       MathAtom const atom = cur.prevAtom();
-                       if (atom->asNestInset() && atom->isActive()) {
-                               cur.posBackward();
-                               cur.pushBackward(*cur.nextInset());
+               for (char_type c : cmd.argument()) {
+                       // Don't record undo steps if we are in macro mode and thus
+                       // cmd.argument is the next character of the macro name.
+                       // Otherwise we'll get an invalid cursor if we undo after
+                       // the macro was finished and the macro is a known command,
+                       // e.g. sqrt. Cursor::macroModeClose replaces in this case
+                       // the InsetMathUnknown with name "frac" by an empty
+                       // InsetMathFrac -> a pos value > 0 is invalid.
+                       // A side effect is that an undo before the macro is finished
+                       // undoes the complete macro, not only the last character.
+                       // At the time we hit '\' we are not in macro mode, still.
+                       if (!cur.inMacroMode())
+                               cur.recordUndoSelection();
+
+                       // special handling of space. If we insert an inset
+                       // via macro mode, we want to put the cursor inside it
+                       // if relevant. Think typing "\frac<space>".
+                       if (c == ' '
+                               && cur.inMacroMode() && cur.macroName() != "\\"
+                               && cur.macroModeClose() && cur.pos() > 0) {
+                               MathAtom const atom = cur.prevAtom();
+                               if (atom->asNestInset() && atom->isActive()) {
+                                       cur.posBackward();
+                                       cur.pushBackward(*cur.nextInset());
+                               }
+                       } else if (!interpretChar(cur, c)) {
+                               cmd = FuncRequest(LFUN_FINISHED_FORWARD);
+                               cur.undispatched();
+                               // FIXME: can we avoid skipping the end of the string?
+                               break;
                        }
-               } else if (!interpretChar(cur, cmd.argument()[0])) {
-                       cmd = FuncRequest(LFUN_FINISHED_FORWARD);
-                       cur.undispatched();
                }
                break;
 
@@ -1890,6 +1891,7 @@ bool InsetMathNest::interpretString(Cursor & cur, docstring const & str)
                                prev = prev.substr(1);
                                latexkeys const * l = in_word_set(prev);
                                if (l && l->inset == "big") {
+                                       cur.recordUndoSelection();
                                        cur.cell()[cur.pos() - 1] =
                                                MathAtom(new InsetMathBig(prev, str));
                                        return true;
index 3d4977d63c44e38a9d42c4dbf954bd8953760259..929a5f0890a738a62f24782f1246746233af3094 100644 (file)
@@ -166,7 +166,7 @@ protected:
 public:
        /// interpret \p str and insert the result at the current position of
        /// \p cur if it is something known. Return whether \p cur was
-       /// inserted.
+       /// inserted. Handles undo.
        virtual bool interpretString(Cursor & cur, docstring const & str);
 
 private:
index dbe3a4621dcbda60e71e48496e8b0d0f190dfd5f..c90ed2ee4f49fdb0bd9b80bd30560c24b9373465 100644 (file)
@@ -88,6 +88,8 @@ What's new
 
 - Fix display of percent sign with numbers in RTL (bug 4057).
 
+- Fix issues with dead key accents (bug 11183).
+
 
 
 * INTERNALS