From a619d282d878d93df6dee432d7d67d168a6f0d6a Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 19 Jul 2019 11:46:35 +0200 Subject: [PATCH] Set language to OS input language when moving cursor Instead of setting language from context when moving the cursor, set it to the OS input language. This behavior will probably need to be controlled by a preference, since not everybody changes keyboard mapping when changing language. This required to move BufferView::setCursorLanguage to Cursor::setLanguageFromInput(). --- src/BufferView.cpp | 11 ----------- src/BufferView.h | 6 ------ src/Cursor.cpp | 18 ++++++++++++++++++ src/Cursor.h | 8 +++++++- src/Language.cpp | 2 +- src/frontends/qt4/GuiApplication.cpp | 6 +++--- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 40d8643363..97adab820c 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -2739,17 +2739,6 @@ Cursor const & BufferView::cursor() const } -void BufferView::setCursorLanguage(std::string const & code) -{ - Language const * lang = languages.getFromCode(code, buffer_.getLanguages()); - if (lang) { - d->cursor_.current_font.setLanguage(lang); - d->cursor_.real_current_font.setLanguage(lang); - } else - LYXERR0("setCursorLanguage: unknown language code " << code); -} - - bool BufferView::singleParUpdate() { Text & buftext = buffer_.text(); diff --git a/src/BufferView.h b/src/BufferView.h index bb75c160c6..40dd0d29c3 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -267,12 +267,6 @@ public: /// sets cursor. /// This is used when handling LFUN_MOUSE_PRESS. bool mouseSetCursor(Cursor & cur, bool select = false); - /// Set the cursor language from language code. - /* Considers first exact math with the codes used in the document, - * then approximate match among the same list, and finally exact - * or partial match with the whole list of languages. - */ - void setCursorLanguage(std::string const & code); /// sets the selection. /* When \c backwards == false, set anchor diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 48a74f3bdd..947eeb1d53 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -22,6 +22,7 @@ #include "DispatchResult.h" #include "FuncCode.h" #include "FuncRequest.h" +#include "Language.h" #include "Layout.h" #include "LyXAction.h" #include "LyXRC.h" @@ -51,6 +52,8 @@ #include "mathed/MathFactory.h" #include "mathed/InsetMathMacro.h" +#include "frontends/Application.h" + #include #include #include @@ -2396,6 +2399,18 @@ bool notifyCursorLeavesOrEnters(Cursor const & old, Cursor & cur) } +void Cursor::setLanguageFromInput() +{ + string const & code = theApp()->inputLanguageCode(); + Language const * lang = languages.getFromCode(code, buffer()->getLanguages()); + if (lang) { + current_font.setLanguage(lang); + real_current_font.setLanguage(lang); + } else + LYXERR0("setLanguageFromCode: unknown language code " << code); +} + + void Cursor::setCurrentFont() { CursorSlice const & cs = innerTextSlice(); @@ -2429,6 +2444,9 @@ void Cursor::setCurrentFont() current_font = par.getFontSettings(bufparams, cpos); real_current_font = tm.displayFont(cpit, cpos); + // set language to input language + setLanguageFromInput(); + // special case for paragraph end if (cs.pos() == lastpos() && tm.isRTLBoundary(cpit, cs.pos()) diff --git a/src/Cursor.h b/src/Cursor.h index 35d2fc9768..4091790603 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -279,7 +279,13 @@ public: /// get the resut of the last dispatch DispatchResult const & result() const; - /// + /// Set the cursor language from current input method language + /* Considers first exact math with the codes used in the document, + * then approximate match among the same list, and finally exact + * or partial match with the whole list of languages. + */ + void setLanguageFromInput(); + /// Set the current font of the cursor from its location. void setCurrentFont(); /** diff --git a/src/Language.cpp b/src/Language.cpp index a1f356247b..ccac697569 100644 --- a/src/Language.cpp +++ b/src/Language.cpp @@ -390,7 +390,7 @@ Match match(string const & code, Language const & lang) if ((code.size() == 2) && (langcode.size() > 2) && (code + '_' == langcode.substr(0, 3))) return ApproximateMatch; - if (code.substr(0,2) == langcode.substr(0,2)) + if (code.substr(0,2) == langcode.substr(0,2)) return VeryApproximateMatch; return NoMatch; } diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index dd343241c5..08c10c454f 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -2129,7 +2129,7 @@ string GuiApplication::inputLanguageCode() const QLocale loc = inputMethod()->locale(); #endif //LYXERR0("input lang = " << fromqstr(loc.name())); - return fromqstr(loc.name()); + return loc.name() == "C" ? "en_US" : fromqstr(loc.name()); } @@ -2137,7 +2137,7 @@ void GuiApplication::onLocaleChanged() { //LYXERR0("Change language to " << inputLanguage()->lang()); if (currentView() && currentView()->currentBufferView()) - currentView()->currentBufferView()->setCursorLanguage(inputLanguageCode()); + currentView()->currentBufferView()->cursor().setLanguageFromInput(); } @@ -2749,7 +2749,7 @@ bool GuiApplication::event(QEvent * e) case QEvent::KeyboardLayoutChange: //LYXERR0("keyboard change"); if (currentView() && currentView()->currentBufferView()) - currentView()->currentBufferView()->setCursorLanguage(inputLanguageCode()); + currentView()->currentBufferView()->cursor().setLanguageFromInput(); e->accept(); return true; #endif -- 2.39.5