]> git.lyx.org Git - features.git/commitdiff
Set language to OS input language when moving cursor
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 19 Jul 2019 09:46:35 +0000 (11:46 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:37 +0000 (15:48 +0200)
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
src/BufferView.h
src/Cursor.cpp
src/Cursor.h
src/Language.cpp
src/frontends/qt4/GuiApplication.cpp

index 40d8643363763547574d93a1c887a4cdbf765fe5..97adab820cfcec1599658a14d3a6dc15f5e16b56 100644 (file)
@@ -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();
index bb75c160c66e83b2e53c3d0736d449362ff1e2cc..40dd0d29c352a4496ef0b3301b2910fda1c67226 100644 (file)
@@ -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
index 48a74f3bddbb3ed57bf70836a8886d36bf11efcb..947eeb1d536dd9141a9b59dfe74ce0a6d5677656 100644 (file)
@@ -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 <sstream>
 #include <limits>
 #include <map>
@@ -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())
index 35d2fc97680dcfc9989c50a29f18f3ed13a9c2c5..4091790603d8b325e05310503b6c7bf7b98a7f54 100644 (file)
@@ -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();
 
        /**
index a1f356247b00616cb645068fca9ff6aebb5d5472..ccac6975690152452f6a674bbb97e2cc16179cd3 100644 (file)
@@ -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;
 }
index dd343241c55379f87ff785aec740d636ab055963..08c10c454fc2141ba163aa6f92a186b4fca781b9 100644 (file)
@@ -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