#include "DispatchResult.h"
#include "FuncCode.h"
#include "FuncRequest.h"
+#include "Language.h"
#include "Layout.h"
#include "LyXAction.h"
#include "LyXRC.h"
#include "mathed/MathFactory.h"
#include "mathed/InsetMathMacro.h"
+#include "frontends/Application.h"
+
#include <sstream>
#include <limits>
#include <map>
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)
{}
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
}
-docstring CursorData::selectionAsString(bool with_label) const
+docstring CursorData::selectionAsString(bool const with_label, bool const skipdelete) const
{
if (!selection())
return docstring();
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();
}
-bool CursorData::isInside(Inset const * p) const
-{
- for (size_t i = 0; i != depth(); ++i)
- if (&operator[](i).inset() == p)
- return true;
- return false;
-}
-
-
-void CursorData::leaveInset(Inset const & inset)
-{
- for (size_t i = 0; i != depth(); ++i) {
- if (&operator[](i).inset() == &inset) {
- resize(i);
- return;
- }
- }
-}
-
-
-bool CursorData::textUndo()
+bool CursorData::undoAction()
{
- if (!buffer()->undo().textUndo(*this))
+ if (!buffer()->undo().undoAction(*this))
return false;
sanitize();
return true;
}
-bool CursorData::textRedo()
+bool CursorData::redoAction()
{
- if (!buffer()->undo().textRedo(*this))
+ if (!buffer()->undo().redoAction(*this))
return false;
sanitize();
return true;
}
+void CursorData::splitUndoGroup() const
+{
+ buffer()->undo().splitUndoGroup(*this);
+}
+
+
void CursorData::recordUndo(pit_type from, pit_type to) const
{
buffer()->undo().recordUndo(*this, from, to);
}
+void Cursor::editInsertedInset()
+{
+ LASSERT(!empty(), return);
+ if (pos() == 0)
+ return;
+
+ InsetMath &p = prevMath();
+ if (!p.isActive())
+ return;
+
+ posBackward();
+ push(p);
+ p.idxFirst(*this);
+ // this could be a while() loop, but only one cell is not empty in
+ // cases we are interested in. The cell is not empty because we
+ // have inserted the selection in there.
+ if (!cell().empty()) {
+ // if it is not empty, move to the next one.
+ if (!inset().idxNext(*this))
+ // If there is no next one, exit the inset.
+ popForward();
+ }
+}
+
+
bool Cursor::popBackward()
{
LASSERT(!empty(), return false);
plainInsert(t);
// If possible, enter the new inset and move the contents of the selection
if (t->isActive()) {
- posBackward();
- // be careful here: don't use 'pushBackward(t)' as this we need to
- // push the clone, not the original
- pushBackward(*nextInset());
- // We may not use niceInsert here (recursion)
+ idx_type const idx = prevMath().asNestInset()->firstIdx();
MathData ar(buffer());
asArray(safe, ar);
- insert(ar);
+ prevMath().cell(idx).insert(0, ar);
+ editInsertedInset();
} else if (t->asMacro() && !safe.empty()) {
MathData ar(buffer());
asArray(safe, ar);
}
-void Cursor::handleNest(MathAtom const & a, int c)
+void Cursor::handleNest(MathAtom const & a)
{
- //lyxerr << "Cursor::handleNest: " << c << endl;
+ idx_type const idx = a.nucleus()->asNestInset()->firstIdx();
+ //lyxerr << "Cursor::handleNest: " << idx << endl;
MathAtom t = a;
- asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
+ asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(idx));
insert(t);
- posBackward();
- pushBackward(*nextInset());
-}
-
-
-void Cursor::handleNest(MathAtom const & a)
-{
- handleNest(a, a.nucleus()->asNestInset()->firstIdx());
+ editInsertedInset();
}
// 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
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;
}
}
+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();
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())
// 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();
}