mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Honor key bindings for commit string
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.
This commit is contained in:
parent
8fff0cf774
commit
ab54158447
@ -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;
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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?
|
||||
|
Loading…
Reference in New Issue
Block a user