]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Clean includes using the output of iwyu tool
[lyx.git] / src / Cursor.cpp
index 50d0a220ec1c2936fbe32cdb8503c8d699b4625a..7197b91cf26951477c8515f69915c3bc686dc0d5 100644 (file)
 
 #include <config.h>
 
+#include "Cursor.h"
+
 #include "Buffer.h"
 #include "BufferView.h"
 #include "CoordCache.h"
-#include "Cursor.h"
 #include "CutAndPaste.h"
-#include "DispatchResult.h"
 #include "FuncCode.h"
 #include "FuncRequest.h"
+#include "Language.h"
 #include "Layout.h"
 #include "LyXAction.h"
 #include "LyXRC.h"
 #include "Paragraph.h"
-#include "ParIterator.h"
 #include "Row.h"
 #include "texstream.h"
 #include "Text.h"
 
 #include "support/debug.h"
 #include "support/docstream.h"
-#include "support/ExceptionMessage.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
 
 #include "insets/InsetTabular.h"
-#include "insets/InsetText.h"
 
 #include "mathed/InsetMath.h"
 #include "mathed/InsetMathBrace.h"
@@ -51,6 +49,8 @@
 #include "mathed/MathFactory.h"
 #include "mathed/InsetMathMacro.h"
 
+#include "frontends/Application.h"
+
 #include <sstream>
 #include <limits>
 #include <map>
@@ -121,19 +121,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 +330,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
@@ -342,7 +344,7 @@ docstring parbreak(CursorData const * cur)
 }
 
 
-docstring CursorData::selectionAsString(bool with_label) const
+docstring CursorData::selectionAsString(bool const with_label, bool const skipdelete) const
 {
        if (!selection())
                return docstring();
@@ -350,8 +352,12 @@ docstring CursorData::selectionAsString(bool with_label) const
        if (inMathed())
                return cap::grabSelection(*this);
 
-       int const label = with_label
+       int label = with_label
                ? AS_STR_LABEL | AS_STR_INSETS : AS_STR_INSETS;
+       if (skipdelete)
+               label = with_label
+                               ? AS_STR_LABEL | AS_STR_INSETS | AS_STR_SKIPDELETE
+                               : AS_STR_INSETS | AS_STR_SKIPDELETE;
 
        idx_type const startidx = selBegin().idx();
        idx_type const endidx = selEnd().idx();
@@ -607,6 +613,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);
@@ -1420,10 +1432,7 @@ bool Cursor::atFirstOrLastRow(bool up)
 ///////////////////////////////////////////////////////////////////
 
 #include "mathed/InsetMathChar.h"
-#include "mathed/InsetMathGrid.h"
-#include "mathed/InsetMathScript.h"
 #include "mathed/InsetMathUnknown.h"
-#include "mathed/MathFactory.h"
 #include "mathed/MathStream.h"
 #include "mathed/MathSupport.h"
 
@@ -1762,7 +1771,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() {
+               if (!selection.empty() && data && data->numargs()) {
                        macroArg = true;
                        atomAsMacro->setDisplayMode(InsetMathMacro::DISPLAY_INTERACTIVE_INIT, 1);
                } else
@@ -1824,13 +1833,13 @@ bool Cursor::inMacroMode() const
 
 InsetMathUnknown * Cursor::activeMacro()
 {
-       return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
+       return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : nullptr;
 }
 
 
 InsetMathUnknown const * Cursor::activeMacro() const
 {
-       return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
+       return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : nullptr;
 }
 
 
@@ -2388,6 +2397,20 @@ bool notifyCursorLeavesOrEnters(Cursor const & old, Cursor & cur)
 }
 
 
+void Cursor::setLanguageFromInput()
+{
+       if (!lyxrc.respect_os_kbd_language)
+               return;
+       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())
@@ -2442,12 +2468,6 @@ void Cursor::checkBufferStructure()
                // In case the master has no gui associated with it,
                // the TocItem is not updated (part of bug 5699).
                buffer()->tocBackend().updateItem(*this);
-
-       // If the last tracked change of the paragraph has just been
-       // deleted, then we need to recompute the buffer flag
-       // tracked_changes_present_.
-       if (inTexted() && paragraph().isChangeUpdateRequired())
-               disp_.forceChangesUpdate();
 }