2003-09-17 16:44:51 +00:00
|
|
|
/**
|
2007-04-26 14:56:30 +00:00
|
|
|
* \file Cursor.cpp
|
2003-09-17 16:44:51 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2004-01-26 10:13:15 +00:00
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
* \author Alfredo Braunstein
|
2008-02-10 19:52:45 +00:00
|
|
|
* \author Dov Feldstern
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2007-05-29 20:53:32 +00:00
|
|
|
* \author Stefan Schimanski
|
2003-09-17 16:44:51 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2020-10-14 21:45:04 +00:00
|
|
|
#include "Cursor.h"
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "CoordCache.h"
|
2004-03-25 09:16:36 +00:00
|
|
|
#include "CutAndPaste.h"
|
2008-03-15 01:20:36 +00:00
|
|
|
#include "FuncCode.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2019-07-19 09:46:35 +00:00
|
|
|
#include "Language.h"
|
2010-11-06 15:06:19 +00:00
|
|
|
#include "Layout.h"
|
2009-11-13 14:32:51 +00:00
|
|
|
#include "LyXAction.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
#include "Paragraph.h"
|
|
|
|
#include "Row.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
#include "Text.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
#include "TextMetrics.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
#include "TocBackend.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-05 22:54:53 +00:00
|
|
|
#include "support/docstream.h"
|
2013-04-25 21:27:10 +00:00
|
|
|
#include "support/gettext.h"
|
|
|
|
#include "support/lassert.h"
|
2007-11-05 22:54:53 +00:00
|
|
|
|
2020-12-02 20:34:28 +00:00
|
|
|
#include "insets/InsetLayout.h"
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetTabular.h"
|
2003-11-04 12:36:59 +00:00
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "mathed/InsetMath.h"
|
2008-03-04 14:49:24 +00:00
|
|
|
#include "mathed/InsetMathBrace.h"
|
2016-09-10 00:07:47 +00:00
|
|
|
#include "mathed/InsetMathEnsureMath.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "mathed/InsetMathScript.h"
|
2007-04-28 20:44:46 +00:00
|
|
|
#include "mathed/MacroTable.h"
|
2007-11-01 14:40:15 +00:00
|
|
|
#include "mathed/MathData.h"
|
2016-09-10 00:07:47 +00:00
|
|
|
#include "mathed/MathFactory.h"
|
2017-07-05 12:31:28 +00:00
|
|
|
#include "mathed/InsetMathMacro.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
2019-07-19 09:46:35 +00:00
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2005-01-18 14:15:57 +00:00
|
|
|
#include <limits>
|
2006-11-27 16:40:03 +00:00
|
|
|
#include <map>
|
2010-04-22 11:45:34 +00:00
|
|
|
#include <algorithm>
|
2004-07-24 10:55:30 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-07-17 17:46:54 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2004-08-13 19:19:53 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
// Find position closest to (x, y) in cell given by iter.
|
|
|
|
// Used only in mathed
|
2016-02-28 15:48:11 +00:00
|
|
|
DocIterator bruteFind(Cursor const & c, int x, int y)
|
2007-11-28 22:12:03 +00:00
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
double best_dist = numeric_limits<double>::max();
|
2004-08-13 19:19:53 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
DocIterator result;
|
2006-11-27 16:40:03 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
DocIterator it = c;
|
2016-02-28 15:56:00 +00:00
|
|
|
it.pos() = 0;
|
2007-11-28 22:12:03 +00:00
|
|
|
DocIterator et = c;
|
2016-02-28 15:56:00 +00:00
|
|
|
et.pos() = et.lastpos();
|
2007-11-28 22:12:03 +00:00
|
|
|
for (size_t i = 0;; ++i) {
|
|
|
|
int xo;
|
|
|
|
int yo;
|
|
|
|
Inset const * inset = &it.inset();
|
2016-02-28 15:56:00 +00:00
|
|
|
CoordCache::Insets const & insetCache = c.bv().coordCache().getInsets();
|
2004-08-13 19:19:53 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
// FIXME: in the case where the inset is not in the cache, this
|
|
|
|
// means that no part of it is visible on screen. In this case
|
|
|
|
// we don't do elaborate search and we just return the forwarded
|
|
|
|
// DocIterator at its beginning.
|
2016-02-28 15:56:00 +00:00
|
|
|
if (!insetCache.has(inset)) {
|
2007-11-28 22:12:03 +00:00
|
|
|
it.top().pos() = 0;
|
|
|
|
return it;
|
|
|
|
}
|
2004-08-13 19:19:53 +00:00
|
|
|
|
2016-02-28 15:56:00 +00:00
|
|
|
Point const o = insetCache.xy(inset);
|
2007-11-28 22:12:03 +00:00
|
|
|
inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
|
|
|
|
// Convert to absolute
|
|
|
|
xo += o.x_;
|
|
|
|
yo += o.y_;
|
|
|
|
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
|
|
|
|
// '<=' in order to take the last possible position
|
|
|
|
// this is important for clicking behind \sum in e.g. '\sum_i a'
|
|
|
|
LYXERR(Debug::DEBUG, "i: " << i << " d: " << d
|
|
|
|
<< " best: " << best_dist);
|
|
|
|
if (d <= best_dist) {
|
|
|
|
best_dist = d;
|
|
|
|
result = it;
|
|
|
|
}
|
|
|
|
if (it == et)
|
|
|
|
break;
|
|
|
|
it.forwardPos();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2004-08-13 19:19:53 +00:00
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
//
|
|
|
|
// CursorData
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2012-07-15 16:16:09 +00:00
|
|
|
CursorData::CursorData()
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
: DocIterator(), anchor_(), selection_(false), mark_(false),
|
2019-05-24 23:07:26 +00:00
|
|
|
word_selection_(false), current_font(inherit_font)
|
2012-07-15 16:16:09 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
CursorData::CursorData(Buffer * buffer)
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
: DocIterator(buffer), anchor_(), selection_(false), mark_(false),
|
2019-05-24 23:07:26 +00:00
|
|
|
word_selection_(false), current_font(inherit_font)
|
2012-07-15 16:16:09 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
CursorData::CursorData(DocIterator const & dit)
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
: DocIterator(dit), anchor_(), selection_(false), mark_(false),
|
2019-05-24 23:07:26 +00:00
|
|
|
word_selection_(false), current_font(inherit_font)
|
2012-07-15 16:16:09 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2015-03-10 14:53:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
ostream & operator<<(ostream & os, CursorData const & cur)
|
|
|
|
{
|
|
|
|
os << "\n cursor: | anchor:\n";
|
|
|
|
for (size_t i = 0, n = cur.depth(); i != n; ++i) {
|
|
|
|
os << " " << cur[i] << " | ";
|
|
|
|
if (i < cur.anchor_.depth())
|
|
|
|
os << cur.anchor_[i];
|
|
|
|
else
|
|
|
|
os << "-------------------------------";
|
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
|
|
|
|
os << "------------------------------- | " << cur.anchor_[i] << "\n";
|
|
|
|
}
|
|
|
|
os << " selection: " << cur.selection_
|
|
|
|
// << " x_target: " << cur.x_target_
|
|
|
|
<< " boundary: " << cur.boundary() << endl;
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
LyXErr & operator<<(LyXErr & os, CursorData const & cur)
|
|
|
|
{
|
|
|
|
os.stream() << cur;
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::reset()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
push_back(CursorSlice(buffer()->inset()));
|
|
|
|
anchor_ = doc_iterator_begin(buffer());
|
|
|
|
anchor_.clear();
|
|
|
|
new_word_ = doc_iterator_begin(buffer());
|
|
|
|
new_word_.clear();
|
|
|
|
selection_ = false;
|
|
|
|
mark_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::setCursor(DocIterator const & cur)
|
|
|
|
{
|
|
|
|
DocIterator::operator=(cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::setCursorSelectionTo(DocIterator dit)
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
// normalise dit
|
|
|
|
while (i < dit.depth() && i < anchor_.depth() && dit[i] == anchor_[i])
|
|
|
|
++i;
|
|
|
|
if (i != dit.depth()) {
|
|
|
|
// otherwise the cursor is already normal
|
|
|
|
if (i == anchor_.depth())
|
|
|
|
// dit is a proper extension of the anchor_
|
|
|
|
dit.cutOff(i - 1);
|
|
|
|
else if (i + 1 < dit.depth()) {
|
|
|
|
// one has dit[i] != anchor_[i] but either dit[i-1] == anchor_[i-1]
|
|
|
|
// or i == 0. Remove excess.
|
|
|
|
dit.cutOff(i);
|
|
|
|
if (dit[i] > anchor_[i])
|
|
|
|
// place dit after the inset it was in
|
|
|
|
++dit.pos();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setCursor(dit);
|
|
|
|
setSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::setCursorToAnchor()
|
|
|
|
{
|
|
|
|
if (selection()) {
|
|
|
|
DocIterator normal = anchor_;
|
|
|
|
while (depth() < normal.depth())
|
|
|
|
normal.pop_back();
|
|
|
|
if (depth() < anchor_.depth() && top() <= anchor_[depth() - 1])
|
|
|
|
++normal.pos();
|
|
|
|
setCursor(normal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CursorSlice CursorData::normalAnchor() const
|
|
|
|
{
|
|
|
|
if (!selection())
|
|
|
|
return top();
|
|
|
|
// LASSERT: There have been several bugs around this code, that seem
|
|
|
|
// to involve failures to reset the anchor. We can at least not crash
|
|
|
|
// in release mode by resetting it ourselves.
|
|
|
|
if (anchor_.depth() < depth()) {
|
|
|
|
LYXERR0("Cursor is deeper than anchor. PLEASE REPORT.\nCursor is"
|
|
|
|
<< *this);
|
|
|
|
const_cast<DocIterator &>(anchor_) = *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CursorSlice normal = anchor_[depth() - 1];
|
|
|
|
if (depth() < anchor_.depth() && top() <= normal) {
|
|
|
|
// anchor is behind cursor -> move anchor behind the inset
|
|
|
|
++normal.pos();
|
|
|
|
}
|
|
|
|
return normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::setSelection()
|
|
|
|
{
|
|
|
|
selection(true);
|
|
|
|
if (idx() == normalAnchor().idx() &&
|
|
|
|
pit() == normalAnchor().pit() &&
|
|
|
|
pos() == normalAnchor().pos())
|
|
|
|
selection(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::setSelection(DocIterator const & where, int n)
|
|
|
|
{
|
|
|
|
setCursor(where);
|
|
|
|
selection(true);
|
|
|
|
anchor_ = where;
|
|
|
|
pos() += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::resetAnchor()
|
|
|
|
{
|
|
|
|
anchor_ = *this;
|
|
|
|
checkNewWordPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CursorSlice CursorData::selBegin() const
|
|
|
|
{
|
|
|
|
if (!selection())
|
|
|
|
return top();
|
|
|
|
return normalAnchor() < top() ? normalAnchor() : top();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CursorSlice CursorData::selEnd() const
|
|
|
|
{
|
|
|
|
if (!selection())
|
|
|
|
return top();
|
|
|
|
return normalAnchor() > top() ? normalAnchor() : top();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DocIterator CursorData::selectionBegin() const
|
|
|
|
{
|
|
|
|
if (!selection())
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
DocIterator di;
|
|
|
|
// FIXME: This is a work-around for the problem that
|
|
|
|
// CursorSlice doesn't keep track of the boundary.
|
|
|
|
if (normalAnchor() == top())
|
|
|
|
di = anchor_.boundary() > boundary() ? anchor_ : *this;
|
|
|
|
else
|
|
|
|
di = normalAnchor() < top() ? anchor_ : *this;
|
|
|
|
di.resize(depth());
|
|
|
|
return di;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DocIterator CursorData::selectionEnd() const
|
|
|
|
{
|
|
|
|
if (!selection())
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
DocIterator di;
|
|
|
|
// FIXME: This is a work-around for the problem that
|
|
|
|
// CursorSlice doesn't keep track of the boundary.
|
|
|
|
if (normalAnchor() == top())
|
|
|
|
di = anchor_.boundary() < boundary() ? anchor_ : *this;
|
|
|
|
else
|
|
|
|
di = normalAnchor() > top() ? anchor_ : *this;
|
|
|
|
|
|
|
|
if (di.depth() > depth()) {
|
|
|
|
di.resize(depth());
|
|
|
|
++di.pos();
|
|
|
|
}
|
|
|
|
return di;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
docstring parbreak(CursorData const * cur)
|
|
|
|
{
|
2019-06-02 16:16:30 +00:00
|
|
|
if (cur->inset().getLayout().parbreakIgnored())
|
|
|
|
return docstring();
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
odocstringstream os;
|
|
|
|
os << '\n';
|
|
|
|
// only add blank line if we're not in a ParbreakIsNewline situation
|
|
|
|
if (!cur->inset().getLayout().parbreakIsNewline()
|
|
|
|
&& !cur->paragraph().layout().parbreak_is_newline)
|
|
|
|
os << '\n';
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-31 12:47:06 +00:00
|
|
|
docstring CursorData::selectionAsString(bool const with_label, bool const skipdelete) const
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
{
|
|
|
|
if (!selection())
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
if (inMathed())
|
|
|
|
return cap::grabSelection(*this);
|
|
|
|
|
2019-12-31 12:47:06 +00:00
|
|
|
int label = with_label
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
? AS_STR_LABEL | AS_STR_INSETS : AS_STR_INSETS;
|
2019-12-31 12:47:06 +00:00
|
|
|
if (skipdelete)
|
|
|
|
label = with_label
|
|
|
|
? AS_STR_LABEL | AS_STR_INSETS | AS_STR_SKIPDELETE
|
|
|
|
: AS_STR_INSETS | AS_STR_SKIPDELETE;
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
|
|
|
|
idx_type const startidx = selBegin().idx();
|
|
|
|
idx_type const endidx = selEnd().idx();
|
|
|
|
if (startidx != endidx) {
|
|
|
|
// multicell selection
|
|
|
|
InsetTabular * table = inset().asInsetTabular();
|
|
|
|
LASSERT(table, return docstring());
|
|
|
|
return table->asString(startidx, endidx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ParagraphList const & pars = text()->paragraphs();
|
|
|
|
|
|
|
|
pit_type const startpit = selBegin().pit();
|
|
|
|
pit_type const endpit = selEnd().pit();
|
|
|
|
size_t const startpos = selBegin().pos();
|
|
|
|
size_t const endpos = selEnd().pos();
|
|
|
|
|
|
|
|
if (startpit == endpit)
|
|
|
|
return pars[startpit].asString(startpos, endpos, label);
|
|
|
|
|
|
|
|
// First paragraph in selection
|
|
|
|
docstring result = pars[startpit].
|
|
|
|
asString(startpos, pars[startpit].size(), label)
|
|
|
|
+ parbreak(this);
|
|
|
|
|
|
|
|
// The paragraphs in between (if any)
|
|
|
|
for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
|
|
|
|
Paragraph const & par = pars[pit];
|
|
|
|
result += par.asString(0, par.size(), label)
|
|
|
|
+ parbreak(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last paragraph in selection
|
|
|
|
result += pars[endpit].asString(0, endpos, label);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::info(odocstream & os, bool devel_mode) const
|
|
|
|
{
|
|
|
|
for (int i = 1, n = depth(); i < n; ++i) {
|
|
|
|
operator[](i).inset().infoize(os);
|
|
|
|
os << " ";
|
|
|
|
}
|
|
|
|
if (pos() != 0) {
|
|
|
|
Inset const * inset = prevInset();
|
|
|
|
// prevInset() can return 0 in certain case.
|
|
|
|
if (inset)
|
|
|
|
prevInset()->infoize2(os);
|
|
|
|
}
|
|
|
|
if (devel_mode) {
|
|
|
|
InsetMath * math = inset().asInsetMath();
|
|
|
|
if (math)
|
|
|
|
os << _(", Inset: ") << math->id();
|
|
|
|
os << _(", Cell: ") << idx();
|
|
|
|
os << _(", Position: ") << pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
docstring CursorData::currentState(bool devel_mode) const
|
|
|
|
{
|
|
|
|
if (inMathed()) {
|
|
|
|
odocstringstream os;
|
|
|
|
info(os, devel_mode);
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inTexted())
|
|
|
|
return text()->currentState(*this, devel_mode);
|
|
|
|
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::markNewWordPosition()
|
|
|
|
{
|
|
|
|
if (lyxrc.spellcheck_continuously && inTexted() && new_word_.empty()) {
|
|
|
|
FontSpan nw = locateWord(WHOLE_WORD);
|
|
|
|
if (nw.size() == 1) {
|
|
|
|
LYXERR(Debug::DEBUG, "start new word: "
|
|
|
|
<< " par: " << pit()
|
|
|
|
<< " pos: " << nw.first);
|
|
|
|
new_word_ = *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::clearNewWordPosition()
|
|
|
|
{
|
|
|
|
if (!new_word_.empty()) {
|
|
|
|
LYXERR(Debug::DEBUG, "clear new word: "
|
|
|
|
<< " par: " << pit()
|
|
|
|
<< " pos: " << pos());
|
|
|
|
new_word_.resize(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::checkNewWordPosition()
|
|
|
|
{
|
|
|
|
if (!lyxrc.spellcheck_continuously || new_word_.empty())
|
|
|
|
return ;
|
2018-01-31 15:26:45 +00:00
|
|
|
// forget the position of the current new word if
|
|
|
|
// 1) or the remembered position was "broken"
|
|
|
|
// 2) or the count of nested insets changed
|
|
|
|
// 3) the top-level inset is not the same anymore
|
|
|
|
// 4) the cell index changed
|
|
|
|
// 5) or the paragraph changed
|
|
|
|
// 6) or the cursor pos is out of paragraph bound
|
|
|
|
if (new_word_.fixIfBroken()
|
|
|
|
|| depth() != new_word_.depth()
|
|
|
|
|| &inset() != &new_word_.inset()
|
|
|
|
|| pit() != new_word_.pit()
|
|
|
|
|| idx() != new_word_.idx()
|
|
|
|
|| new_word_.pos() > new_word_.lastpos())
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
clearNewWordPosition();
|
2018-01-31 15:26:45 +00:00
|
|
|
else {
|
|
|
|
FontSpan nw = locateWord(WHOLE_WORD);
|
|
|
|
if (!nw.empty()) {
|
|
|
|
FontSpan ow = new_word_.locateWord(WHOLE_WORD);
|
|
|
|
if (nw.intersect(ow).empty())
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
clearNewWordPosition();
|
2018-01-31 15:26:45 +00:00
|
|
|
else
|
|
|
|
LYXERR(Debug::DEBUG, "new word: "
|
|
|
|
<< " par: " << pit()
|
|
|
|
<< " pos: " << nw.first << ".." << nw.last);
|
|
|
|
} else
|
|
|
|
clearNewWordPosition();
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::clearSelection()
|
|
|
|
{
|
|
|
|
selection(false);
|
|
|
|
setWordSelection(false);
|
|
|
|
setMark(false);
|
|
|
|
resetAnchor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-21 08:35:40 +00:00
|
|
|
int CursorData::countInsetsInSelection(InsetCode const & inset_code) const
|
2018-05-02 20:35:09 +00:00
|
|
|
{
|
|
|
|
if (!selection_)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
DocIterator from, to;
|
|
|
|
from = selectionBegin();
|
|
|
|
to = selectionEnd();
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (!from.nextInset()) //move to closest inset
|
|
|
|
from.forwardInset();
|
|
|
|
|
|
|
|
while (!from.empty() && from < to) {
|
|
|
|
Inset * inset = from.nextInset();
|
|
|
|
if (!inset)
|
|
|
|
break;
|
|
|
|
if (inset->lyxCode() == inset_code)
|
|
|
|
count ++;
|
|
|
|
from.forwardInset();
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-21 08:35:40 +00:00
|
|
|
bool CursorData::insetInSelection(InsetCode const & inset_code) const
|
2018-05-02 20:35:09 +00:00
|
|
|
{
|
|
|
|
if (!selection_)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DocIterator from, to;
|
|
|
|
from = selectionBegin();
|
|
|
|
to = selectionEnd();
|
|
|
|
|
|
|
|
if (!from.nextInset()) //move to closest inset
|
|
|
|
from.forwardInset();
|
|
|
|
|
|
|
|
while (!from.empty() && from < to) {
|
|
|
|
Inset * inset = from.nextInset();
|
|
|
|
if (!inset)
|
|
|
|
break;
|
|
|
|
if (inset->lyxCode() == inset_code)
|
|
|
|
return true;
|
|
|
|
from.forwardInset();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
bool CursorData::fixIfBroken()
|
|
|
|
{
|
|
|
|
bool const broken_cursor = DocIterator::fixIfBroken();
|
|
|
|
bool const broken_anchor = anchor_.fixIfBroken();
|
|
|
|
|
|
|
|
if (broken_cursor || broken_anchor) {
|
|
|
|
clearNewWordPosition();
|
|
|
|
clearSelection();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::sanitize()
|
|
|
|
{
|
|
|
|
DocIterator::sanitize();
|
2018-01-16 15:00:07 +00:00
|
|
|
new_word_.sanitize();
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
if (selection())
|
|
|
|
anchor_.sanitize();
|
|
|
|
else
|
|
|
|
resetAnchor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-26 14:47:25 +00:00
|
|
|
bool CursorData::undoAction()
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
{
|
2018-08-26 14:47:25 +00:00
|
|
|
if (!buffer()->undo().undoAction(*this))
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
return false;
|
|
|
|
sanitize();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-26 14:47:25 +00:00
|
|
|
bool CursorData::redoAction()
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
{
|
2018-08-26 14:47:25 +00:00
|
|
|
if (!buffer()->undo().redoAction(*this))
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
return false;
|
|
|
|
sanitize();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::finishUndo() const
|
|
|
|
{
|
|
|
|
buffer()->undo().finishUndo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::beginUndoGroup() const
|
|
|
|
{
|
|
|
|
buffer()->undo().beginUndoGroup(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::endUndoGroup() const
|
|
|
|
{
|
|
|
|
buffer()->undo().endUndoGroup(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-15 09:12:25 +00:00
|
|
|
void CursorData::splitUndoGroup() const
|
|
|
|
{
|
|
|
|
buffer()->undo().splitUndoGroup(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
void CursorData::recordUndo(pit_type from, pit_type to) const
|
|
|
|
{
|
|
|
|
buffer()->undo().recordUndo(*this, from, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::recordUndo(pit_type from) const
|
|
|
|
{
|
|
|
|
buffer()->undo().recordUndo(*this, from, pit());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::recordUndo(UndoKind kind) const
|
|
|
|
{
|
|
|
|
buffer()->undo().recordUndo(*this, kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 17:18:51 +00:00
|
|
|
void CursorData::recordUndoInset(Inset const * inset) const
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
{
|
2020-10-31 17:18:51 +00:00
|
|
|
buffer()->undo().recordUndoInset(*this, inset);
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::recordUndoFullBuffer() const
|
|
|
|
{
|
|
|
|
buffer()->undo().recordUndoFullBuffer(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::recordUndoBufferParams() const
|
|
|
|
{
|
|
|
|
buffer()->undo().recordUndoBufferParams(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CursorData::recordUndoSelection() const
|
|
|
|
{
|
|
|
|
if (inMathed()) {
|
|
|
|
if (cap::multipleCellsSelected(*this))
|
|
|
|
recordUndoInset();
|
|
|
|
else
|
|
|
|
recordUndo();
|
|
|
|
} else {
|
|
|
|
buffer()->undo().recordUndo(*this,
|
|
|
|
selBegin().pit(), selEnd().pit());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-21 08:35:40 +00:00
|
|
|
int CursorData::currentMode() const
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
{
|
|
|
|
LASSERT(!empty(), return Inset::UNDECIDED_MODE);
|
|
|
|
for (int i = depth() - 1; i >= 0; --i) {
|
|
|
|
int res = operator[](i).inset().currentMode();
|
|
|
|
bool locked_mode = operator[](i).inset().lockedMode();
|
|
|
|
// Also return UNDECIDED_MODE when the mode is locked,
|
|
|
|
// as in this case it is treated the same as TEXT_MODE
|
|
|
|
if (res != Inset::UNDECIDED_MODE || locked_mode)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
return Inset::TEXT_MODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CursorData::confirmDeletion(bool const before) const
|
|
|
|
{
|
|
|
|
if (!selection()) {
|
|
|
|
if (Inset const * inset = before ? prevInset() : nextInset())
|
|
|
|
return inset->confirmDeletion();
|
|
|
|
} else {
|
|
|
|
DocIterator dit = selectionBegin();
|
|
|
|
CursorSlice const end = selectionEnd().top();
|
|
|
|
for (; dit.top() < end; dit.top().forwardPos())
|
|
|
|
if (Inset const * inset = dit.nextInset())
|
|
|
|
if (inset->confirmDeletion())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Cursor
|
|
|
|
//
|
2015-03-10 14:53:25 +00:00
|
|
|
|
|
|
|
|
2004-12-03 16:39:59 +00:00
|
|
|
// be careful: this is called from the bv's constructor, too, so
|
2004-11-30 01:59:49 +00:00
|
|
|
// bv functions are not yet available!
|
2007-04-26 14:56:30 +00:00
|
|
|
Cursor::Cursor(BufferView & bv)
|
2014-03-14 13:22:26 +00:00
|
|
|
: CursorData(&bv.buffer()), bv_(&bv),
|
2015-03-04 22:00:07 +00:00
|
|
|
x_target_(-1), textTargetOffset_(0),
|
|
|
|
beforeDispatchPosX_(0), beforeDispatchPosY_(0)
|
2003-11-10 09:06:48 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2009-10-29 22:46:04 +00:00
|
|
|
void Cursor::reset()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
CursorData::reset();
|
2004-01-30 11:41:12 +00:00
|
|
|
clearTargetX();
|
2012-07-15 16:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::setCursorData(CursorData const & data)
|
|
|
|
{
|
|
|
|
CursorData::operator=(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-13 14:32:51 +00:00
|
|
|
bool Cursor::getStatus(FuncRequest const & cmd, FuncStatus & status) const
|
|
|
|
{
|
|
|
|
Cursor cur = *this;
|
|
|
|
|
|
|
|
// Try to fix cursor in case it is broken.
|
|
|
|
cur.fixIfBroken();
|
|
|
|
|
|
|
|
// Is this a function that acts on inset at point?
|
|
|
|
Inset * inset = cur.nextInset();
|
2010-04-09 19:00:42 +00:00
|
|
|
if (lyxaction.funcHasFlag(cmd.action(), LyXAction::AtPoint)
|
2009-11-13 14:32:51 +00:00
|
|
|
&& inset && inset->getStatus(cur, cmd, status))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// This is, of course, a mess. Better create a new doc iterator and use
|
|
|
|
// this in Inset::getStatus. This might require an additional
|
|
|
|
// BufferView * arg, though (which should be avoided)
|
|
|
|
//Cursor safe = *this;
|
|
|
|
bool res = false;
|
|
|
|
for ( ; cur.depth(); cur.pop()) {
|
|
|
|
//lyxerr << "\nCursor::getStatus: cmd: " << cmd << endl << *this << endl;
|
2013-04-25 21:27:10 +00:00
|
|
|
// LASSERT: Is it safe to continue here, or should we return?
|
2009-11-13 14:32:51 +00:00
|
|
|
LASSERT(cur.idx() <= cur.lastidx(), /**/);
|
|
|
|
LASSERT(cur.pit() <= cur.lastpit(), /**/);
|
|
|
|
LASSERT(cur.pos() <= cur.lastpos(), /**/);
|
|
|
|
|
|
|
|
// The inset's getStatus() will return 'true' if it made
|
|
|
|
// a definitive decision on whether it want to handle the
|
|
|
|
// request or not. The result of this decision is put into
|
|
|
|
// the 'status' parameter.
|
|
|
|
if (cur.inset().getStatus(cur, cmd, status)) {
|
|
|
|
res = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-09 14:29:27 +00:00
|
|
|
void Cursor::saveBeforeDispatchPosXY()
|
|
|
|
{
|
|
|
|
getPos(beforeDispatchPosX_, beforeDispatchPosY_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::dispatch(FuncRequest const & cmd0)
|
2003-09-17 16:44:51 +00:00
|
|
|
{
|
2015-07-08 08:57:04 +00:00
|
|
|
LYXERR(Debug::ACTION, "Cursor::dispatch: cmd: " << cmd0 << '\n' << *this);
|
2004-03-18 12:53:43 +00:00
|
|
|
if (empty())
|
2004-08-13 14:56:06 +00:00
|
|
|
return;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
2005-02-15 17:34:54 +00:00
|
|
|
fixIfBroken();
|
2003-11-10 09:06:48 +00:00
|
|
|
FuncRequest cmd = cmd0;
|
2007-04-26 14:56:30 +00:00
|
|
|
Cursor safe = *this;
|
2010-12-05 00:57:04 +00:00
|
|
|
Cursor old = *this;
|
2010-10-17 12:06:47 +00:00
|
|
|
disp_ = DispatchResult();
|
2009-10-03 19:12:21 +00:00
|
|
|
|
2012-02-07 14:56:16 +00:00
|
|
|
beginUndoGroup();
|
2010-11-29 09:47:46 +00:00
|
|
|
|
2009-11-13 14:32:51 +00:00
|
|
|
// Is this a function that acts on inset at point?
|
2010-04-09 19:00:42 +00:00
|
|
|
if (lyxaction.funcHasFlag(cmd.action(), LyXAction::AtPoint)
|
2009-11-13 14:32:51 +00:00
|
|
|
&& nextInset()) {
|
2010-04-15 17:14:59 +00:00
|
|
|
disp_.dispatched(true);
|
2010-10-13 17:28:55 +00:00
|
|
|
disp_.screenUpdate(Update::FitCursor | Update::Force);
|
2009-11-13 14:32:51 +00:00
|
|
|
FuncRequest tmpcmd = cmd;
|
|
|
|
LYXERR(Debug::DEBUG, "Cursor::dispatch: (AtPoint) cmd: "
|
|
|
|
<< cmd0 << endl << *this);
|
|
|
|
nextInset()->dispatch(*this, tmpcmd);
|
2010-04-15 17:14:59 +00:00
|
|
|
if (disp_.dispatched()) {
|
2012-02-07 14:56:16 +00:00
|
|
|
endUndoGroup();
|
2009-11-13 14:32:51 +00:00
|
|
|
return;
|
2010-01-21 16:59:39 +00:00
|
|
|
}
|
2009-11-13 14:32:51 +00:00
|
|
|
}
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// store some values to be used inside of the handlers
|
2007-06-14 20:32:28 +00:00
|
|
|
beforeDispatchCursor_ = *this;
|
2008-02-29 08:27:22 +00:00
|
|
|
for (; depth(); pop(), boundary(false)) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "Cursor::dispatch: cmd: "
|
|
|
|
<< cmd0 << endl << *this);
|
2014-02-16 01:53:03 +00:00
|
|
|
|
|
|
|
// In any of these cases, the cursor is invalid, and we should
|
|
|
|
// try to save this document rather than crash.
|
|
|
|
LBUFERR(pos() <= lastpos());
|
|
|
|
LBUFERR(idx() <= lastidx());
|
|
|
|
LBUFERR(pit() <= lastpit());
|
2004-03-18 12:53:43 +00:00
|
|
|
|
2004-04-03 08:37:12 +00:00
|
|
|
// The common case is 'LFUN handled, need update', so make the
|
2004-03-18 12:53:43 +00:00
|
|
|
// LFUN handler's life easier by assuming this as default value.
|
|
|
|
// The handler can reset the update and val flags if necessary.
|
2010-10-13 17:28:55 +00:00
|
|
|
disp_.screenUpdate(Update::FitCursor | Update::Force);
|
2004-03-18 12:53:43 +00:00
|
|
|
disp_.dispatched(true);
|
|
|
|
inset().dispatch(*this, cmd);
|
|
|
|
if (disp_.dispatched())
|
|
|
|
break;
|
2003-09-17 16:44:51 +00:00
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
// it completely to get a 'bomb early' behaviour in case this
|
|
|
|
// object will be used again.
|
2004-03-25 09:16:36 +00:00
|
|
|
if (!disp_.dispatched()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "RESTORING OLD CURSOR!");
|
2009-04-15 20:20:42 +00:00
|
|
|
// We might have invalidated the cursor when removing an empty
|
|
|
|
// paragraph while the cursor could not be moved out the inset
|
|
|
|
// while we initially thought we could. This might happen when
|
2014-03-14 13:22:26 +00:00
|
|
|
// a multiline inset becomes an inline inset when the second
|
2009-04-15 20:20:42 +00:00
|
|
|
// paragraph is removed.
|
|
|
|
if (safe.pit() > safe.lastpit()) {
|
|
|
|
safe.pit() = safe.lastpit();
|
|
|
|
safe.pos() = safe.lastpos();
|
|
|
|
}
|
2004-03-18 13:57:20 +00:00
|
|
|
operator=(safe);
|
2010-10-13 17:28:55 +00:00
|
|
|
disp_.screenUpdate(Update::None);
|
2004-04-07 20:20:15 +00:00
|
|
|
disp_.dispatched(false);
|
2007-06-14 20:32:28 +00:00
|
|
|
} else {
|
|
|
|
// restore the previous one because nested Cursor::dispatch calls
|
|
|
|
// are possible which would change it
|
|
|
|
beforeDispatchCursor_ = safe.beforeDispatchCursor_;
|
2004-03-25 09:16:36 +00:00
|
|
|
}
|
2012-02-07 14:56:16 +00:00
|
|
|
endUndoGroup();
|
2010-12-05 00:57:04 +00:00
|
|
|
|
2015-06-05 09:43:05 +00:00
|
|
|
// NOTE: The code below has been copied to BufferView::dispatch.
|
|
|
|
// If you need to modify this, please update the other one too.
|
|
|
|
|
2010-12-05 00:57:04 +00:00
|
|
|
// notify insets we just left
|
|
|
|
if (*this != old) {
|
|
|
|
old.beginUndoGroup();
|
|
|
|
old.fixIfBroken();
|
|
|
|
bool badcursor = notifyCursorLeavesOrEnters(old, *this);
|
|
|
|
if (badcursor) {
|
|
|
|
fixIfBroken();
|
2011-02-21 15:26:28 +00:00
|
|
|
bv().resetInlineCompletionPos();
|
2010-12-05 00:57:04 +00:00
|
|
|
}
|
|
|
|
old.endUndoGroup();
|
|
|
|
}
|
2004-08-13 14:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-15 17:14:59 +00:00
|
|
|
DispatchResult const & Cursor::result() const
|
2004-08-13 14:56:06 +00:00
|
|
|
{
|
2004-02-16 11:58:51 +00:00
|
|
|
return disp_;
|
2003-09-17 16:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
void Cursor::message(docstring const & msg) const
|
|
|
|
{
|
|
|
|
disp_.setMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::errorMessage(docstring const & msg) const
|
|
|
|
{
|
|
|
|
disp_.setMessage(msg);
|
|
|
|
disp_.setError(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
BufferView & Cursor::bv() const
|
2003-11-06 10:30:43 +00:00
|
|
|
{
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(bv_);
|
2004-03-18 12:53:43 +00:00
|
|
|
return *bv_;
|
2004-03-11 17:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::pop()
|
2003-11-04 12:36:59 +00:00
|
|
|
{
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(depth() >= 1);
|
2004-03-01 17:12:09 +00:00
|
|
|
pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 17:18:51 +00:00
|
|
|
void Cursor::push(Inset & inset)
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2020-10-31 17:18:51 +00:00
|
|
|
push_back(CursorSlice(inset));
|
|
|
|
inset.setBuffer(*buffer());
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 17:18:51 +00:00
|
|
|
void Cursor::pushBackward(Inset & inset)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
LASSERT(!empty(), return);
|
2007-11-05 19:41:16 +00:00
|
|
|
//lyxerr << "Entering inset " << t << " front" << endl;
|
2020-10-31 17:18:51 +00:00
|
|
|
push(inset);
|
|
|
|
inset.idxFirst(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-06 07:29:22 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
bool Cursor::popBackward()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
LASSERT(!empty(), return false);
|
2004-03-18 16:05:32 +00:00
|
|
|
if (depth() == 1)
|
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
pop();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
bool Cursor::popForward()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
LASSERT(!empty(), return false);
|
2007-11-05 19:41:16 +00:00
|
|
|
//lyxerr << "Leaving inset from in back" << endl;
|
2006-12-29 14:17:48 +00:00
|
|
|
const pos_type lp = (depth() > 1) ? (*this)[depth() - 2].lastpos() : 0;
|
2004-03-18 16:05:32 +00:00
|
|
|
if (depth() == 1)
|
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
pop();
|
2006-12-29 14:17:48 +00:00
|
|
|
pos() += lastpos() - lp + 1;
|
2004-01-26 10:13:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::getPos(int & x, int & y) const
|
2003-11-10 09:06:48 +00:00
|
|
|
{
|
2010-04-21 13:03:04 +00:00
|
|
|
Point p = bv().getPos(*this);
|
2004-11-30 01:59:49 +00:00
|
|
|
x = p.x_;
|
|
|
|
y = p.y_;
|
2003-11-10 09:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
Row const & Cursor::textRow() const
|
2006-12-19 13:39:46 +00:00
|
|
|
{
|
2007-12-22 09:25:59 +00:00
|
|
|
CursorSlice const & cs = innerTextSlice();
|
|
|
|
ParagraphMetrics const & pm = bv().parMetrics(cs.text(), cs.pit());
|
2006-12-29 23:54:48 +00:00
|
|
|
return pm.getRow(pos(), boundary());
|
2006-12-19 13:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
bool Cursor::posVisRight(bool skip_inset)
|
|
|
|
{
|
|
|
|
Cursor new_cur = *this; // where we will move to
|
|
|
|
pos_type left_pos; // position visually left of current cursor
|
|
|
|
pos_type right_pos; // position visually right of current cursor
|
|
|
|
|
|
|
|
getSurroundingPos(left_pos, right_pos);
|
|
|
|
|
|
|
|
LYXERR(Debug::RTL, left_pos <<"|"<< right_pos << " (pos: "<< pos() <<")");
|
|
|
|
|
|
|
|
// Are we at an inset?
|
|
|
|
new_cur.pos() = right_pos;
|
|
|
|
new_cur.boundary(false);
|
|
|
|
if (!skip_inset &&
|
2008-08-13 19:58:00 +00:00
|
|
|
text()->checkAndActivateInsetVisual(new_cur, right_pos >= pos(), false)) {
|
2012-10-27 13:45:27 +00:00
|
|
|
// we actually move the cursor at the end of this
|
|
|
|
// function, for now we just keep track of the new
|
|
|
|
// position in new_cur...
|
2008-05-04 20:17:59 +00:00
|
|
|
LYXERR(Debug::RTL, "entering inset at: " << new_cur.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we already at rightmost pos in row?
|
|
|
|
else if (text()->empty() || right_pos == -1) {
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
new_cur = *this;
|
|
|
|
if (!new_cur.posVisToNewRow(false)) {
|
|
|
|
LYXERR(Debug::RTL, "not moving!");
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
// we actually move the cursor at the end of this
|
|
|
|
// function, for now just keep track of the new
|
|
|
|
// position in new_cur...
|
2014-03-14 13:22:26 +00:00
|
|
|
LYXERR(Debug::RTL, "right edge, moving: " << int(new_cur.pit()) << ","
|
2008-05-04 20:17:59 +00:00
|
|
|
<< int(new_cur.pos()) << "," << (new_cur.boundary() ? 1 : 0));
|
|
|
|
|
|
|
|
}
|
|
|
|
// normal movement to the right
|
|
|
|
else {
|
|
|
|
new_cur = *this;
|
2012-10-27 13:45:27 +00:00
|
|
|
// Recall, if the cursor is at position 'x', that
|
|
|
|
// means *before* the character at position 'x'. In
|
|
|
|
// RTL, "before" means "to the right of", in LTR, "to
|
|
|
|
// the left of". So currently our situation is this:
|
|
|
|
// the position to our right is 'right_pos' (i.e.,
|
|
|
|
// we're currently to the left of 'right_pos'). In
|
|
|
|
// order to move to the right, it depends whether or
|
|
|
|
// not the character at 'right_pos' is RTL.
|
2014-04-04 19:54:32 +00:00
|
|
|
bool const new_pos_is_RTL = paragraph().getFontSettings(
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->params(), right_pos).isVisibleRightToLeft();
|
2012-10-27 13:45:27 +00:00
|
|
|
// If the character at 'right_pos' *is* LTR, then in
|
|
|
|
// order to move to the right of it, we need to be
|
|
|
|
// *after* 'right_pos', i.e., move to position
|
|
|
|
// 'right_pos' + 1.
|
2008-05-04 20:17:59 +00:00
|
|
|
if (!new_pos_is_RTL) {
|
|
|
|
new_cur.pos() = right_pos + 1;
|
|
|
|
// set the boundary to true in two situations:
|
|
|
|
if (
|
2012-10-27 13:45:27 +00:00
|
|
|
// 1. if new_pos is now lastpos, and we're in
|
|
|
|
// an RTL paragraph (this means that we're
|
|
|
|
// moving right to the end of an LTR chunk
|
2008-11-01 17:00:58 +00:00
|
|
|
// which is at the end of an RTL paragraph);
|
|
|
|
(new_cur.pos() == lastpos()
|
2008-11-17 11:46:07 +00:00
|
|
|
&& paragraph().isRTL(buffer()->params()))
|
2012-10-27 13:45:27 +00:00
|
|
|
// 2. if the position *after* right_pos is RTL
|
|
|
|
// (we want to be *after* right_pos, not
|
|
|
|
// before right_pos + 1!)
|
2008-11-17 11:46:07 +00:00
|
|
|
|| paragraph().getFontSettings(buffer()->params(),
|
2008-05-04 20:17:59 +00:00
|
|
|
new_cur.pos()).isVisibleRightToLeft()
|
|
|
|
)
|
|
|
|
new_cur.boundary(true);
|
|
|
|
else // set the boundary to false
|
|
|
|
new_cur.boundary(false);
|
|
|
|
}
|
2012-10-27 13:45:27 +00:00
|
|
|
// Otherwise (if the character at position 'right_pos'
|
|
|
|
// is RTL), then moving to the right of it is as easy
|
|
|
|
// as setting the new position to 'right_pos'.
|
2008-05-04 20:17:59 +00:00
|
|
|
else {
|
|
|
|
new_cur.pos() = right_pos;
|
|
|
|
new_cur.boundary(false);
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 09:10:26 +00:00
|
|
|
bool const moved = new_cur != *this || new_cur.boundary() != boundary();
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
if (moved) {
|
2014-03-14 13:22:26 +00:00
|
|
|
LYXERR(Debug::RTL, "moving to: " << new_cur.pos()
|
2008-05-04 20:17:59 +00:00
|
|
|
<< (new_cur.boundary() ? " (boundary)" : ""));
|
|
|
|
*this = new_cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
return moved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::posVisLeft(bool skip_inset)
|
|
|
|
{
|
|
|
|
Cursor new_cur = *this; // where we will move to
|
|
|
|
pos_type left_pos; // position visually left of current cursor
|
|
|
|
pos_type right_pos; // position visually right of current cursor
|
|
|
|
|
|
|
|
getSurroundingPos(left_pos, right_pos);
|
|
|
|
|
|
|
|
LYXERR(Debug::RTL, left_pos <<"|"<< right_pos << " (pos: "<< pos() <<")");
|
|
|
|
|
|
|
|
// Are we at an inset?
|
|
|
|
new_cur.pos() = left_pos;
|
|
|
|
new_cur.boundary(false);
|
2014-03-14 13:22:26 +00:00
|
|
|
if (!skip_inset &&
|
2008-05-04 20:17:59 +00:00
|
|
|
text()->checkAndActivateInsetVisual(new_cur, left_pos >= pos(), true)) {
|
2012-10-27 13:45:27 +00:00
|
|
|
// we actually move the cursor at the end of this
|
|
|
|
// function, for now we just keep track of the new
|
|
|
|
// position in new_cur...
|
2008-05-04 20:17:59 +00:00
|
|
|
LYXERR(Debug::RTL, "entering inset at: " << new_cur.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we already at leftmost pos in row?
|
|
|
|
else if (text()->empty() || left_pos == -1) {
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
new_cur = *this;
|
|
|
|
if (!new_cur.posVisToNewRow(true)) {
|
|
|
|
LYXERR(Debug::RTL, "not moving!");
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
// we actually move the cursor at the end of this
|
|
|
|
// function, for now just keep track of the new
|
|
|
|
// position in new_cur...
|
2014-03-14 13:22:26 +00:00
|
|
|
LYXERR(Debug::RTL, "left edge, moving: " << int(new_cur.pit()) << ","
|
2008-05-04 20:17:59 +00:00
|
|
|
<< int(new_cur.pos()) << "," << (new_cur.boundary() ? 1 : 0));
|
|
|
|
|
|
|
|
}
|
|
|
|
// normal movement to the left
|
|
|
|
else {
|
|
|
|
new_cur = *this;
|
2012-10-27 13:45:27 +00:00
|
|
|
// Recall, if the cursor is at position 'x', that
|
|
|
|
// means *before* the character at position 'x'. In
|
|
|
|
// RTL, "before" means "to the right of", in LTR, "to
|
|
|
|
// the left of". So currently our situation is this:
|
|
|
|
// the position to our left is 'left_pos' (i.e., we're
|
|
|
|
// currently to the right of 'left_pos'). In order to
|
|
|
|
// move to the left, it depends whether or not the
|
|
|
|
// character at 'left_pos' is RTL.
|
2014-04-04 19:54:32 +00:00
|
|
|
bool const new_pos_is_RTL = paragraph().getFontSettings(
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->params(), left_pos).isVisibleRightToLeft();
|
2012-10-27 13:45:27 +00:00
|
|
|
// If the character at 'left_pos' *is* RTL, then in
|
|
|
|
// order to move to the left of it, we need to be
|
|
|
|
// *after* 'left_pos', i.e., move to position
|
|
|
|
// 'left_pos' + 1.
|
2008-05-04 20:17:59 +00:00
|
|
|
if (new_pos_is_RTL) {
|
|
|
|
new_cur.pos() = left_pos + 1;
|
|
|
|
// set the boundary to true in two situations:
|
|
|
|
if (
|
2012-10-27 13:45:27 +00:00
|
|
|
// 1. if new_pos is now lastpos and we're in
|
|
|
|
// an LTR paragraph (this means that we're
|
|
|
|
// moving left to the end of an RTL chunk
|
2008-11-01 17:00:58 +00:00
|
|
|
// which is at the end of an LTR paragraph);
|
|
|
|
(new_cur.pos() == lastpos()
|
2008-11-17 11:46:07 +00:00
|
|
|
&& !paragraph().isRTL(buffer()->params()))
|
2012-10-27 13:45:27 +00:00
|
|
|
// 2. if the position *after* left_pos is not
|
|
|
|
// RTL (we want to be *after* left_pos, not
|
|
|
|
// before left_pos + 1!)
|
2008-11-17 11:46:07 +00:00
|
|
|
|| !paragraph().getFontSettings(buffer()->params(),
|
2008-05-04 20:17:59 +00:00
|
|
|
new_cur.pos()).isVisibleRightToLeft()
|
|
|
|
)
|
|
|
|
new_cur.boundary(true);
|
|
|
|
else // set the boundary to false
|
|
|
|
new_cur.boundary(false);
|
|
|
|
}
|
2012-10-27 13:45:27 +00:00
|
|
|
// Otherwise (if the character at position 'left_pos'
|
|
|
|
// is LTR), then moving to the left of it is as easy
|
|
|
|
// as setting the new position to 'left_pos'.
|
2008-05-04 20:17:59 +00:00
|
|
|
else {
|
|
|
|
new_cur.pos() = left_pos;
|
|
|
|
new_cur.boundary(false);
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 09:10:26 +00:00
|
|
|
bool const moved = new_cur != *this || new_cur.boundary() != boundary();
|
2008-05-04 20:17:59 +00:00
|
|
|
|
|
|
|
if (moved) {
|
2014-03-14 13:22:26 +00:00
|
|
|
LYXERR(Debug::RTL, "moving to: " << new_cur.pos()
|
2008-05-04 20:17:59 +00:00
|
|
|
<< (new_cur.boundary() ? " (boundary)" : ""));
|
|
|
|
*this = new_cur;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
return moved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-14 20:13:39 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Return true on success
|
|
|
|
bool findNonVirtual(Row const & row, Row::const_iterator & cit, bool onleft)
|
|
|
|
{
|
|
|
|
if (onleft) {
|
|
|
|
while (cit != row.begin() && cit->isVirtual())
|
|
|
|
--cit;
|
|
|
|
} else {
|
|
|
|
while (cit != row.end() && cit->isVirtual())
|
|
|
|
++cit;
|
|
|
|
}
|
|
|
|
return cit != row.end() && !cit->isVirtual();
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2015-09-14 20:13:39 +00:00
|
|
|
|
2015-10-09 13:10:39 +00:00
|
|
|
void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos) const
|
2015-09-14 20:13:39 +00:00
|
|
|
{
|
|
|
|
// by default, we know nothing.
|
|
|
|
left_pos = -1;
|
|
|
|
right_pos = -1;
|
|
|
|
|
|
|
|
Row const & row = textRow();
|
|
|
|
double dummy = 0;
|
2017-02-02 14:23:20 +00:00
|
|
|
Row::const_iterator cit = row.findElement(pos(), boundary(), dummy);
|
2015-09-14 20:13:39 +00:00
|
|
|
// Handle the case of empty row
|
|
|
|
if (cit == row.end()) {
|
2016-12-07 11:16:41 +00:00
|
|
|
if (row.isRTL())
|
2015-09-14 20:13:39 +00:00
|
|
|
right_pos = row.pos();
|
|
|
|
else
|
|
|
|
left_pos = row.pos() - 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip virtual elements and exit if no non-virtual one exists
|
|
|
|
if (!findNonVirtual(row, cit, !cit->isRTL()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if the position is at the left side of the element, we have to
|
|
|
|
// look at the previous element
|
|
|
|
if (pos() == cit->left_pos()) {
|
|
|
|
LYXERR(Debug::RTL, "getSurroundingPos(" << pos() << (boundary() ? "b" : "")
|
|
|
|
<< "), AT LEFT of *cit=" << *cit);
|
|
|
|
// this one is easy (see common case below)
|
|
|
|
right_pos = pos() - (cit->isRTL() ? 1 : 0);
|
|
|
|
// at the left of the row
|
|
|
|
if (cit == row.begin())
|
|
|
|
return;
|
|
|
|
--cit;
|
|
|
|
if (!findNonVirtual(row, cit, true))
|
|
|
|
return;
|
|
|
|
// [...[ is the row element, | is cursor position (! with boundary)
|
|
|
|
// [ 1 2 [ is a ltr row element with pos=1 and endpos=3
|
|
|
|
// ] 2 1] is an rtl row element with pos=1 and endpos=3
|
|
|
|
// [ 1 2 [ [|3 4 [ => (2, 3)
|
|
|
|
// or [ 1 2 [ ]!4 3 ] => (2, 4)
|
|
|
|
// or ] 2 1 ] [|3 4 [ => (1, 3)
|
|
|
|
// or ] 4 3 ] ]!2 1 ] => (3, 2)
|
|
|
|
left_pos = cit->right_pos() - (cit->isRTL() ? 0 : 1);
|
|
|
|
// happens with consecutive row of same direction
|
|
|
|
if (left_pos == right_pos) {
|
|
|
|
left_pos += cit->isRTL() ? 1 : -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// same code but with the element at the right
|
|
|
|
else if (pos() == cit->right_pos()) {
|
|
|
|
LYXERR(Debug::RTL, "getSurroundingPos(" << pos() << (boundary() ? "b" : "")
|
|
|
|
<< "), AT RIGHT of *cit=" << *cit);
|
|
|
|
// this one is easy (see common case below)
|
|
|
|
left_pos = pos() - (cit->isRTL() ? 0 : 1);
|
|
|
|
// at the right of the row
|
|
|
|
if (cit + 1 == row.end())
|
|
|
|
return;
|
|
|
|
++cit;
|
|
|
|
if (!findNonVirtual(row, cit, false))
|
|
|
|
return;
|
|
|
|
// [ 1 2![ [ 3 4 [ => (2, 3)
|
|
|
|
// or [ 1 2![ ] 4 3 ] => (2, 4)
|
|
|
|
// or ] 2 1|] [ 3 4 [ => (1, 3)
|
|
|
|
// or ] 4 3|] ] 2 1 ] => (3, 2)
|
|
|
|
right_pos = cit->left_pos() - (cit->isRTL() ? 1 : 0);
|
|
|
|
// happens with consecutive row of same direction
|
|
|
|
if (right_pos == left_pos)
|
|
|
|
right_pos += cit->isRTL() ? -1 : 1;
|
|
|
|
}
|
|
|
|
// common case: both positions are inside the row element
|
|
|
|
else {
|
|
|
|
// [ 1 2|3 [ => (2, 3)
|
|
|
|
// or ] 3|2 1 ] => (3, 2)
|
|
|
|
left_pos = pos() - (cit->isRTL() ? 0 : 1);
|
|
|
|
right_pos = pos() - (cit->isRTL() ? 1 : 0);
|
|
|
|
}
|
2008-02-10 19:52:45 +00:00
|
|
|
|
2015-10-09 13:10:39 +00:00
|
|
|
// Note that debug message does not catch all early returns above
|
2015-09-14 20:13:39 +00:00
|
|
|
LYXERR(Debug::RTL,"getSurroundingPos(" << pos() << (boundary() ? "b" : "")
|
|
|
|
<< ") => (" << left_pos << ", " << right_pos <<")");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-10 19:52:45 +00:00
|
|
|
bool Cursor::posVisToNewRow(bool movingLeft)
|
|
|
|
{
|
|
|
|
Row const & row = textRow();
|
2016-12-07 11:16:41 +00:00
|
|
|
bool par_is_LTR = !row.isRTL();
|
2008-04-11 12:02:10 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
// Inside a table, determining whether to move to the next or
|
|
|
|
// previous row should be done based on the table's direction.
|
2015-10-09 13:48:59 +00:00
|
|
|
if (inset().asInsetTabular()) {
|
|
|
|
par_is_LTR = !inset().asInsetTabular()->isRightToLeft(*this);
|
2008-04-11 12:02:10 +00:00
|
|
|
LYXERR(Debug::RTL, "Inside table! par_is_LTR=" << (par_is_LTR ? 1 : 0));
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
// if moving left in an LTR paragraph or moving right in an
|
|
|
|
// RTL one, move to previous row
|
2008-02-10 19:52:45 +00:00
|
|
|
if (par_is_LTR == movingLeft) {
|
|
|
|
if (row.pos() == 0) { // we're at first row in paragraph
|
|
|
|
if (pit() == 0) // no previous paragraph! don't move
|
|
|
|
return false;
|
|
|
|
// move to last pos in previous par
|
|
|
|
--pit();
|
|
|
|
pos() = lastpos();
|
|
|
|
boundary(false);
|
|
|
|
} else { // move to previous row in this par
|
|
|
|
pos() = row.pos() - 1; // this is guaranteed to be in previous row
|
|
|
|
boundary(false);
|
|
|
|
}
|
|
|
|
}
|
2012-10-27 13:45:27 +00:00
|
|
|
// if moving left in an RTL paragraph or moving right in an
|
|
|
|
// LTR one, move to next row
|
2008-02-10 19:52:45 +00:00
|
|
|
else {
|
|
|
|
if (row.endpos() == lastpos()) { // we're at last row in paragraph
|
|
|
|
if (pit() == lastpit()) // last paragraph! don't move
|
|
|
|
return false;
|
|
|
|
// move to first row in next par
|
|
|
|
++pit();
|
|
|
|
pos() = 0;
|
|
|
|
boundary(false);
|
|
|
|
} else { // move to next row in this par
|
|
|
|
pos() = row.endpos();
|
|
|
|
boundary(false);
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
}
|
2005-11-07 15:02:08 +00:00
|
|
|
}
|
2004-01-20 14:25:24 +00:00
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
// make sure we're at left-/right-most pos in new row
|
|
|
|
posVisToRowExtremity(!movingLeft);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
return true;
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
void Cursor::posVisToRowExtremity(bool left)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
LYXERR(Debug::RTL, "entering extremity: " << pit() << "," << pos() << ","
|
|
|
|
<< (boundary() ? 1 : 0));
|
|
|
|
|
|
|
|
TextMetrics const & tm = bv_->textMetrics(text());
|
|
|
|
// Looking for extremities is like clicking on the left or the
|
|
|
|
// right of the row.
|
|
|
|
int x = tm.origin().x_ + (left ? 0 : textRow().width());
|
|
|
|
bool b = false;
|
|
|
|
pos() = tm.getPosNearX(textRow(), x, b);
|
|
|
|
boundary(b);
|
|
|
|
|
|
|
|
LYXERR(Debug::RTL, "leaving extremity: " << pit() << "," << pos() << ","
|
|
|
|
<< (boundary() ? 1 : 0));
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
bool Cursor::reverseDirectionNeeded() const
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
/*
|
|
|
|
* We determine the directions based on the direction of the
|
|
|
|
* bottom() --- i.e., outermost --- paragraph, because that is
|
|
|
|
* the only way to achieve consistency of the arrow's movements
|
|
|
|
* within a paragraph, and thus avoid situations in which the
|
|
|
|
* cursor gets stuck.
|
|
|
|
*/
|
|
|
|
return bottom().paragraph().isRTL(bv().buffer().params());
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
void Cursor::setTargetX(int x)
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
2007-05-29 20:53:32 +00:00
|
|
|
x_target_ = x;
|
|
|
|
textTargetOffset_ = 0;
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
int Cursor::x_target() const
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
|
|
|
return x_target_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::clearTargetX()
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
|
|
|
x_target_ = -1;
|
2007-05-29 20:53:32 +00:00
|
|
|
textTargetOffset_ = 0;
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
void Cursor::updateTextTargetOffset()
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
getPos(x, y);
|
|
|
|
textTargetOffset_ = x - x_target_;
|
|
|
|
}
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
2020-10-31 17:18:51 +00:00
|
|
|
bool Cursor::selHandle(bool selecting)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
//lyxerr << "Cursor::selHandle" << endl;
|
2007-12-18 07:10:55 +00:00
|
|
|
if (mark())
|
2020-10-31 17:18:51 +00:00
|
|
|
selecting = true;
|
|
|
|
if (selecting == selection())
|
2006-10-22 11:46:36 +00:00
|
|
|
return false;
|
2004-04-20 08:51:15 +00:00
|
|
|
|
2020-10-31 17:18:51 +00:00
|
|
|
if (!selecting)
|
2007-07-10 12:44:19 +00:00
|
|
|
cap::saveSelection(*this);
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
resetAnchor();
|
2020-10-31 17:18:51 +00:00
|
|
|
selection(selecting);
|
2006-10-22 11:46:36 +00:00
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::atFirstOrLastRow(bool up)
|
|
|
|
{
|
|
|
|
TextMetrics const & tm = bv_->textMetrics(text());
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(pit());
|
|
|
|
|
|
|
|
int row;
|
|
|
|
if (pos() && boundary())
|
|
|
|
row = pm.pos2row(pos() - 1);
|
|
|
|
else
|
|
|
|
row = pm.pos2row(pos());
|
|
|
|
|
|
|
|
if (up) {
|
|
|
|
if (pit() == 0 && row == 0)
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (pit() + 1 >= int(text()->paragraphs().size()) &&
|
|
|
|
row + 1 >= int(pm.rows().size()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-11-28 22:12:03 +00:00
|
|
|
// FIXME: Look here
|
2004-01-26 10:13:15 +00:00
|
|
|
// The part below is the non-integrated rest of the original math
|
|
|
|
// cursor. This should be either generalized for texted or moved
|
2006-09-16 18:11:38 +00:00
|
|
|
// back to mathed (in most cases to InsetMathNest).
|
2004-01-26 10:13:15 +00:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "mathed/InsetMathChar.h"
|
|
|
|
#include "mathed/InsetMathUnknown.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "mathed/MathStream.h"
|
|
|
|
#include "mathed/MathSupport.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool Cursor::openable(MathAtom const & t) const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
if (!t->isActive())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (t->lock())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!selection())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// we can't move into anything new during selection
|
2018-01-16 15:00:07 +00:00
|
|
|
if (depth() >= realAnchor().depth())
|
2004-01-26 10:13:15 +00:00
|
|
|
return false;
|
2018-01-16 15:00:07 +00:00
|
|
|
if (t.nucleus() != &realAnchor()[depth()].inset())
|
2004-01-26 10:13:15 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::plainErase()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
cell().erase(pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::plainInsert(MathAtom const & t)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
cell().insert(pos(), t);
|
|
|
|
++pos();
|
2008-03-02 18:49:49 +00:00
|
|
|
inset().setBuffer(bv_->buffer());
|
2008-03-03 17:58:26 +00:00
|
|
|
inset().initView();
|
2015-11-30 22:25:03 +00:00
|
|
|
checkBufferStructure();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::insert(char_type c)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
//lyxerr << "Cursor::insert char '" << c << "'" << endl;
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(!empty(), return);
|
2004-03-18 12:53:43 +00:00
|
|
|
if (inMathed()) {
|
2006-10-21 00:16:43 +00:00
|
|
|
cap::selClearOrDel(*this);
|
2006-09-16 18:11:38 +00:00
|
|
|
insert(new InsetMathChar(c));
|
2004-03-18 12:53:43 +00:00
|
|
|
} else {
|
|
|
|
text()->insertChar(*this, c);
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
void Cursor::insert(docstring const & str)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
for (char_type c : str)
|
|
|
|
insert(c);
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-29 20:55:56 +00:00
|
|
|
void Cursor::insert(Inset * inset0)
|
2004-02-11 14:45:44 +00:00
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(inset0, return);
|
2004-02-11 14:45:44 +00:00
|
|
|
if (inMathed())
|
2010-10-26 16:45:21 +00:00
|
|
|
insert(MathAtom(inset0->asInsetMath()));
|
2008-03-02 18:49:49 +00:00
|
|
|
else {
|
2008-02-29 20:55:56 +00:00
|
|
|
text()->insertInset(*this, inset0);
|
2008-03-02 18:49:49 +00:00
|
|
|
inset0->setBuffer(bv_->buffer());
|
2008-03-03 17:58:26 +00:00
|
|
|
inset0->initView();
|
2010-07-09 14:37:00 +00:00
|
|
|
if (inset0->isLabeled())
|
|
|
|
forceBufferUpdate();
|
2008-03-02 18:49:49 +00:00
|
|
|
}
|
2004-02-11 14:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
void Cursor::insert(MathAtom const & t)
|
|
|
|
{
|
|
|
|
LATTEST(inMathed());
|
|
|
|
//lyxerr << "Cursor::insert MathAtom '" << t << "'" << endl;
|
|
|
|
macroModeClose();
|
|
|
|
cap::selClearOrDel(*this);
|
|
|
|
plainInsert(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::insert(MathData const & ar)
|
|
|
|
{
|
|
|
|
LATTEST(inMathed());
|
|
|
|
macroModeClose();
|
|
|
|
if (selection())
|
|
|
|
cap::eraseSelection(*this);
|
|
|
|
cell().insert(pos(), ar);
|
|
|
|
pos() += ar.size();
|
|
|
|
// FIXME audit setBuffer calls
|
|
|
|
inset().setBuffer(bv_->buffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-27 00:43:25 +00:00
|
|
|
int Cursor::niceInsert(docstring const & t, Parse::flags f, bool enter)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
LATTEST(inMathed());
|
2009-11-15 01:03:03 +00:00
|
|
|
MathData ar(buffer());
|
2008-10-17 21:40:11 +00:00
|
|
|
asArray(t, ar, f);
|
2011-01-28 09:52:12 +00:00
|
|
|
if (ar.size() == 1 && (enter || selection()))
|
2004-01-26 10:13:15 +00:00
|
|
|
niceInsert(ar[0]);
|
2011-01-28 09:52:12 +00:00
|
|
|
else
|
2004-01-26 10:13:15 +00:00
|
|
|
insert(ar);
|
2011-01-28 09:52:12 +00:00
|
|
|
return ar.size();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::niceInsert(MathAtom const & t)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
LATTEST(inMathed());
|
2004-01-26 10:13:15 +00:00
|
|
|
macroModeClose();
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring const safe = cap::grabAndEraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
plainInsert(t);
|
2009-12-11 01:30:33 +00:00
|
|
|
// If possible, enter the new inset and move the contents of the selection
|
|
|
|
if (t->isActive()) {
|
2018-11-06 07:29:22 +00:00
|
|
|
idx_type const idx = prevMath().asNestInset()->firstIdx();
|
2019-03-28 12:18:34 +00:00
|
|
|
MathData ar(buffer());
|
|
|
|
asArray(safe, ar);
|
|
|
|
prevMath().cell(idx).insert(0, ar);
|
2018-11-06 07:29:22 +00:00
|
|
|
editInsertedInset();
|
2010-11-09 00:03:32 +00:00
|
|
|
} else if (t->asMacro() && !safe.empty()) {
|
|
|
|
MathData ar(buffer());
|
|
|
|
asArray(safe, ar);
|
|
|
|
docstring const name = t->asMacro()->name();
|
|
|
|
MacroData const * data = buffer()->getMacro(name);
|
|
|
|
if (data && data->numargs() - data->optionals() > 0) {
|
|
|
|
plainInsert(MathAtom(new InsetMathBrace(ar)));
|
|
|
|
posBackward();
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-18 18:12:55 +00:00
|
|
|
bool Cursor::backspace(bool const force)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
if (selection()) {
|
2007-01-04 15:21:58 +00:00
|
|
|
cap::eraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos() == 0) {
|
2006-11-19 18:33:13 +00:00
|
|
|
// If empty cell, and not part of a big cell
|
|
|
|
if (lastpos() == 0 && inset().nargs() == 1) {
|
2007-11-05 19:41:16 +00:00
|
|
|
popBackward();
|
2007-05-28 22:27:45 +00:00
|
|
|
// Directly delete empty cell: [|[]] => [|]
|
2006-11-19 18:33:13 +00:00
|
|
|
if (inMathed()) {
|
|
|
|
plainErase();
|
|
|
|
resetAnchor();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// [|], can not delete from inside
|
2004-01-26 10:13:15 +00:00
|
|
|
return false;
|
2006-11-19 18:33:13 +00:00
|
|
|
} else {
|
2021-01-30 23:51:15 +00:00
|
|
|
if (inMathed()) {
|
|
|
|
switch (inset().asInsetMath()->getType()) {
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign: {
|
|
|
|
FuncRequest cmd(LFUN_CHAR_BACKWARD);
|
|
|
|
this->dispatch(cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
pullArg();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
2007-11-05 19:41:16 +00:00
|
|
|
popBackward();
|
2006-11-19 18:33:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (inMacroMode()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathUnknown * p = activeMacro();
|
2004-01-26 10:13:15 +00:00
|
|
|
if (p->name().size() > 1) {
|
|
|
|
p->setName(p->name().substr(0, p->name().size() - 1));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-18 18:12:55 +00:00
|
|
|
if (pos() != 0 && !force && prevAtom()->confirmDeletion()) {
|
2004-01-26 10:13:15 +00:00
|
|
|
// let's require two backspaces for 'big stuff' and
|
|
|
|
// highlight on the first
|
2004-04-05 16:44:10 +00:00
|
|
|
resetAnchor();
|
2016-02-28 16:36:29 +00:00
|
|
|
selection(true);
|
2004-02-25 14:39:14 +00:00
|
|
|
--pos();
|
2004-01-26 10:13:15 +00:00
|
|
|
} else {
|
|
|
|
--pos();
|
|
|
|
plainErase();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-18 18:12:55 +00:00
|
|
|
bool Cursor::erase(bool const force)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
if (inMacroMode())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (selection()) {
|
2007-01-04 15:21:58 +00:00
|
|
|
cap::eraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete empty cells if possible
|
2004-03-18 12:53:43 +00:00
|
|
|
if (pos() == lastpos() && inset().idxDelete(idx()))
|
2004-02-03 08:56:28 +00:00
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
// special behaviour when in last position of cell
|
|
|
|
if (pos() == lastpos()) {
|
2004-03-18 12:53:43 +00:00
|
|
|
bool one_cell = inset().nargs() == 1;
|
2006-11-19 18:33:13 +00:00
|
|
|
if (one_cell && lastpos() == 0) {
|
2007-11-05 19:41:16 +00:00
|
|
|
popBackward();
|
2007-05-28 22:27:45 +00:00
|
|
|
// Directly delete empty cell: [|[]] => [|]
|
2006-11-19 18:33:13 +00:00
|
|
|
if (inMathed()) {
|
|
|
|
plainErase();
|
|
|
|
resetAnchor();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// [|], can not delete from inside
|
2004-01-26 10:13:15 +00:00
|
|
|
return false;
|
2006-11-19 18:33:13 +00:00
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
// remove markup
|
2006-11-19 18:33:13 +00:00
|
|
|
if (!one_cell)
|
2004-03-18 12:53:43 +00:00
|
|
|
inset().idxGlue(idx());
|
2004-01-26 10:13:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-04-05 16:44:10 +00:00
|
|
|
// 'clever' UI hack: only erase large items if previously slected
|
2017-02-18 18:12:55 +00:00
|
|
|
if (pos() != lastpos() && !force && nextAtom()->confirmDeletion()) {
|
2004-04-05 16:44:10 +00:00
|
|
|
resetAnchor();
|
2016-02-28 16:36:29 +00:00
|
|
|
selection(true);
|
2004-02-25 14:39:14 +00:00
|
|
|
++pos();
|
2004-01-26 10:13:15 +00:00
|
|
|
} else {
|
|
|
|
plainErase();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool Cursor::up()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
macroModeClose();
|
2004-03-31 19:11:56 +00:00
|
|
|
DocIterator save = *this;
|
2007-05-29 20:53:32 +00:00
|
|
|
FuncRequest cmd(selection() ? LFUN_UP_SELECT : LFUN_UP, docstring());
|
|
|
|
this->dispatch(cmd);
|
|
|
|
if (disp_.dispatched())
|
2004-01-26 10:13:15 +00:00
|
|
|
return true;
|
2004-08-14 19:55:00 +00:00
|
|
|
setCursor(save);
|
2007-05-29 20:53:32 +00:00
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool Cursor::down()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
macroModeClose();
|
2004-03-31 19:11:56 +00:00
|
|
|
DocIterator save = *this;
|
2007-05-29 20:53:32 +00:00
|
|
|
FuncRequest cmd(selection() ? LFUN_DOWN_SELECT : LFUN_DOWN, docstring());
|
|
|
|
this->dispatch(cmd);
|
|
|
|
if (disp_.dispatched())
|
2004-01-26 10:13:15 +00:00
|
|
|
return true;
|
2004-08-14 19:55:00 +00:00
|
|
|
setCursor(save);
|
2007-05-29 20:53:32 +00:00
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-06 07:29:22 +00:00
|
|
|
void Cursor::handleNest(MathAtom const & a)
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
{
|
2018-11-06 07:29:22 +00:00
|
|
|
idx_type const idx = a.nucleus()->asNestInset()->firstIdx();
|
|
|
|
//lyxerr << "Cursor::handleNest: " << idx << endl;
|
2021-02-28 21:32:11 +00:00
|
|
|
InsetMath const * im = selectionBegin().inset().asInsetMath();
|
|
|
|
Parse::flags const f = im && im->currentMode() != InsetMath::MATH_MODE
|
|
|
|
? Parse::TEXTMODE : Parse::NORMAL;
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
MathAtom t = a;
|
2021-02-28 21:32:11 +00:00
|
|
|
asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(idx), f);
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
insert(t);
|
2018-11-06 07:29:22 +00:00
|
|
|
editInsertedInset();
|
2018-04-04 16:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
int Cursor::targetX() const
|
|
|
|
{
|
|
|
|
if (x_target() != -1)
|
|
|
|
return x_target();
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
getPos(x, y);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Cursor::textTargetOffset() const
|
|
|
|
{
|
|
|
|
return textTargetOffset_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::setTargetX()
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
getPos(x, y);
|
|
|
|
setTargetX(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-20 11:09:10 +00:00
|
|
|
bool Cursor::macroModeClose(bool cancel)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
if (!inMacroMode())
|
2006-01-11 17:08:50 +00:00
|
|
|
return false;
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathUnknown * p = activeMacro();
|
2004-01-26 10:13:15 +00:00
|
|
|
p->finalize();
|
2009-11-15 01:03:03 +00:00
|
|
|
MathData selection(buffer());
|
2009-10-29 13:24:02 +00:00
|
|
|
asArray(p->selection(), selection);
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring const s = p->name();
|
2004-01-26 10:13:15 +00:00
|
|
|
--pos();
|
|
|
|
cell().erase(pos());
|
|
|
|
|
2007-04-19 13:37:17 +00:00
|
|
|
// trigger updates of macros, at least, if no full
|
|
|
|
// updates take place anyway
|
2010-07-08 20:04:35 +00:00
|
|
|
screenUpdateFlags(Update::Force);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
2018-04-24 12:03:35 +00:00
|
|
|
// do nothing if the macro name is empty
|
|
|
|
if (s == "\\" || cancel) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-04-19 13:37:17 +00:00
|
|
|
docstring const name = s.substr(1);
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathNest * const in = inset().asInsetMath()->asNestInset();
|
2006-10-19 16:38:13 +00:00
|
|
|
if (in && in->interpretString(*this, s))
|
2006-05-01 08:05:22 +00:00
|
|
|
return true;
|
2016-09-16 00:15:52 +00:00
|
|
|
bool const user_macro = buffer()->getMacro(name, *this, false);
|
2017-07-05 12:31:28 +00:00
|
|
|
MathAtom atom = user_macro ? MathAtom(new InsetMathMacro(buffer(), name))
|
2016-09-16 00:15:52 +00:00
|
|
|
: createInsetMath(name, buffer());
|
2008-03-04 14:49:24 +00:00
|
|
|
|
|
|
|
// try to put argument into macro, if we just inserted a macro
|
|
|
|
bool macroArg = false;
|
2017-07-05 12:31:28 +00:00
|
|
|
InsetMathMacro * atomAsMacro = atom.nucleus()->asMacro();
|
2018-04-04 16:24:14 +00:00
|
|
|
InsetMathNest * atomAsNest = atom.nucleus()->asNestInset();
|
2007-11-01 14:45:14 +00:00
|
|
|
if (atomAsMacro) {
|
2008-03-04 14:49:24 +00:00
|
|
|
// macros here are still unfolded (in init mode in fact). So
|
|
|
|
// we have to resolve the macro here manually and check its arity
|
|
|
|
// to put the selection behind it if arity > 0.
|
2008-11-17 11:46:07 +00:00
|
|
|
MacroData const * data = buffer()->getMacro(atomAsMacro->name());
|
2019-05-19 14:34:57 +00:00
|
|
|
if (!selection.empty() && data && data->numargs()) {
|
2008-03-04 14:49:24 +00:00
|
|
|
macroArg = true;
|
2017-07-05 12:31:28 +00:00
|
|
|
atomAsMacro->setDisplayMode(InsetMathMacro::DISPLAY_INTERACTIVE_INIT, 1);
|
2008-03-04 14:49:24 +00:00
|
|
|
} else
|
|
|
|
// non-greedy case. Do not touch the arguments behind
|
2017-07-05 12:31:28 +00:00
|
|
|
atomAsMacro->setDisplayMode(InsetMathMacro::DISPLAY_INTERACTIVE_INIT, 0);
|
2007-11-01 14:40:15 +00:00
|
|
|
}
|
2008-03-04 14:49:24 +00:00
|
|
|
|
|
|
|
// insert remembered selection into first argument of a non-macro
|
2018-04-04 16:24:14 +00:00
|
|
|
else if (atomAsNest && atomAsNest->nargs() > 0)
|
|
|
|
atomAsNest->cell(atomAsNest->firstIdx()).append(selection);
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2016-09-15 22:37:04 +00:00
|
|
|
MathWordList const & words = mathedWordList();
|
|
|
|
MathWordList::const_iterator it = words.find(name);
|
2017-10-22 21:09:37 +00:00
|
|
|
bool keep_mathmode = user_macro
|
|
|
|
|| (it != words.end() && (it->second.inset == "font"
|
|
|
|
|| it->second.inset == "oldfont"
|
|
|
|
|| it->second.inset == "mbox"));
|
2016-09-25 16:59:07 +00:00
|
|
|
bool ert_macro = !user_macro && it == words.end() && atomAsMacro;
|
2016-09-12 05:55:38 +00:00
|
|
|
|
2016-09-12 03:15:00 +00:00
|
|
|
if (in && in->currentMode() == Inset::TEXT_MODE
|
2016-09-10 00:39:57 +00:00
|
|
|
&& atom.nucleus()->currentMode() == Inset::MATH_MODE
|
2016-09-12 05:55:38 +00:00
|
|
|
&& name != from_ascii("ensuremath") && !ert_macro) {
|
2016-09-10 00:07:47 +00:00
|
|
|
MathAtom at(new InsetMathEnsureMath(buffer()));
|
|
|
|
at.nucleus()->cell(0).push_back(atom);
|
|
|
|
niceInsert(at);
|
|
|
|
posForward();
|
2016-09-12 03:15:00 +00:00
|
|
|
} else if (in && in->currentMode() == Inset::MATH_MODE
|
2016-09-10 00:39:57 +00:00
|
|
|
&& atom.nucleus()->currentMode() == Inset::TEXT_MODE
|
2016-09-15 22:37:04 +00:00
|
|
|
&& !keep_mathmode) {
|
2016-09-10 00:07:47 +00:00
|
|
|
MathAtom at = createInsetMath("text", buffer());
|
|
|
|
at.nucleus()->cell(0).push_back(atom);
|
|
|
|
niceInsert(at);
|
|
|
|
posForward();
|
|
|
|
} else
|
|
|
|
plainInsert(atom);
|
2008-03-04 14:49:24 +00:00
|
|
|
|
|
|
|
// finally put the macro argument behind, if needed
|
|
|
|
if (macroArg) {
|
2009-10-29 13:24:02 +00:00
|
|
|
if (selection.size() > 1 || selection[0]->asScriptInset())
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
plainInsert(MathAtom(new InsetMathBrace(selection)));
|
|
|
|
else
|
|
|
|
insert(selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2004-11-30 01:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool Cursor::inMacroMode() const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-05-29 20:53:32 +00:00
|
|
|
if (!inMathed())
|
|
|
|
return false;
|
2011-01-10 10:23:10 +00:00
|
|
|
if (pos() == 0 || cell().empty())
|
2004-01-26 10:13:15 +00:00
|
|
|
return false;
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathUnknown const * p = prevAtom()->asUnknownInset();
|
2004-01-26 10:13:15 +00:00
|
|
|
return p && !p->final();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
InsetMathUnknown * Cursor::activeMacro()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2020-02-28 06:55:05 +00:00
|
|
|
return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : nullptr;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
InsetMathUnknown const * Cursor::activeMacro() const
|
|
|
|
{
|
2020-02-28 06:55:05 +00:00
|
|
|
return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : nullptr;
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
docstring Cursor::macroName()
|
|
|
|
{
|
|
|
|
return inMacroMode() ? activeMacro()->name() : docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::pullArg()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-08-10 11:47:12 +00:00
|
|
|
// FIXME: Look here
|
2007-04-26 16:06:39 +00:00
|
|
|
MathData ar = cell();
|
2007-11-05 19:41:16 +00:00
|
|
|
if (popBackward() && inMathed()) {
|
2004-01-26 10:13:15 +00:00
|
|
|
plainErase();
|
|
|
|
cell().insert(pos(), ar);
|
|
|
|
resetAnchor();
|
|
|
|
} else {
|
2004-02-11 14:45:44 +00:00
|
|
|
//formula()->mutateToText();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::normalize()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2005-07-18 17:12:28 +00:00
|
|
|
if (idx() > lastidx()) {
|
2004-01-26 10:13:15 +00:00
|
|
|
lyxerr << "this should not really happen - 1: "
|
|
|
|
<< idx() << ' ' << nargs()
|
2004-03-18 12:53:43 +00:00
|
|
|
<< " in: " << &inset() << endl;
|
2005-07-18 17:12:28 +00:00
|
|
|
idx() = lastidx();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pos() > lastpos()) {
|
|
|
|
lyxerr << "this should not really happen - 2: "
|
|
|
|
<< pos() << ' ' << lastpos() << " in idx: " << idx()
|
|
|
|
<< " in atom: '";
|
2006-10-21 00:16:43 +00:00
|
|
|
odocstringstream os;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexrowstream ots(os);
|
2020-12-26 19:04:36 +00:00
|
|
|
TeXMathStream wi(ots, false, true, TeXMathStream::wsDefault);
|
2006-09-16 18:11:38 +00:00
|
|
|
inset().asInsetMath()->write(wi);
|
2006-10-21 00:16:43 +00:00
|
|
|
lyxerr << to_utf8(os.str()) << endl;
|
2005-07-18 17:12:28 +00:00
|
|
|
pos() = lastpos();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
bool Cursor::upDownInMath(bool up)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2004-02-16 11:58:51 +00:00
|
|
|
// Be warned: The 'logic' implemented in this function is highly
|
|
|
|
// fragile. A distance of one pixel or a '<' vs '<=' _really
|
|
|
|
// matters. So fiddle around with it only if you think you know
|
|
|
|
// what you are doing!
|
2004-08-13 19:19:53 +00:00
|
|
|
int xo = 0;
|
2004-01-26 10:13:15 +00:00
|
|
|
int yo = 0;
|
2004-01-30 11:41:12 +00:00
|
|
|
getPos(xo, yo);
|
2010-02-09 14:29:27 +00:00
|
|
|
xo = beforeDispatchPosX_;
|
2010-02-09 16:11:13 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
// check if we had something else in mind, if not, this is the future
|
|
|
|
// target
|
2007-05-29 20:53:32 +00:00
|
|
|
if (x_target_ == -1)
|
|
|
|
setTargetX(xo);
|
2007-11-03 18:07:41 +00:00
|
|
|
else if (inset().asInsetText() && xo - textTargetOffset() != x_target()) {
|
2007-05-29 20:53:32 +00:00
|
|
|
// In text mode inside the line (not left or right) possibly set a new target_x,
|
|
|
|
// but only if we are somewhere else than the previous target-offset.
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// We want to keep the x-target on subsequent up/down movements
|
|
|
|
// that cross beyond the end of short lines. Thus a special
|
2007-08-11 10:32:36 +00:00
|
|
|
// handling when the cursor is at the end of line: Use the new
|
2007-05-29 20:53:32 +00:00
|
|
|
// x-target only if the old one was before the end of line
|
|
|
|
// or the old one was after the beginning of the line
|
2015-07-16 09:55:45 +00:00
|
|
|
bool inRTL = innerParagraph().isRTL(bv().buffer().params());
|
2007-05-29 20:53:32 +00:00
|
|
|
bool left;
|
|
|
|
bool right;
|
|
|
|
if (inRTL) {
|
|
|
|
left = pos() == textRow().endpos();
|
|
|
|
right = pos() == textRow().pos();
|
|
|
|
} else {
|
|
|
|
left = pos() == textRow().pos();
|
|
|
|
right = pos() == textRow().endpos();
|
|
|
|
}
|
|
|
|
if ((!left && !right) ||
|
2007-08-11 10:32:36 +00:00
|
|
|
(left && !right && xo < x_target_) ||
|
2007-05-29 20:53:32 +00:00
|
|
|
(!left && right && x_target_ < xo))
|
|
|
|
setTargetX(xo);
|
|
|
|
else
|
|
|
|
xo = targetX();
|
2007-08-11 10:32:36 +00:00
|
|
|
} else
|
2007-05-29 20:53:32 +00:00
|
|
|
xo = targetX();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
// try neigbouring script insets
|
2007-05-29 20:53:32 +00:00
|
|
|
Cursor old = *this;
|
|
|
|
if (inMathed() && !selection()) {
|
2004-01-26 10:13:15 +00:00
|
|
|
// try left
|
|
|
|
if (pos() != 0) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathScript const * p = prevAtom()->asScriptInset();
|
2004-01-26 10:13:15 +00:00
|
|
|
if (p && p->has(up)) {
|
|
|
|
--pos();
|
2006-09-16 18:11:38 +00:00
|
|
|
push(*const_cast<InsetMathScript*>(p));
|
2005-07-17 12:28:02 +00:00
|
|
|
idx() = p->idxOfScript(up);
|
2004-01-26 10:13:15 +00:00
|
|
|
pos() = lastpos();
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// we went in the right direction? Otherwise don't jump into the script
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
getPos(x, y);
|
2010-02-09 14:29:27 +00:00
|
|
|
int oy = beforeDispatchPosY_;
|
2007-12-17 18:13:02 +00:00
|
|
|
if ((!up && y <= oy) ||
|
|
|
|
(up && y >= oy))
|
2007-05-29 20:53:32 +00:00
|
|
|
operator=(old);
|
|
|
|
else
|
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
// try right
|
|
|
|
if (pos() != lastpos()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathScript const * p = nextAtom()->asScriptInset();
|
2004-01-26 10:13:15 +00:00
|
|
|
if (p && p->has(up)) {
|
2006-09-16 18:11:38 +00:00
|
|
|
push(*const_cast<InsetMathScript*>(p));
|
2005-07-17 12:28:02 +00:00
|
|
|
idx() = p->idxOfScript(up);
|
2004-01-26 10:13:15 +00:00
|
|
|
pos() = 0;
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// we went in the right direction? Otherwise don't jump into the script
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
getPos(x, y);
|
2010-02-09 14:29:27 +00:00
|
|
|
int oy = beforeDispatchPosY_;
|
2007-12-17 18:13:02 +00:00
|
|
|
if ((!up && y <= oy) ||
|
|
|
|
(up && y >= oy))
|
2007-05-29 20:53:32 +00:00
|
|
|
operator=(old);
|
|
|
|
else
|
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// try to find an inset that knows better then we,
|
|
|
|
if (inset().idxUpDown(*this, up)) {
|
|
|
|
//lyxerr << "idxUpDown triggered" << endl;
|
|
|
|
// try to find best position within this inset
|
|
|
|
if (!selection())
|
2016-02-28 15:48:11 +00:00
|
|
|
setCursor(bruteFind(*this, xo, yo));
|
2007-05-29 20:53:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// any improvement going just out of inset?
|
2007-11-05 19:41:16 +00:00
|
|
|
if (popBackward() && inMathed()) {
|
|
|
|
//lyxerr << "updown: popBackward succeeded" << endl;
|
2005-02-08 13:18:05 +00:00
|
|
|
int xnew;
|
|
|
|
int ynew;
|
2010-02-09 14:29:27 +00:00
|
|
|
int yold = beforeDispatchPosY_;
|
2004-01-30 11:41:12 +00:00
|
|
|
getPos(xnew, ynew);
|
2007-12-17 18:13:02 +00:00
|
|
|
if (up ? ynew < yold : ynew > yold)
|
2004-01-26 10:13:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// no success, we are probably at the document top or bottom
|
|
|
|
operator=(old);
|
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-27 20:00:54 +00:00
|
|
|
bool Cursor::mathForward(bool word)
|
|
|
|
{
|
|
|
|
LASSERT(inMathed(), return false);
|
|
|
|
if (pos() < lastpos()) {
|
|
|
|
if (word) {
|
2017-05-09 21:28:32 +00:00
|
|
|
// word: skip a group of insets of the form X*(B*|R*|P*) (greedy
|
|
|
|
// match) where X is any math class, B is mathbin, R is mathrel, and
|
|
|
|
// P is mathpunct. Make sure that the following remains true:
|
|
|
|
// mathForward(true); mathBackward(true); mathForward(true)
|
|
|
|
// is the same as mathForward(true) and
|
|
|
|
// mathBackward(true); mathForward(true); mathBackward(true)
|
|
|
|
// is the same as mathBackward(true).
|
2016-05-27 20:00:54 +00:00
|
|
|
MathClass mc = nextMath().mathClass();
|
|
|
|
do
|
|
|
|
posForward();
|
|
|
|
while (pos() < lastpos() && mc == nextMath().mathClass());
|
2017-05-09 21:28:32 +00:00
|
|
|
if (pos() < lastpos() &&
|
|
|
|
((mc = nextMath().mathClass()) == MC_BIN ||
|
|
|
|
mc == MC_REL || mc == MC_PUNCT))
|
|
|
|
do
|
|
|
|
posForward();
|
|
|
|
while (pos() < lastpos() && mc == nextMath().mathClass());
|
2016-05-27 20:00:54 +00:00
|
|
|
} else if (openable(nextAtom())) {
|
2021-02-26 19:30:41 +00:00
|
|
|
InsetMathScript const * n = nextMath().asScriptInset();
|
2021-03-01 09:08:08 +00:00
|
|
|
bool to_brace_deco = n && !n->nuc().empty()
|
2021-02-26 19:30:41 +00:00
|
|
|
&& n->nuc().back()->lyxCode() == MATH_DECORATION_CODE
|
|
|
|
&& n->nuc().back()->mathClass() == MC_OP;
|
2016-05-27 20:00:54 +00:00
|
|
|
// single step: try to enter the next inset
|
|
|
|
pushBackward(nextMath());
|
|
|
|
inset().idxFirst(*this);
|
2021-02-26 19:30:41 +00:00
|
|
|
// Make sure the cursor moves directly to an
|
|
|
|
// \overbrace or \underbrace inset (bug 2264)
|
|
|
|
if (to_brace_deco) {
|
|
|
|
pushBackward(nextMath());
|
|
|
|
inset().idxFirst(*this);
|
|
|
|
}
|
2016-05-27 20:00:54 +00:00
|
|
|
} else
|
|
|
|
posForward();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (inset().idxForward(*this))
|
|
|
|
return true;
|
2021-02-26 19:30:41 +00:00
|
|
|
InsetMath const * m = inset().asInsetMath();
|
|
|
|
bool from_brace_deco = m
|
|
|
|
&& m->lyxCode() == MATH_DECORATION_CODE
|
|
|
|
&& m->mathClass() == MC_OP;
|
2016-05-27 20:00:54 +00:00
|
|
|
// try to pop forwards --- but don't pop out of math! leave that to
|
|
|
|
// the FINISH lfuns
|
|
|
|
int s = depth() - 2;
|
2021-02-26 19:30:41 +00:00
|
|
|
if (s >= 0 && operator[](s).inset().asInsetMath() && popForward()) {
|
|
|
|
// Make sure the cursor moves directly to an
|
|
|
|
// \overbrace or \underbrace inset (bug 2264)
|
|
|
|
bool to_script = inset().asInsetMath()
|
|
|
|
&& inset().asInsetMath()->asScriptInset();
|
|
|
|
return from_brace_deco && to_script ? mathForward(word) : true;
|
|
|
|
}
|
2016-05-27 20:00:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::mathBackward(bool word)
|
|
|
|
{
|
|
|
|
LASSERT(inMathed(), return false);
|
|
|
|
if (pos() > 0) {
|
|
|
|
if (word) {
|
2017-05-09 21:28:32 +00:00
|
|
|
// word: skip a group of insets. See the comment in mathForward.
|
2016-05-27 20:00:54 +00:00
|
|
|
MathClass mc = prevMath().mathClass();
|
|
|
|
do
|
|
|
|
posBackward();
|
|
|
|
while (pos() > 0 && mc == prevMath().mathClass());
|
2017-05-09 21:28:32 +00:00
|
|
|
if (pos() > 0 && (mc == MC_BIN || mc == MC_REL || mc == MC_PUNCT)) {
|
|
|
|
mc = prevMath().mathClass();
|
|
|
|
do
|
|
|
|
posBackward();
|
|
|
|
while (pos() > 0 && mc == prevMath().mathClass());
|
|
|
|
}
|
2016-05-27 20:00:54 +00:00
|
|
|
} else if (openable(prevAtom())) {
|
2021-02-26 19:30:41 +00:00
|
|
|
InsetMathScript const * p = prevMath().asScriptInset();
|
2021-03-01 09:08:08 +00:00
|
|
|
bool to_brace_deco = p && !p->nuc().empty()
|
2021-02-26 19:30:41 +00:00
|
|
|
&& p->nuc().back()->lyxCode() == MATH_DECORATION_CODE
|
|
|
|
&& p->nuc().back()->mathClass() == MC_OP;
|
2016-05-27 20:00:54 +00:00
|
|
|
// single step: try to enter the preceding inset
|
|
|
|
posBackward();
|
|
|
|
push(nextMath());
|
|
|
|
inset().idxLast(*this);
|
2021-02-26 19:30:41 +00:00
|
|
|
// Make sure the cursor moves directly to an
|
|
|
|
// \overbrace or \underbrace inset (bug 2264)
|
|
|
|
if (to_brace_deco) {
|
|
|
|
posBackward();
|
|
|
|
push(nextMath());
|
|
|
|
inset().idxLast(*this);
|
|
|
|
}
|
2016-05-27 20:00:54 +00:00
|
|
|
} else
|
|
|
|
posBackward();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (inset().idxBackward(*this))
|
|
|
|
return true;
|
2021-02-26 19:30:41 +00:00
|
|
|
InsetMath const * m = inset().asInsetMath();
|
|
|
|
bool from_brace_deco = m
|
|
|
|
&& m->lyxCode() == MATH_DECORATION_CODE
|
|
|
|
&& m->mathClass() == MC_OP;
|
2016-05-27 20:00:54 +00:00
|
|
|
// try to pop backwards --- but don't pop out of math! leave that to
|
|
|
|
// the FINISH lfuns
|
|
|
|
int s = depth() - 2;
|
2021-02-26 19:30:41 +00:00
|
|
|
if (s >= 0 && operator[](s).inset().asInsetMath() && popBackward()) {
|
|
|
|
// Make sure the cursor moves directly to an
|
|
|
|
// \overbrace or \underbrace inset (bug 2264)
|
|
|
|
bool to_script = inset().asInsetMath()
|
|
|
|
&& inset().asInsetMath()->asScriptInset();
|
|
|
|
return from_brace_deco && to_script ? mathBackward(word) : true;
|
|
|
|
}
|
2016-05-27 20:00:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-11 10:32:36 +00:00
|
|
|
bool Cursor::upDownInText(bool up, bool & updateNeeded)
|
2007-05-29 20:53:32 +00:00
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(text(), return false);
|
2007-05-29 20:53:32 +00:00
|
|
|
|
|
|
|
// where are we?
|
|
|
|
int xo = 0;
|
|
|
|
int yo = 0;
|
|
|
|
getPos(xo, yo);
|
2010-02-09 14:29:27 +00:00
|
|
|
xo = beforeDispatchPosX_;
|
2007-12-17 18:13:02 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// update the targetX - this is here before the "return false"
|
|
|
|
// to set a new target which can be used by InsetTexts above
|
|
|
|
// if we cannot move up/down inside this inset anymore
|
|
|
|
if (x_target_ == -1)
|
|
|
|
setTargetX(xo);
|
2007-08-11 10:32:36 +00:00
|
|
|
else if (xo - textTargetOffset() != x_target() &&
|
2007-06-14 20:32:28 +00:00
|
|
|
depth() == beforeDispatchCursor_.depth()) {
|
2012-10-27 13:45:27 +00:00
|
|
|
// In text mode inside the line (not left or right)
|
|
|
|
// possibly set a new target_x, but only if we are
|
|
|
|
// somewhere else than the previous target-offset.
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
// We want to keep the x-target on subsequent up/down
|
|
|
|
// movements that cross beyond the end of short lines.
|
|
|
|
// Thus a special handling when the cursor is at the
|
|
|
|
// end of line: Use the new x-target only if the old
|
|
|
|
// one was before the end of line or the old one was
|
|
|
|
// after the beginning of the line
|
2015-07-16 09:55:45 +00:00
|
|
|
bool inRTL = innerParagraph().isRTL(bv().buffer().params());
|
2007-05-29 20:53:32 +00:00
|
|
|
bool left;
|
|
|
|
bool right;
|
|
|
|
if (inRTL) {
|
|
|
|
left = pos() == textRow().endpos();
|
|
|
|
right = pos() == textRow().pos();
|
|
|
|
} else {
|
|
|
|
left = pos() == textRow().pos();
|
|
|
|
right = pos() == textRow().endpos();
|
|
|
|
}
|
|
|
|
if ((!left && !right) ||
|
2007-08-11 10:32:36 +00:00
|
|
|
(left && !right && xo < x_target_) ||
|
2007-05-29 20:53:32 +00:00
|
|
|
(!left && right && x_target_ < xo))
|
|
|
|
setTargetX(xo);
|
|
|
|
else
|
|
|
|
xo = targetX();
|
2007-08-11 10:32:36 +00:00
|
|
|
} else
|
2007-05-29 20:53:32 +00:00
|
|
|
xo = targetX();
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// first get the current line
|
2007-09-02 09:44:08 +00:00
|
|
|
TextMetrics & tm = bv_->textMetrics(text());
|
2007-05-29 20:53:32 +00:00
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(pit());
|
|
|
|
int row;
|
|
|
|
if (pos() && boundary())
|
|
|
|
row = pm.pos2row(pos() - 1);
|
|
|
|
else
|
|
|
|
row = pm.pos2row(pos());
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2009-03-25 21:21:00 +00:00
|
|
|
if (atFirstOrLastRow(up)) {
|
2009-04-15 20:20:42 +00:00
|
|
|
// Is there a place for the cursor to go ? If yes, we
|
|
|
|
// can execute the DEPM, otherwise we should keep the
|
|
|
|
// paragraph to host the cursor.
|
2009-03-25 21:21:00 +00:00
|
|
|
Cursor dummy = *this;
|
2009-04-15 20:20:42 +00:00
|
|
|
bool valid_destination = false;
|
|
|
|
for(; dummy.depth(); dummy.pop())
|
|
|
|
if (!dummy.atFirstOrLastRow(up)) {
|
|
|
|
valid_destination = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-14 13:22:26 +00:00
|
|
|
// will a next dispatch follow and if there is a new
|
2009-04-15 20:20:42 +00:00
|
|
|
// dispatch will it move the cursor out ?
|
|
|
|
if (depth() > 1 && valid_destination) {
|
|
|
|
// The cursor hasn't changed yet. This happens when
|
2014-03-14 13:22:26 +00:00
|
|
|
// you e.g. move out of an inset. And to give the
|
2009-04-15 20:20:42 +00:00
|
|
|
// DEPM the possibility of doing something we must
|
|
|
|
// provide it with two different cursors. (Lgb, vfr)
|
|
|
|
dummy = *this;
|
|
|
|
dummy.pos() = dummy.pos() == 0 ? dummy.lastpos() : 0;
|
|
|
|
dummy.pit() = dummy.pit() == 0 ? dummy.lastpit() : 0;
|
|
|
|
|
|
|
|
updateNeeded |= bv().checkDepm(dummy, *this);
|
|
|
|
updateTextTargetOffset();
|
2013-05-19 12:42:27 +00:00
|
|
|
if (updateNeeded)
|
2010-07-09 14:37:00 +00:00
|
|
|
forceBufferUpdate();
|
2009-04-15 20:20:42 +00:00
|
|
|
}
|
2021-06-29 10:43:59 +00:00
|
|
|
return valid_destination;
|
2009-03-25 21:21:00 +00:00
|
|
|
}
|
2007-06-14 20:32:28 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// with and without selection are handled differently
|
|
|
|
if (!selection()) {
|
2018-02-24 04:42:32 +00:00
|
|
|
int yo1 = bv().getPos(*this).y_;
|
2007-05-29 20:53:32 +00:00
|
|
|
Cursor old = *this;
|
|
|
|
// To next/previous row
|
2017-03-19 13:41:54 +00:00
|
|
|
// FIXME: the y position is often guessed wrongly across styles and
|
|
|
|
// insets, which leads to weird behaviour.
|
2007-05-29 20:53:32 +00:00
|
|
|
if (up)
|
2018-02-24 04:42:32 +00:00
|
|
|
tm.editXY(*this, xo, yo1 - textRow().ascent() - 1);
|
2007-05-29 20:53:32 +00:00
|
|
|
else
|
2018-02-24 04:42:32 +00:00
|
|
|
tm.editXY(*this, xo, yo1 + textRow().descent() + 1);
|
2017-03-19 13:41:54 +00:00
|
|
|
x_target_ = old.x_target_;
|
2007-05-29 20:53:32 +00:00
|
|
|
clearSelection();
|
2014-03-14 13:22:26 +00:00
|
|
|
|
|
|
|
// This happens when you move out of an inset.
|
|
|
|
// And to give the DEPM the possibility of doing
|
|
|
|
// something we must provide it with two different
|
|
|
|
// cursors. (Lgb)
|
2009-04-15 20:20:42 +00:00
|
|
|
Cursor dummy = *this;
|
|
|
|
if (dummy == old)
|
|
|
|
++dummy.pos();
|
|
|
|
if (bv().checkDepm(dummy, old)) {
|
|
|
|
updateNeeded = true;
|
2014-03-14 13:22:26 +00:00
|
|
|
// Make sure that cur gets back whatever happened to dummy (Lgb)
|
2009-04-15 20:20:42 +00:00
|
|
|
operator=(dummy);
|
|
|
|
}
|
2016-01-28 13:13:17 +00:00
|
|
|
if (inTexted() && pos() && paragraph().isEnvSeparator(pos() - 1))
|
2016-01-09 23:08:10 +00:00
|
|
|
posBackward();
|
2007-05-29 20:53:32 +00:00
|
|
|
} else {
|
2009-11-05 12:58:25 +00:00
|
|
|
// if there is a selection, we stay out of any inset,
|
|
|
|
// and just jump to the right position:
|
2007-05-29 20:53:32 +00:00
|
|
|
Cursor old = *this;
|
2009-11-05 12:58:25 +00:00
|
|
|
int next_row = row;
|
2007-05-29 20:53:32 +00:00
|
|
|
if (up) {
|
|
|
|
if (row > 0) {
|
2009-11-05 12:58:25 +00:00
|
|
|
--next_row;
|
2007-05-29 20:53:32 +00:00
|
|
|
} else if (pit() > 0) {
|
|
|
|
--pit();
|
2018-02-24 04:42:32 +00:00
|
|
|
TextMetrics & tm2 = bv_->textMetrics(text());
|
|
|
|
if (!tm2.contains(pit()))
|
|
|
|
tm2.newParMetricsUp();
|
|
|
|
ParagraphMetrics const & pmcur = tm2.parMetrics(pit());
|
2009-11-05 12:58:25 +00:00
|
|
|
next_row = pmcur.rows().size() - 1;
|
2007-05-29 20:53:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (row + 1 < int(pm.rows().size())) {
|
2009-11-05 12:58:25 +00:00
|
|
|
++next_row;
|
2007-05-29 20:53:32 +00:00
|
|
|
} else if (pit() + 1 < int(text()->paragraphs().size())) {
|
|
|
|
++pit();
|
2018-02-24 04:42:32 +00:00
|
|
|
TextMetrics & tm2 = bv_->textMetrics(text());
|
|
|
|
if (!tm2.contains(pit()))
|
|
|
|
tm2.newParMetricsDown();
|
2009-11-05 12:58:25 +00:00
|
|
|
next_row = 0;
|
2007-05-29 20:53:32 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-14 20:32:28 +00:00
|
|
|
|
2014-03-17 10:15:42 +00:00
|
|
|
Row const & real_next_row = tm.parMetrics(pit()).rows()[next_row];
|
|
|
|
bool bound = false;
|
2014-05-02 13:55:10 +00:00
|
|
|
top().pos() = tm.getPosNearX(real_next_row, xo, bound);
|
2014-03-17 10:15:42 +00:00
|
|
|
boundary(bound);
|
2017-10-11 09:56:09 +00:00
|
|
|
// When selection==false, this is done by TextMetrics::editXY
|
|
|
|
setCurrentFont();
|
2009-11-15 22:01:12 +00:00
|
|
|
|
2007-05-30 19:38:22 +00:00
|
|
|
updateNeeded |= bv().checkDepm(*this, old);
|
2007-05-29 20:53:32 +00:00
|
|
|
}
|
2007-06-14 20:32:28 +00:00
|
|
|
|
2010-07-09 14:37:00 +00:00
|
|
|
if (updateNeeded)
|
|
|
|
forceBufferUpdate();
|
2007-05-29 20:53:32 +00:00
|
|
|
updateTextTargetOffset();
|
|
|
|
return true;
|
2014-03-14 13:22:26 +00:00
|
|
|
}
|
2007-05-29 20:53:32 +00:00
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::handleFont(string const & font)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR(Debug::DEBUG, font);
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring safe;
|
2004-01-26 10:13:15 +00:00
|
|
|
if (selection()) {
|
|
|
|
macroModeClose();
|
2006-10-21 00:16:43 +00:00
|
|
|
safe = cap::grabAndEraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
2008-09-14 17:51:46 +00:00
|
|
|
recordUndoInset();
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
if (lastpos() != 0) {
|
|
|
|
// something left in the cell
|
|
|
|
if (pos() == 0) {
|
|
|
|
// cursor in first position
|
2007-11-05 19:41:16 +00:00
|
|
|
popBackward();
|
2004-01-26 10:13:15 +00:00
|
|
|
} else if (pos() == lastpos()) {
|
|
|
|
// cursor in last position
|
2007-11-05 19:41:16 +00:00
|
|
|
popForward();
|
2004-01-26 10:13:15 +00:00
|
|
|
} else {
|
|
|
|
// cursor in between. split cell
|
2007-04-26 16:06:39 +00:00
|
|
|
MathData::iterator bt = cell().begin();
|
2009-11-08 11:45:46 +00:00
|
|
|
MathAtom at = createInsetMath(from_utf8(font), buffer());
|
|
|
|
at.nucleus()->cell(0) = MathData(buffer(), bt, bt + pos());
|
2004-01-26 10:13:15 +00:00
|
|
|
cell().erase(bt, bt + pos());
|
2007-11-05 19:41:16 +00:00
|
|
|
popBackward();
|
2004-01-26 10:13:15 +00:00
|
|
|
plainInsert(at);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// nothing left in the cell
|
2008-09-14 17:51:46 +00:00
|
|
|
popBackward();
|
2004-01-26 10:13:15 +00:00
|
|
|
plainErase();
|
2008-09-14 17:51:46 +00:00
|
|
|
resetAnchor();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
insert(safe);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::undispatched() const
|
2004-02-16 11:58:51 +00:00
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
disp_.dispatched(false);
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::dispatched() const
|
2004-03-27 12:46:30 +00:00
|
|
|
{
|
|
|
|
disp_.dispatched(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::screenUpdateFlags(Update::flags f) const
|
2004-08-13 14:56:06 +00:00
|
|
|
{
|
2010-10-13 17:28:55 +00:00
|
|
|
disp_.screenUpdate(f);
|
2004-08-13 14:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-02 10:43:10 +00:00
|
|
|
void Cursor::noScreenUpdate() const
|
|
|
|
{
|
|
|
|
disp_.screenUpdate(Update::None);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::forceBufferUpdate() const
|
2010-07-09 14:37:00 +00:00
|
|
|
{
|
|
|
|
disp_.forceBufferUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::clearBufferUpdate() const
|
2010-07-09 14:37:00 +00:00
|
|
|
{
|
|
|
|
disp_.clearBufferUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::needBufferUpdate() const
|
|
|
|
{
|
|
|
|
return disp_.needBufferUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
Font Cursor::getFont() const
|
2005-01-10 09:28:06 +00:00
|
|
|
{
|
2012-10-27 13:45:27 +00:00
|
|
|
// The logic here should more or less match to the
|
|
|
|
// Cursor::setCurrentFont logic, i.e. the cursor height should
|
|
|
|
// give a hint what will happen if a character is entered.
|
2016-11-04 11:01:43 +00:00
|
|
|
// FIXME: this is not the case, what about removing this method ? (see #10478).
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2005-01-10 09:28:06 +00:00
|
|
|
// HACK. far from being perfect...
|
2008-02-07 17:07:27 +00:00
|
|
|
|
|
|
|
CursorSlice const & sl = innerTextSlice();
|
2007-04-29 23:33:02 +00:00
|
|
|
Text const & text = *sl.text();
|
2007-06-07 20:40:01 +00:00
|
|
|
Paragraph const & par = text.getPar(sl.pit());
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-06-07 20:40:01 +00:00
|
|
|
// on boundary, so we are really at the character before
|
|
|
|
pos_type pos = sl.pos();
|
|
|
|
if (pos > 0 && boundary())
|
|
|
|
--pos;
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-06-07 20:40:01 +00:00
|
|
|
// on space? Take the font before (only for RTL boundary stay)
|
|
|
|
if (pos > 0) {
|
2007-09-02 21:48:49 +00:00
|
|
|
TextMetrics const & tm = bv().textMetrics(&text);
|
2007-06-07 20:40:01 +00:00
|
|
|
if (pos == sl.lastpos()
|
2014-03-14 13:22:26 +00:00
|
|
|
|| (par.isSeparator(pos)
|
2007-09-02 22:28:49 +00:00
|
|
|
&& !tm.isRTLBoundary(sl.pit(), pos)))
|
2007-06-07 20:40:01 +00:00
|
|
|
--pos;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-06-07 20:40:01 +00:00
|
|
|
// get font at the position
|
2008-11-17 11:46:07 +00:00
|
|
|
Font font = par.getFont(buffer()->params(), pos,
|
2009-08-09 18:35:39 +00:00
|
|
|
text.outerFont(sl.pit()));
|
2005-02-08 13:18:05 +00:00
|
|
|
|
2005-01-10 09:28:06 +00:00
|
|
|
return font;
|
|
|
|
}
|
2005-02-15 17:34:54 +00:00
|
|
|
|
|
|
|
|
2012-07-17 20:26:44 +00:00
|
|
|
void Cursor::sanitize()
|
|
|
|
{
|
2018-01-16 15:00:07 +00:00
|
|
|
setBuffer(&bv_->buffer());
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
CursorData::sanitize();
|
2012-07-17 20:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-15 17:11:01 +00:00
|
|
|
bool notifyCursorLeavesOrEnters(Cursor const & old, Cursor & cur)
|
2007-06-14 20:32:28 +00:00
|
|
|
{
|
|
|
|
// find inset in common
|
|
|
|
size_type i;
|
|
|
|
for (i = 0; i < old.depth() && i < cur.depth(); ++i) {
|
2008-02-09 22:05:24 +00:00
|
|
|
if (&old[i].inset() != &cur[i].inset())
|
2007-06-14 20:32:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-26 19:20:12 +00:00
|
|
|
|
|
|
|
// update words if we just moved to another paragraph
|
|
|
|
if (i == old.depth() && i == cur.depth()
|
2008-11-17 11:46:07 +00:00
|
|
|
&& !cur.buffer()->isClean()
|
2008-02-26 19:20:12 +00:00
|
|
|
&& cur.inTexted() && old.inTexted()
|
|
|
|
&& cur.pit() != old.pit()) {
|
2009-05-01 09:56:20 +00:00
|
|
|
old.paragraph().updateWords();
|
2008-02-26 19:20:12 +00:00
|
|
|
}
|
2008-11-15 17:11:01 +00:00
|
|
|
|
2007-06-14 20:32:28 +00:00
|
|
|
// notify everything on top of the common part in old cursor,
|
|
|
|
// but stop if the inset claims the cursor to be invalid now
|
2008-11-15 17:11:01 +00:00
|
|
|
for (size_type j = i; j < old.depth(); ++j) {
|
2009-11-22 21:45:51 +00:00
|
|
|
Cursor inset_pos = old;
|
|
|
|
inset_pos.cutOff(j);
|
|
|
|
if (old[j].inset().notifyCursorLeaves(inset_pos, cur))
|
2008-11-15 17:11:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// notify everything on top of the common part in new cursor,
|
|
|
|
// but stop if the inset claims the cursor to be invalid now
|
|
|
|
for (; i < cur.depth(); ++i) {
|
|
|
|
if (cur[i].inset().notifyCursorEnters(cur))
|
2007-06-14 20:32:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-06-14 20:32:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-19 09:46:35 +00:00
|
|
|
void Cursor::setLanguageFromInput()
|
|
|
|
{
|
2020-10-21 16:08:39 +00:00
|
|
|
if (!lyxrc.respect_os_kbd_language
|
|
|
|
|| !inTexted()
|
|
|
|
|| paragraph().isPassThru())
|
2019-07-19 15:23:20 +00:00
|
|
|
return;
|
2019-07-19 09:46:35 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-02 13:35:48 +00:00
|
|
|
void Cursor::setCurrentFont()
|
|
|
|
{
|
2007-09-14 12:52:39 +00:00
|
|
|
CursorSlice const & cs = innerTextSlice();
|
|
|
|
Paragraph const & par = cs.paragraph();
|
|
|
|
pos_type cpit = cs.pit();
|
|
|
|
pos_type cpos = cs.pos();
|
|
|
|
Text const & ctext = *cs.text();
|
2007-09-02 21:48:49 +00:00
|
|
|
TextMetrics const & tm = bv().textMetrics(&ctext);
|
2007-09-02 13:35:48 +00:00
|
|
|
|
|
|
|
// are we behind previous char in fact? -> go to that char
|
|
|
|
if (cpos > 0 && boundary())
|
|
|
|
--cpos;
|
|
|
|
|
|
|
|
// find position to take the font from
|
|
|
|
if (cpos != 0) {
|
|
|
|
// paragraph end? -> font of last char
|
|
|
|
if (cpos == lastpos())
|
|
|
|
--cpos;
|
|
|
|
// on space? -> look at the words in front of space
|
|
|
|
else if (cpos > 0 && par.isSeparator(cpos)) {
|
|
|
|
// abc| def -> font of c
|
|
|
|
// abc |[WERBEH], i.e. boundary==true -> font of c
|
|
|
|
// abc [WERBEH]| def, font of the space
|
2007-09-14 12:52:39 +00:00
|
|
|
if (!tm.isRTLBoundary(cpit, cpos))
|
2007-09-02 13:35:48 +00:00
|
|
|
--cpos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get font
|
2008-11-17 11:46:07 +00:00
|
|
|
BufferParams const & bufparams = buffer()->params();
|
2007-09-02 13:35:48 +00:00
|
|
|
current_font = par.getFontSettings(bufparams, cpos);
|
2008-02-27 23:03:26 +00:00
|
|
|
real_current_font = tm.displayFont(cpit, cpos);
|
2007-09-02 13:35:48 +00:00
|
|
|
|
2019-07-19 09:46:35 +00:00
|
|
|
// set language to input language
|
|
|
|
setLanguageFromInput();
|
|
|
|
|
2007-09-02 13:35:48 +00:00
|
|
|
// special case for paragraph end
|
2007-09-14 12:52:39 +00:00
|
|
|
if (cs.pos() == lastpos()
|
|
|
|
&& tm.isRTLBoundary(cpit, cs.pos())
|
2007-09-02 13:35:48 +00:00
|
|
|
&& !boundary()) {
|
|
|
|
Language const * lang = par.getParLanguage(bufparams);
|
|
|
|
current_font.setLanguage(lang);
|
2007-10-28 18:51:54 +00:00
|
|
|
current_font.fontInfo().setNumber(FONT_OFF);
|
2007-09-02 13:35:48 +00:00
|
|
|
real_current_font.setLanguage(lang);
|
2007-10-28 18:51:54 +00:00
|
|
|
real_current_font.fontInfo().setNumber(FONT_OFF);
|
2007-09-02 13:35:48 +00:00
|
|
|
}
|
2020-11-10 12:47:53 +00:00
|
|
|
|
|
|
|
// No language in pass thru situations
|
|
|
|
if (cs.paragraph().isPassThru()) {
|
|
|
|
current_font.setLanguage(latex_language);
|
|
|
|
real_current_font.setLanguage(latex_language);
|
|
|
|
}
|
2007-09-02 13:35:48 +00:00
|
|
|
}
|
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
|
2008-01-12 21:38:51 +00:00
|
|
|
void Cursor::checkBufferStructure()
|
|
|
|
{
|
2021-01-14 19:17:51 +00:00
|
|
|
if (buffer()->isInternal())
|
|
|
|
return;
|
|
|
|
|
2008-11-17 11:46:07 +00:00
|
|
|
Buffer const * master = buffer()->masterBuffer();
|
2008-09-30 09:50:54 +00:00
|
|
|
master->tocBackend().updateItem(*this);
|
2009-02-19 00:29:04 +00:00
|
|
|
if (master != buffer() && !master->hasGuiDelegate())
|
2014-03-14 13:22:26 +00:00
|
|
|
// In case the master has no gui associated with it,
|
2009-02-19 00:29:04 +00:00
|
|
|
// the TocItem is not updated (part of bug 5699).
|
|
|
|
buffer()->tocBackend().updateItem(*this);
|
2008-01-12 21:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-18 21:23:14 +00:00
|
|
|
void Cursor::moveToClosestEdge(int const x, bool const edit)
|
|
|
|
{
|
|
|
|
if (Inset const * inset = nextInset()) {
|
|
|
|
// stay in front of insets for which we want to open the dialog
|
|
|
|
// (e.g. InsetMathSpace).
|
|
|
|
if (edit && (inset->hasSettings() || !inset->contextMenuName().empty()))
|
|
|
|
return;
|
|
|
|
CoordCache::Insets const & insetCache = bv().coordCache().getInsets();
|
2017-03-10 21:55:33 +00:00
|
|
|
if (!insetCache.has(inset))
|
|
|
|
return;
|
2017-02-18 21:23:14 +00:00
|
|
|
int const wid = insetCache.dim(inset).wid;
|
|
|
|
Point p = insetCache.xy(inset);
|
|
|
|
if (x > p.x_ + (wid + 1) / 2)
|
|
|
|
posForward();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|