]> git.lyx.org Git - features.git/commitdiff
Honor key bindings for commit string
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 16 May 2022 20:16:53 +0000 (22:16 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 13 Jun 2022 09:22:50 +0000 (11:22 +0200)
When the commit string from the inputMethodEvent can be interpreted as
characters bound to some action, dispatch this action instead of
inserting the string.

This is useful on an international keyboard, when diaresis+space gives
a plain double quote. It is better in this case to enter a smart
quote.

Adapted from a patch from Daniel Ramoeller <d.lyx@web.de>.

Fixes bug #10377.

src/frontends/KeySymbol.h
src/frontends/qt/GuiKeySymbol.cpp
src/frontends/qt/GuiWorkArea.cpp

index cdb5f8f3a111573005143faf302b1f30583b9ad7..7e67536aa5146c61258a0b6f6d47566470590bec 100644 (file)
@@ -33,6 +33,9 @@ public:
        /// Initialize with the name of a key. F. ex. "space" or "a"
        void init(std::string const & symbolname);
 
+       /// Initialize with some platform specific sym value
+       void init(int key);
+
        /// Is this a valid key?
        bool isOK() const;
 
index 77e3dc35d0a9e0829df388e6ad1229c437cfc980..551ea8dc6dbe4de27fdda1312d4a2f122acb8495 100644 (file)
@@ -752,6 +752,14 @@ void KeySymbol::init(string const & symbolname)
 }
 
 
+void KeySymbol::init(int key)
+{
+       key_ = key;
+       text_ = from_utf8(qkey_to_string(key));
+       LYXERR(Debug::KEY, "Init key to " << key_ << ", " << to_utf8(text_));
+}
+
+
 bool KeySymbol::isOK() const
 {
        bool const ok = !(text_.empty() && qkey_to_string(key_).empty());
index e70563bc5a1472725a4e10f39db7057dd9d7e4ed..900273f03877ef46cc024a79ef8002bc3083fd50 100644 (file)
@@ -31,7 +31,9 @@
 #include "Cursor.h"
 #include "Font.h"
 #include "FuncRequest.h"
+#include "KeyMap.h"
 #include "KeySymbol.h"
+#include "KeySequence.h"
 #include "LyX.h"
 #include "LyXRC.h"
 #include "LyXVC.h"
@@ -47,7 +49,6 @@
 
 #include "frontends/Application.h"
 #include "frontends/CaretGeometry.h"
-
 #include "frontends/FontMetrics.h"
 #include "frontends/WorkAreaManager.h"
 
@@ -1313,11 +1314,24 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
        LYXERR(Debug::KEY, "preeditString: " << e->preeditString()
                   << " commitString: " << e->commitString());
 
-       // insert the processed text in the document (handles undo)
        if (!e->commitString().isEmpty()) {
-               FuncRequest cmd(LFUN_SELF_INSERT,
-                               qstring_to_ucs4(e->commitString()),
-                               FuncRequest::KEYBOARD);
+               FuncRequest cmd;
+               // take care of commit string assigned to a shortcut
+               // e.g. quotation mark on international keyboard
+               KeySequence keyseq;
+               for (QChar const & ch : e->commitString()) {
+                       KeySymbol keysym;
+                       keysym.init(ch.unicode());
+                       keyseq.addkey(keysym, NoModifier);
+               }
+               cmd = theTopLevelKeymap().getBinding(keyseq);
+
+               if (cmd == FuncRequest::noaction || cmd == FuncRequest::unknown
+                   || cmd.action() == LFUN_SELF_INSERT)
+                       // insert the processed text in the document (handles undo)
+                       cmd = FuncRequest(LFUN_SELF_INSERT, qstring_to_ucs4(e->commitString()));
+
+               cmd.setOrigin(FuncRequest::KEYBOARD);
                dispatch(cmd);
                // FIXME: this is supposed to remove traces from preedit
                // string. Can we avoid calling it explicitly?