3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
7 * \author Alfredo Braunstein
10 * Full author contact details are available in file CREDITS.
16 #include "BufferView.h"
19 #include "dispatchresult.h"
20 #include "funcrequest.h"
21 #include "iterators.h"
23 #include "lyxfunc.h" // only for setMessage()
27 #include "paragraph.h"
29 #include "insets/updatableinset.h"
30 #include "insets/insettabular.h"
31 #include "insets/insettext.h"
33 #include "mathed/math_data.h"
34 #include "mathed/math_hullinset.h"
35 #include "mathed/math_support.h"
37 #include "support/limited_stack.h"
38 #include "support/std_sstream.h"
40 #include "frontends/LyXView.h"
42 #include <boost/assert.hpp>
47 #ifndef CXX_GLOBAL_CSTD
56 limited_stack<string> theCutBuffer;
59 LCursor::LCursor(BufferView & bv)
60 : DocumentIterator(bv), anchor_(bv),
61 cached_y_(0), x_target_(-1), selection_(false), mark_(false)
68 push_back(CursorSlice());
70 anchor_.push_back(CursorSlice());
78 void LCursor::setCursor(DocumentIterator const & cur, bool sel)
80 // this (intentionally) does not touch the anchor
81 DocumentIterator::operator=(cur);
86 DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
88 lyxerr << "\nLCursor::dispatch: cmd: " << cmd0 << endl << *this << endl;
89 BOOST_ASSERT(pos() <= lastpos());
90 BOOST_ASSERT(idx() <= lastidx());
91 BOOST_ASSERT(par() <= lastpar());
92 FuncRequest cmd = cmd0;
94 DocumentIterator orig = *this;
98 // the inset's dispatch() is supposed to reset the update and
99 // val flags if necessary
100 inset()->dispatch(*this, cmd);
102 // "Mutate" the request for semi-handled requests that need
103 // additional handling in outer levels.
104 switch (disp_.val()) {
106 // the inset handled the event fully
107 return DispatchResult(true, true);
109 // the inset handled the event partially
110 cmd = FuncRequest(LFUN_FINISHED_LEFT);
113 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
116 cmd = FuncRequest(LFUN_FINISHED_UP);
119 cmd = FuncRequest(LFUN_FINISHED_DOWN);
122 //lyxerr << "not handled on level " << depth()
123 // << " val: " << disp_.val() << endl;
127 bv().text()->dispatch(*this, cmd);
129 setCursor(orig, false);
130 //lyxerr << " result: " << res.val() << endl;
135 bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status)
137 lyxerr << "\nLCursor::getStatus: cmd: " << cmd << endl << *this << endl;
138 DocumentIterator orig = *this;
139 BOOST_ASSERT(pos() <= lastpos());
140 BOOST_ASSERT(idx() <= lastidx());
141 BOOST_ASSERT(par() <= lastpar());
142 for ( ; size() != 0; pop_back()) {
143 // the inset's getStatus() will return 'true' if it made
144 // a definitive decision on whether it want to handle the
145 // request or not. The result of this decision is put into
146 // the 'status' parameter.
147 bool const res = inset()->getStatus(*this, cmd, status);
149 setCursor(orig, false);
153 bool const res = bv().text()->getStatus(*this, cmd, status);
154 setCursor(orig, false);
159 BufferView & LCursor::bv() const
161 return DocumentIterator::bv();
166 void LCursor::pop(int depth)
168 while (int(size()) > depth + 1)
170 lyxerr << "LCursor::pop() result: " << *this << endl;
177 BOOST_ASSERT(size() >= 1);
183 void LCursor::push(InsetBase * p)
185 push_back(CursorSlice(p));
189 void LCursor::pushLeft(InsetBase * p)
191 BOOST_ASSERT(!empty());
192 //lyxerr << "Entering inset " << t << " left" << endl;
198 bool LCursor::popLeft()
200 BOOST_ASSERT(!empty());
201 //lyxerr << "Leaving inset to the left" << endl;
204 inset()->notifyCursorLeaves(idx());
207 inset()->notifyCursorLeaves(idx());
213 bool LCursor::popRight()
215 BOOST_ASSERT(!empty());
216 //lyxerr << "Leaving inset to the right" << endl;
219 inset()->notifyCursorLeaves(idx());
222 inset()->notifyCursorLeaves(idx());
229 int LCursor::currentMode()
231 BOOST_ASSERT(!empty());
232 for (int i = size() - 1; i >= 1; --i) {
233 int res = operator[](i).inset()->currentMode();
234 if (res != MathInset::UNDECIDED_MODE)
237 return MathInset::TEXT_MODE;
241 void LCursor::updatePos()
243 BOOST_ASSERT(!empty());
245 cached_y_ = bv().top_y() + back().inset()->yo();
246 //cached_y_ = back().inset()->yo();
250 void LCursor::getDim(int & asc, int & des) const
252 BOOST_ASSERT(!empty());
254 BOOST_ASSERT(inset());
255 BOOST_ASSERT(inset()->asMathInset());
256 //inset()->asMathInset()->getCursorDim(asc, des);
260 Row const & row = textRow();
261 asc = row.baseline();
262 des = row.height() - asc;
267 void LCursor::getPos(int & x, int & y) const
269 BOOST_ASSERT(!empty());
273 x = bv().text()->cursorX(front());
274 y = bv().text()->cursorY(front());
277 lyxerr << "#### LCursor::getPos: " << *this << endl;
278 BOOST_ASSERT(inset());
280 inset()->getCursorPos(back(), x, y);
281 // getCursorPos gives _screen_ coordinates. We need to add
282 // top_y to get document coordinates. This is hidden in cached_y_.
283 //y += cached_y_ - inset()->yo();
284 // The rest is non-obvious. The reason we have to have these
285 // extra computation is that the getCursorPos() calls rely
286 // on the inset's own knowledge of its screen position.
287 // If we scroll up or down in a big enough increment,
288 // inset->draw() is not called: this doesn't update
289 // inset.yo_, so getCursor() returns an old value.
292 //lyxerr << "#### LCursor::getPos: " << *this
293 // << " x: " << x << " y: " << y << endl;
297 void LCursor::paste(string const & data)
299 dispatch(FuncRequest(LFUN_PASTE, data));
303 void LCursor::resetAnchor()
310 bool LCursor::posLeft()
319 bool LCursor::posRight()
321 if (pos() == lastpos())
328 CursorSlice & LCursor::anchor()
330 return anchor_.back();
334 CursorSlice const & LCursor::anchor() const
336 return anchor_.back();
340 CursorSlice const & LCursor::selBegin() const
344 return anchor() < back() ? anchor() : back();
348 CursorSlice & LCursor::selBegin()
352 // can't use std::min as this returns a const ref
353 return anchor() < back() ? anchor() : back();
357 CursorSlice const & LCursor::selEnd() const
361 return anchor() > back() ? anchor() : back();
365 CursorSlice & LCursor::selEnd()
369 // can't use std::min as this returns a const ref
370 return anchor() > back() ? anchor() : back();
374 void LCursor::setSelection()
377 // a selection with no contents is not a selection
378 if (par() == anchor().par() && pos() == anchor().pos())
383 void LCursor::setSelection(DocumentIterator const & where, size_t n)
386 setCursor(where, false);
392 void LCursor::clearSelection()
401 int & LCursor::x_target()
407 int LCursor::x_target() const
413 void LCursor::clearTargetX()
420 void LCursor::info(std::ostream & os) const
422 for (int i = 1, n = depth(); i < n; ++i) {
423 operator[](i).inset()->infoize(os);
427 prevInset()->infoize2(os);
428 // overwite old message
435 void region(CursorSlice const & i1, CursorSlice const & i2,
436 LCursor::row_type & r1, LCursor::row_type & r2,
437 LCursor::col_type & c1, LCursor::col_type & c2)
439 InsetBase * p = i1.inset();
440 c1 = p->col(i1.idx_);
441 c2 = p->col(i2.idx_);
444 r1 = p->row(i1.idx_);
445 r2 = p->row(i2.idx_);
453 string LCursor::grabSelection()
458 CursorSlice i1 = selBegin();
459 CursorSlice i2 = selEnd();
461 if (i1.idx_ == i2.idx_) {
462 if (i1.inset()->asMathInset()) {
463 MathArray::const_iterator it = i1.cell().begin();
464 return asString(MathArray(it + i1.pos_, it + i2.pos_));
466 return "unknown selection 1";
472 region(i1, i2, r1, r2, c1, c2);
475 if (i1.inset()->asMathInset()) {
476 for (row_type row = r1; row <= r2; ++row) {
479 for (col_type col = c1; col <= c2; ++col) {
482 data += asString(i1.asMathInset()->cell(i1.asMathInset()->index(row, col)));
486 data = "unknown selection 2";
492 void LCursor::eraseSelection()
494 //lyxerr << "LCursor::eraseSelection" << endl;
495 CursorSlice const & i1 = selBegin();
496 CursorSlice const & i2 = selEnd();
498 if (i1.inset()->asMathInset()) {
499 if (i1.idx_ == i2.idx_) {
500 i1.cell().erase(i1.pos_, i2.pos_);
502 MathInset * p = i1.asMathInset();
505 region(i1, i2, r1, r2, c1, c2);
506 for (row_type row = r1; row <= r2; ++row)
507 for (col_type col = c1; col <= c2; ++col)
508 p->cell(p->index(row, col)).clear();
512 lyxerr << "can't erase this selection 1" << endl;
514 //lyxerr << "LCursor::eraseSelection end" << endl;
518 string LCursor::grabAndEraseSelection()
522 string res = grabSelection();
529 void LCursor::selClear()
536 void LCursor::selCopy()
539 theCutBuffer.push(grabSelection());
542 //theCutBuffer.erase();
547 void LCursor::selCut()
549 theCutBuffer.push(grabAndEraseSelection());
553 void LCursor::selDel()
555 //lyxerr << "LCursor::selDel" << endl;
563 void LCursor::selPaste(size_t n)
566 if (n < theCutBuffer.size())
567 paste(theCutBuffer[n]);
573 void LCursor::selHandle(bool sel)
575 //lyxerr << "LCursor::selHandle" << endl;
576 if (sel == selection())
583 void LCursor::selClearOrDel()
585 //lyxerr << "LCursor::selClearOrDel" << endl;
586 if (lyxrc.auto_region_delete)
593 std::ostream & operator<<(std::ostream & os, LCursor const & cur)
595 for (size_t i = 0, n = cur.size(); i != n; ++i)
596 os << " " << cur.operator[](i) << " | " << cur.anchor_[i] << "\n";
597 os << " selection: " << cur.selection_ << endl;
604 ///////////////////////////////////////////////////////////////////
606 // The part below is the non-integrated rest of the original math
607 // cursor. This should be either generalized for texted or moved
608 // back to mathed (in most cases to MathNestInset).
610 ///////////////////////////////////////////////////////////////////
612 #include "mathed/math_charinset.h"
613 #include "mathed/math_factory.h"
614 #include "mathed/math_gridinset.h"
615 #include "mathed/math_macroarg.h"
616 #include "mathed/math_macrotemplate.h"
617 #include "mathed/math_mathmlstream.h"
618 #include "mathed/math_scriptinset.h"
619 #include "mathed/math_support.h"
620 #include "mathed/math_unknowninset.h"
622 //#define FILEDEBUG 1
625 bool LCursor::isInside(InsetBase const * p)
627 for (unsigned i = 0; i < depth(); ++i)
628 if (operator[](i).inset() == p)
634 bool LCursor::openable(MathAtom const & t) const
645 // we can't move into anything new during selection
646 if (depth() == anchor_.size())
648 if (!ptr_cmp(t.nucleus(), anchor_[depth()].inset()))
655 bool positionable(DocumentIterator const & cursor,
656 DocumentIterator const & anchor)
658 // avoid deeper nested insets when selecting
659 if (cursor.size() > anchor.size())
662 // anchor might be deeper, should have same path then
663 for (size_t i = 0; i < cursor.size(); ++i)
664 if (cursor[i].inset() != anchor[i].inset())
667 // position should be ok.
672 void LCursor::setScreenPos(int x, int y)
674 bool res = bruteFind(x, y, formula()->xlow(), formula()->xhigh(),
675 formula()->ylow(), formula()->yhigh());
677 // this can happen on creation of "math-display"
686 void LCursor::plainErase()
692 void LCursor::markInsert()
694 cell().insert(pos(), MathAtom(new MathCharInset(0)));
698 void LCursor::markErase()
704 void LCursor::plainInsert(MathAtom const & t)
706 cell().insert(pos(), t);
711 void LCursor::insert(string const & str)
713 lyxerr << "LCursor::insert str '" << str << "'" << endl;
716 for (string::const_iterator it = str.begin(); it != str.end(); ++it)
717 plainInsert(MathAtom(new MathCharInset(*it)));
726 void LCursor::insert(char c)
728 //lyxerr << "LCursor::insert char '" << c << "'" << endl;
730 plainInsert(MathAtom(new MathCharInset(c)));
734 void LCursor::insert(MathAtom const & t)
736 //lyxerr << "LCursor::insert MathAtom: " << endl;
743 void LCursor::insert(InsetBase * inset)
746 insert(MathAtom(inset));
748 text()->insertInset(*this, inset);
752 void LCursor::niceInsert(string const & t)
763 void LCursor::niceInsert(MathAtom const & t)
766 string safe = grabAndEraseSelection();
768 // enter the new inset and move the contents of the selection if possible
771 // be careful here: don't use 'pushLeft(t)' as this we need to
772 // push the clone, not the original
773 pushLeft(nextAtom().nucleus());
779 void LCursor::insert(MathArray const & ar)
784 cell().insert(pos(), ar);
789 bool LCursor::backspace()
791 autocorrect() = false;
799 if (inset()->nargs() == 1 && depth() == 1 && lastpos() == 0)
806 MathUnknownInset * p = activeMacro();
807 if (p->name().size() > 1) {
808 p->setName(p->name().substr(0, p->name().size() - 1));
813 if (pos() != 0 && prevAtom()->nargs() > 0) {
814 // let's require two backspaces for 'big stuff' and
815 // highlight on the first
826 bool LCursor::erase()
828 autocorrect() = false;
837 // delete empty cells if possible
838 if (pos() == lastpos() && inset()->idxDelete(idx()))
841 // special behaviour when in last position of cell
842 if (pos() == lastpos()) {
843 bool one_cell = inset()->nargs() == 1;
844 if (one_cell && depth() == 1 && lastpos() == 0)
850 inset()->idxGlue(idx());
854 if (pos() != lastpos() && inset()->nargs() > 0) {
868 DocumentIterator save = *this;
871 setCursor(save, false);
872 autocorrect() = false;
880 DocumentIterator save = *this;
883 setCursor(save, false);
884 autocorrect() = false;
889 void LCursor::macroModeClose()
893 MathUnknownInset * p = activeMacro();
895 string s = p->name();
899 // do nothing if the macro name is empty
903 string const name = s.substr(1);
905 // prevent entering of recursive macros
906 InsetBase const * macro = innerInsetOfType(InsetBase::MATHMACRO_CODE);
907 if (macro && macro->getInsetName() == name)
908 lyxerr << "can't enter recursive macro" << endl;
910 niceInsert(createMathInset(name));
914 string LCursor::macroName()
916 return inMacroMode() ? activeMacro()->name() : string();
920 void LCursor::handleNest(MathAtom const & a, int c)
922 //lyxerr << "LCursor::handleNest: " << c << endl;
924 asArray(grabAndEraseSelection(), t.nucleus()->cell(c));
927 pushLeft(nextAtom().nucleus());
931 int LCursor::targetX() const
933 if (x_target() != -1)
942 MathHullInset * LCursor::formula() const
944 for (int i = size() - 1; i >= 1; --i) {
945 MathInset * inset = operator[](i).inset()->asMathInset();
946 if (inset && inset->asHullInset())
947 return static_cast<MathHullInset *>(inset);
953 void LCursor::adjust(pos_type from, int diff)
957 if (anchor().pos_ > from)
958 anchor().pos_ += diff;
959 // just to be on the safe side
960 // theoretically unecessary
965 bool LCursor::inMacroMode() const
969 MathUnknownInset const * p = prevAtom()->asUnknownInset();
970 return p && !p->final();
974 MathUnknownInset * LCursor::activeMacro()
976 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
980 bool LCursor::inMacroArgMode() const
982 return pos() > 0 && prevAtom()->getChar() == '#';
986 MathGridInset * LCursor::enclosingGrid(idx_type & idx) const
988 for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
989 MathInset * m = operator[](i).inset()->asMathInset();
992 MathGridInset * p = m->asGridInset();
994 idx = operator[](i).idx_;
1002 void LCursor::pullArg()
1005 MathArray ar = cell();
1006 if (popLeft() && inMathed()) {
1008 cell().insert(pos(), ar);
1011 //formula()->mutateToText();
1016 void LCursor::touch()
1020 DocumentIterator::const_iterator it = begin();
1021 DocumentIterator::const_iterator et = end();
1022 for ( ; it != et; ++it)
1028 void LCursor::normalize()
1030 if (idx() >= nargs()) {
1031 lyxerr << "this should not really happen - 1: "
1032 << idx() << ' ' << nargs()
1033 << " in: " << inset() << endl;
1035 idx() = min(idx(), lastidx());
1037 if (pos() > lastpos()) {
1038 lyxerr << "this should not really happen - 2: "
1039 << pos() << ' ' << lastpos() << " in idx: " << idx()
1041 WriteStream wi(lyxerr, false, true);
1042 inset()->asMathInset()->write(wi);
1045 pos() = min(pos(), lastpos());
1049 char LCursor::valign()
1052 MathGridInset * p = enclosingGrid(idx);
1053 return p ? p->valign() : '\0';
1057 char LCursor::halign()
1060 MathGridInset * p = enclosingGrid(idx);
1061 return p ? p->halign(idx % p->ncols()) : '\0';
1065 bool LCursor::goUpDown(bool up)
1067 // Be warned: The 'logic' implemented in this function is highly
1068 // fragile. A distance of one pixel or a '<' vs '<=' _really
1069 // matters. So fiddle around with it only if you think you know
1070 // what you are doing!
1075 // check if we had something else in mind, if not, this is the future goal
1076 if (x_target() == -1)
1081 // try neigbouring script insets
1085 MathScriptInset const * p = prevAtom()->asScriptInset();
1086 if (p && p->has(up)) {
1089 idx() = up; // the superscript has index 1
1091 //lyxerr << "updown: handled by scriptinset to the left" << endl;
1097 if (pos() != lastpos()) {
1098 MathScriptInset const * p = nextAtom()->asScriptInset();
1099 if (p && p->has(up)) {
1103 //lyxerr << "updown: handled by scriptinset to the right" << endl;
1109 // try current cell for e.g. text insets
1110 if (inset()->idxUpDown2(*this, up))
1113 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1118 //if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
1119 // lyxerr << "updown: handled by brute find in the same cell" << endl;
1123 // try to find an inset that knows better then we
1125 //lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl;
1127 if (inset()->idxUpDown(*this, up)) {
1128 // try to find best position within this inset
1134 // no such inset found, just take something "above"
1135 //lyxerr << "updown: handled by strange case" << endl;
1141 up ? formula()->ylow() : yo + 4,
1142 up ? yo - 4 : formula()->yhigh()
1146 // any improvement so far?
1149 if (up ? ynew < yo : ynew > yo)
1155 bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1157 DocumentIterator best_cursor(bv());
1158 double best_dist = 1e10;
1160 DocumentIterator it = bufferBegin(bv());
1161 DocumentIterator et = bufferEnd();
1163 // avoid invalid nesting when selecting
1164 if (!selection() || positionable(it, anchor_)) {
1166 CursorSlice & cur = it.back();
1167 cur.inset()->getCursorPos(cur, xo, yo);
1168 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1169 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1170 //lyxerr << "x: " << x << " y: " << y << " d: " << endl;
1171 // '<=' in order to take the last possible position
1172 // this is important for clicking behind \sum in e.g. '\sum_i a'
1173 if (d <= best_dist) {
1185 if (best_dist < 1e10)
1186 setCursor(best_cursor, false);
1187 return best_dist < 1e10;
1191 void LCursor::bruteFind2(int x, int y)
1193 double best_dist = 1e10;
1195 DocumentIterator it = *this;
1196 it.back().pos() = 0;
1197 DocumentIterator et = *this;
1198 et.back().pos() = et.back().asMathInset()->cell(et.back().idx_).size();
1199 for (int i = 0; ; ++i) {
1201 CursorSlice & cur = it.back();
1202 cur.inset()->getCursorPos(cur, xo, yo);
1203 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1204 // '<=' in order to take the last possible position
1205 // this is important for clicking behind \sum in e.g. '\sum_i a'
1206 lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl;
1207 if (d <= best_dist) {
1209 setCursor(it, false);
1218 CursorSlice LCursor::normalAnchor()
1220 if (anchor_.size() < depth()) {
1222 lyxerr << "unusual Anchor size" << endl;
1224 //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth());
1225 // use Anchor on the same level as Cursor
1226 CursorSlice normal = anchor_[size() - 1];
1228 if (depth() < anchor_.size() && !(normal < xx())) {
1229 // anchor is behind cursor -> move anchor behind the inset
1238 DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd)
1240 // mouse clicks are somewhat special
1242 switch (cmd.action) {
1243 case LFUN_MOUSE_PRESS:
1244 case LFUN_MOUSE_MOTION:
1245 case LFUN_MOUSE_RELEASE:
1246 case LFUN_MOUSE_DOUBLE: {
1247 CursorSlice & pos = back();
1251 if (x < cmd.x && pos() != 0) {
1252 DispatchResult const res = prevAtom().nucleus()->dispatch(cmd);
1253 if (res.dispatched())
1256 if (x > cmd.x && pos() != lastpos()) {
1257 DispatchResult const res = inset()->dispatch(cmd);
1258 if (res.dispatched())
1269 void LCursor::handleFont(string const & font)
1271 lyxerr << "LCursor::handleFont: " << font << endl;
1275 safe = grabAndEraseSelection();
1278 if (lastpos() != 0) {
1279 // something left in the cell
1281 // cursor in first position
1283 } else if (pos() == lastpos()) {
1284 // cursor in last position
1287 // cursor in between. split cell
1288 MathArray::iterator bt = cell().begin();
1289 MathAtom at = createMathInset(font);
1290 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1291 cell().erase(bt, bt + pos());
1296 // nothing left in the cell
1304 void LCursor::message(string const & msg) const
1306 bv().owner()->getLyXFunc().setMessage(msg);
1310 void LCursor::errorMessage(string const & msg) const
1312 bv().owner()->getLyXFunc().setErrorMessage(msg);
1316 string LCursor::selectionAsString(bool label) const
1322 Buffer const & buffer = *bv().buffer();
1324 // should be const ...
1325 ParagraphList::iterator startpit = text()->getPar(selBegin());
1326 ParagraphList::iterator endpit = text()->getPar(selEnd());
1327 size_t const startpos = selBegin().pos();
1328 size_t const endpos = selEnd().pos();
1330 if (startpit == endpit)
1331 return startpit->asString(buffer, startpos, endpos, label);
1333 // First paragraph in selection
1335 startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
1337 // The paragraphs in between (if any)
1338 ParagraphList::iterator pit = startpit;
1339 for (++pit; pit != endpit; ++pit)
1340 result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
1342 // Last paragraph in selection
1343 result += endpit->asString(buffer, 0, endpos, label);
1353 string LCursor::currentState()
1356 std::ostringstream os;
1360 return text() ? text()->currentState(*this) : string();
1364 // only used by the spellchecker
1365 void LCursor::replaceWord(string const & replacestring)
1367 LyXText * t = text();
1370 t->replaceSelectionWithString(*this, replacestring);
1371 t->setSelectionRange(*this, replacestring.length());
1373 // Go back so that replacement string is also spellchecked
1374 for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
1375 t->cursorLeft(*this);
1379 void LCursor::update()
1385 string LCursor::getPossibleLabel()
1387 return inMathed() ? "eq:" : text()->getPossibleLabel(*this);
1391 void LCursor::undispatched()
1393 disp_.dispatched(false);
1397 void LCursor::dispatched(dispatch_result_t res)
1403 void LCursor::noUpdate()
1405 disp_.update(false);
1409 void LCursor::noPop()