]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Set language to OS input language when moving cursor
[lyx.git] / src / Cursor.cpp
index 56a9dd872245c62f66f345c3679406f52f61f502..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>
@@ -121,19 +124,19 @@ DocIterator bruteFind(Cursor const & c, int x, int y)
 
 CursorData::CursorData()
        : DocIterator(), anchor_(), selection_(false), mark_(false),
-         word_selection_(false), autocorrect_(false), current_font(inherit_font)
+         word_selection_(false), current_font(inherit_font)
 {}
 
 
 CursorData::CursorData(Buffer * buffer)
        : DocIterator(buffer), anchor_(), selection_(false), mark_(false),
-         word_selection_(false), autocorrect_(false), current_font(inherit_font)
+         word_selection_(false), current_font(inherit_font)
 {}
 
 
 CursorData::CursorData(DocIterator const & dit)
        : DocIterator(dit), anchor_(), selection_(false), mark_(false),
-         word_selection_(false), autocorrect_(false), current_font(inherit_font)
+         word_selection_(false), current_font(inherit_font)
 {}
 
 
@@ -330,6 +333,8 @@ namespace {
 
 docstring parbreak(CursorData const * cur)
 {
+       if (cur->inset().getLayout().parbreakIgnored())
+               return docstring();
        odocstringstream os;
        os << '\n';
        // only add blank line if we're not in a ParbreakIsNewline situation
@@ -607,6 +612,12 @@ void CursorData::endUndoGroup() const
 }
 
 
+void CursorData::splitUndoGroup() const
+{
+       buffer()->undo().splitUndoGroup(*this);
+}
+
+
 void CursorData::recordUndo(pit_type from, pit_type to) const
 {
        buffer()->undo().recordUndo(*this, from, to);
@@ -1762,7 +1773,7 @@ bool Cursor::macroModeClose(bool cancel)
                // we have to resolve the macro here manually and check its arity
                // to put the selection behind it if arity > 0.
                MacroData const * data = buffer()->getMacro(atomAsMacro->name());
-               if (!selection.empty() && data && data->numargs() - data->optionals() > 0) {
+               if (!selection.empty() && data && data->numargs()) {
                        macroArg = true;
                        atomAsMacro->setDisplayMode(InsetMathMacro::DISPLAY_INTERACTIVE_INIT, 1);
                } else
@@ -2388,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();
@@ -2421,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())