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>
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
#include "Bidi.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"
|
2008-01-12 21:38:51 +00:00
|
|
|
#include "Cursor.h"
|
2004-03-25 09:16:36 +00:00
|
|
|
#include "CutAndPaste.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "Encoding.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
#include "Font.h"
|
2008-03-15 01:20:36 +00:00
|
|
|
#include "FuncCode.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#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"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "ParIterator.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
#include "Row.h"
|
|
|
|
#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
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-05 22:54:53 +00:00
|
|
|
#include "support/docstream.h"
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetTabular.h"
|
|
|
|
#include "insets/InsetText.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"
|
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"
|
|
|
|
#include "mathed/MathMacro.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
2010-04-22 11:16:58 +00:00
|
|
|
#include "support/bind.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
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
|
|
|
bool positionable(DocIterator const & cursor, DocIterator const & anchor)
|
|
|
|
{
|
|
|
|
// avoid deeper nested insets when selecting
|
|
|
|
if (cursor.depth() > anchor.depth())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// anchor might be deeper, should have same path then
|
|
|
|
for (size_t i = 0; i < cursor.depth(); ++i)
|
|
|
|
if (&cursor[i].inset() != &anchor[i].inset())
|
2004-08-13 19:19:53 +00:00
|
|
|
return false;
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
// position should be ok.
|
|
|
|
return true;
|
|
|
|
}
|
2004-08-13 19:19:53 +00:00
|
|
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
// Find position closest to (x, y) in cell given by iter.
|
|
|
|
// Used only in mathed
|
|
|
|
DocIterator bruteFind2(Cursor const & c, int x, int y)
|
|
|
|
{
|
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;
|
|
|
|
it.top().pos() = 0;
|
|
|
|
DocIterator et = c;
|
|
|
|
et.top().pos() = et.top().asInsetMath()->cell(et.top().idx()).size();
|
|
|
|
for (size_t i = 0;; ++i) {
|
|
|
|
int xo;
|
|
|
|
int yo;
|
|
|
|
Inset const * inset = &it.inset();
|
2007-12-12 19:28:07 +00:00
|
|
|
map<Inset const *, Geometry> const & data =
|
2007-11-28 22:12:03 +00:00
|
|
|
c.bv().coordCache().getInsets().getData();
|
2007-12-12 19:28:07 +00:00
|
|
|
map<Inset const *, Geometry>::const_iterator I = data.find(inset);
|
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.
|
|
|
|
if (I == data.end()) {
|
|
|
|
it.top().pos() = 0;
|
|
|
|
return it;
|
|
|
|
}
|
2004-08-13 19:19:53 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
Point o = I->second.pos;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/// moves position closest to (x, y) in given box
|
|
|
|
bool bruteFind(Cursor & cursor,
|
|
|
|
int x, int y, int xlow, int xhigh, int ylow, int yhigh)
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(!cursor.empty(), return false);
|
2007-11-28 22:12:03 +00:00
|
|
|
Inset & inset = cursor[0].inset();
|
|
|
|
BufferView & bv = cursor.bv();
|
|
|
|
|
|
|
|
CoordCache::InnerParPosCache const & cache =
|
|
|
|
bv.coordCache().getParPos().find(cursor.bottom().text())->second;
|
|
|
|
// Get an iterator on the first paragraph in the cache
|
|
|
|
DocIterator it(inset);
|
|
|
|
it.push_back(CursorSlice(inset));
|
|
|
|
it.pit() = cache.begin()->first;
|
|
|
|
// Get an iterator after the last paragraph in the cache
|
|
|
|
DocIterator et(inset);
|
|
|
|
et.push_back(CursorSlice(inset));
|
|
|
|
et.pit() = boost::prior(cache.end())->first;
|
|
|
|
if (et.pit() >= et.lastpit())
|
|
|
|
et = doc_iterator_end(inset);
|
|
|
|
else
|
|
|
|
++et.pit();
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
double best_dist = numeric_limits<double>::max();;
|
2007-11-28 22:12:03 +00:00
|
|
|
DocIterator best_cursor = et;
|
|
|
|
|
|
|
|
for ( ; it != et; it.forwardPos(true)) {
|
|
|
|
// avoid invalid nesting when selecting
|
|
|
|
if (!cursor.selection() || positionable(it, cursor.anchor_)) {
|
|
|
|
Point p = bv.getPos(it, false);
|
|
|
|
int xo = p.x_;
|
|
|
|
int yo = p.y_;
|
|
|
|
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
|
|
|
|
double const dx = xo - x;
|
|
|
|
double const dy = yo - y;
|
|
|
|
double const d = dx * dx + dy * dy;
|
|
|
|
// '<=' in order to take the last possible position
|
|
|
|
// this is important for clicking behind \sum in e.g. '\sum_i a'
|
|
|
|
if (d <= best_dist) {
|
|
|
|
// lyxerr << "*" << endl;
|
|
|
|
best_dist = d;
|
|
|
|
best_cursor = it;
|
2004-08-13 19:19:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-28 22:12:03 +00:00
|
|
|
}
|
2004-08-13 19:19:53 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
if (best_cursor != et) {
|
|
|
|
cursor.setCursor(best_cursor);
|
|
|
|
return true;
|
2004-08-13 19:19:53 +00:00
|
|
|
}
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*/
|
2005-07-18 17:12:28 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
|
|
|
/// moves position closest to (x, y) in given box
|
|
|
|
bool bruteFind3(Cursor & cur, int x, int y, bool up)
|
|
|
|
{
|
|
|
|
BufferView & bv = cur.bv();
|
|
|
|
int ylow = up ? 0 : y + 1;
|
|
|
|
int yhigh = up ? y - 1 : bv.workHeight();
|
|
|
|
int xlow = 0;
|
|
|
|
int xhigh = bv.workWidth();
|
2005-07-18 17:12:28 +00:00
|
|
|
|
|
|
|
// FIXME: bit more work needed to get 'from' and 'to' right.
|
2007-11-28 22:12:03 +00:00
|
|
|
pit_type from = cur.bottom().pit();
|
|
|
|
//pit_type to = cur.bottom().pit();
|
|
|
|
//lyxerr << "Pit start: " << from << endl;
|
|
|
|
|
|
|
|
//lyxerr << "bruteFind3: x: " << x << " y: " << y
|
|
|
|
// << " xlow: " << xlow << " xhigh: " << xhigh
|
|
|
|
// << " ylow: " << ylow << " yhigh: " << yhigh
|
|
|
|
// << endl;
|
2008-11-17 11:46:07 +00:00
|
|
|
DocIterator it = doc_iterator_begin(cur.buffer());
|
2007-11-28 22:12:03 +00:00
|
|
|
it.pit() = from;
|
2008-11-17 11:46:07 +00:00
|
|
|
DocIterator et = doc_iterator_end(cur.buffer());
|
2007-11-28 22:12:03 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
double best_dist = numeric_limits<double>::max();
|
2007-11-28 22:12:03 +00:00
|
|
|
DocIterator best_cursor = et;
|
|
|
|
|
|
|
|
for ( ; it != et; it.forwardPos()) {
|
|
|
|
// avoid invalid nesting when selecting
|
|
|
|
if (bv.cursorStatus(it) == CUR_INSIDE
|
2010-04-15 18:16:07 +00:00
|
|
|
&& (!cur.selection() || positionable(it, cur.realAnchor()))) {
|
2010-04-21 13:03:04 +00:00
|
|
|
// If this function is ever used again, check whether this
|
|
|
|
// is the same as "bv.getPos(it, false)" with boundary = false.
|
|
|
|
Point p = bv.getPos(it);
|
2007-11-28 22:12:03 +00:00
|
|
|
int xo = p.x_;
|
|
|
|
int yo = p.y_;
|
|
|
|
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
|
|
|
|
double const dx = xo - x;
|
|
|
|
double const dy = yo - y;
|
|
|
|
double const d = dx * dx + dy * dy;
|
|
|
|
//lyxerr << "itx: " << xo << " ity: " << yo << " d: " << d
|
|
|
|
// << " dx: " << dx << " dy: " << dy
|
|
|
|
// << " idx: " << it.idx() << " pos: " << it.pos()
|
|
|
|
// << " it:\n" << it
|
|
|
|
// << endl;
|
|
|
|
// '<=' in order to take the last possible position
|
|
|
|
// this is important for clicking behind \sum in e.g. '\sum_i a'
|
|
|
|
if (d <= best_dist) {
|
|
|
|
//lyxerr << "*" << endl;
|
|
|
|
best_dist = d;
|
|
|
|
best_cursor = it;
|
2005-07-18 17:12:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
//lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl;
|
|
|
|
if (best_cursor == et)
|
|
|
|
return false;
|
|
|
|
cur.setCursor(best_cursor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-08-13 19:19:53 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
2004-01-26 10:13:15 +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)
|
2008-11-17 11:46:07 +00:00
|
|
|
: DocIterator(&bv.buffer()), bv_(&bv), anchor_(),
|
|
|
|
x_target_(-1), textTargetOffset_(0),
|
2009-12-18 14:18:10 +00:00
|
|
|
selection_(false), mark_(false), word_selection_(false),
|
|
|
|
logicalpos_(false), current_font(inherit_font)
|
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
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
clear();
|
2009-10-29 22:46:04 +00:00
|
|
|
push_back(CursorSlice(buffer()->inset()));
|
|
|
|
anchor_ = doc_iterator_begin(buffer());
|
2008-02-09 15:23:05 +00:00
|
|
|
anchor_.clear();
|
2004-01-30 11:41:12 +00:00
|
|
|
clearTargetX();
|
2004-01-26 10:13:15 +00:00
|
|
|
selection_ = false;
|
|
|
|
mark_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-14 19:55:00 +00:00
|
|
|
// this (intentionally) does neither touch anchor nor selection status
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::setCursor(DocIterator const & cur)
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2004-03-31 19:11:56 +00:00
|
|
|
DocIterator::operator=(cur);
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
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
|
|
|
{
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR(Debug::DEBUG, "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-10-17 12:06:47 +00:00
|
|
|
disp_ = DispatchResult();
|
2009-10-03 19:12:21 +00:00
|
|
|
|
|
|
|
buffer()->undo().beginUndoGroup();
|
2007-05-29 20:53:32 +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()) {
|
2010-01-21 16:59:39 +00:00
|
|
|
buffer()->undo().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);
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(pos() <= lastpos(), /**/);
|
|
|
|
LASSERT(idx() <= lastidx(), /**/);
|
|
|
|
LASSERT(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
|
|
|
}
|
2007-06-14 20:32:28 +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
|
|
|
|
// a multiline inset becomes an inline inset when the second
|
|
|
|
// 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
|
|
|
}
|
2009-10-03 19:12:21 +00:00
|
|
|
buffer()->undo().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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
BufferView & Cursor::bv() const
|
2003-11-06 10:30:43 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(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
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(depth() >= 1, /**/);
|
2004-03-01 17:12:09 +00:00
|
|
|
pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
void Cursor::push(Inset & p)
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
|
|
|
push_back(CursorSlice(p));
|
2008-11-17 11:46:07 +00:00
|
|
|
p.setBuffer(*buffer());
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
void Cursor::pushBackward(Inset & p)
|
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;
|
2004-01-26 10:13:15 +00:00
|
|
|
push(p);
|
2004-03-18 12:53:43 +00:00
|
|
|
p.idxFirst(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
int Cursor::currentMode()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(!empty(), /**/);
|
2005-02-08 13:18:05 +00:00
|
|
|
for (int i = depth() - 1; i >= 0; --i) {
|
2004-03-18 12:53:43 +00:00
|
|
|
int res = operator[](i).inset().currentMode();
|
2009-07-03 00:05:58 +00:00
|
|
|
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)
|
2004-01-26 10:13:15 +00:00
|
|
|
return res;
|
|
|
|
}
|
2007-04-29 13:39:47 +00:00
|
|
|
return Inset::TEXT_MODE;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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());
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(!pm.rows().empty(), /**/);
|
2006-12-29 23:54:48 +00:00
|
|
|
return pm.getRow(pos(), boundary());
|
2006-12-19 13:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::resetAnchor()
|
2004-01-08 18:30:14 +00:00
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
anchor_ = *this;
|
2004-01-16 13:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:16:32 +00:00
|
|
|
void Cursor::setCursorToAnchor()
|
|
|
|
{
|
2010-01-06 16:59:12 +00:00
|
|
|
if (selection()) {
|
|
|
|
DocIterator normal = anchor_;
|
|
|
|
while (depth() < normal.depth())
|
|
|
|
normal.pop_back();
|
|
|
|
if (depth() < anchor_.depth() && top() <= anchor_[depth() - 1])
|
|
|
|
++normal.pos();
|
|
|
|
setCursor(normal);
|
|
|
|
}
|
2009-04-05 20:16:32 +00:00
|
|
|
}
|
|
|
|
|
2004-01-16 13:35:10 +00:00
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
bool Cursor::posBackward()
|
2004-01-16 13:35:10 +00:00
|
|
|
{
|
|
|
|
if (pos() == 0)
|
|
|
|
return false;
|
|
|
|
--pos();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
bool Cursor::posForward()
|
2004-01-16 13:35:10 +00:00
|
|
|
{
|
|
|
|
if (pos() == lastpos())
|
|
|
|
return false;
|
|
|
|
++pos();
|
|
|
|
return true;
|
|
|
|
}
|
2004-01-20 14:25:24 +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
|
|
|
|
bool new_pos_is_RTL; // is new position we're moving to RTL?
|
|
|
|
|
|
|
|
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)) {
|
2008-05-04 20:17:59 +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...
|
|
|
|
LYXERR(Debug::RTL, "entering inset at: " << new_cur.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we already at rightmost pos in row?
|
|
|
|
else if (text()->empty() || right_pos == -1) {
|
|
|
|
|
|
|
|
new_cur = *this;
|
|
|
|
if (!new_cur.posVisToNewRow(false)) {
|
|
|
|
LYXERR(Debug::RTL, "not moving!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we actually move the cursor at the end of this function, for now
|
|
|
|
// just keep track of the new position in new_cur...
|
|
|
|
LYXERR(Debug::RTL, "right edge, moving: " << int(new_cur.pit()) << ","
|
|
|
|
<< int(new_cur.pos()) << "," << (new_cur.boundary() ? 1 : 0));
|
|
|
|
|
|
|
|
}
|
|
|
|
// normal movement to the right
|
|
|
|
else {
|
|
|
|
new_cur = *this;
|
|
|
|
// 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.
|
|
|
|
new_pos_is_RTL = paragraph().getFontSettings(
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->params(), right_pos).isVisibleRightToLeft();
|
2008-05-04 20:17:59 +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.
|
|
|
|
if (!new_pos_is_RTL) {
|
|
|
|
new_cur.pos() = right_pos + 1;
|
|
|
|
// set the boundary to true in two situations:
|
|
|
|
if (
|
2008-11-01 17:00:58 +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
|
|
|
|
// 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()))
|
2008-05-04 20:17:59 +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);
|
|
|
|
}
|
|
|
|
// 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'.
|
|
|
|
else {
|
|
|
|
new_cur.pos() = right_pos;
|
|
|
|
new_cur.boundary(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool moved = (new_cur.pos() != pos()
|
|
|
|
|| new_cur.pit() != pit()
|
2009-02-08 14:14:30 +00:00
|
|
|
|| new_cur.boundary() != boundary()
|
|
|
|
|| &new_cur.inset() != &inset());
|
2008-05-04 20:17:59 +00:00
|
|
|
|
|
|
|
if (moved) {
|
|
|
|
LYXERR(Debug::RTL, "moving to: " << new_cur.pos()
|
|
|
|
<< (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
|
|
|
|
bool new_pos_is_RTL; // is new position we're moving to RTL?
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (!skip_inset &&
|
|
|
|
text()->checkAndActivateInsetVisual(new_cur, left_pos >= pos(), true)) {
|
|
|
|
// we actually move the cursor at the end of this function, for now
|
|
|
|
// we just keep track of the new position in new_cur...
|
|
|
|
LYXERR(Debug::RTL, "entering inset at: " << new_cur.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we already at leftmost pos in row?
|
|
|
|
else if (text()->empty() || left_pos == -1) {
|
|
|
|
|
|
|
|
new_cur = *this;
|
|
|
|
if (!new_cur.posVisToNewRow(true)) {
|
|
|
|
LYXERR(Debug::RTL, "not moving!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we actually move the cursor at the end of this function, for now
|
|
|
|
// just keep track of the new position in new_cur...
|
|
|
|
LYXERR(Debug::RTL, "left edge, moving: " << int(new_cur.pit()) << ","
|
|
|
|
<< int(new_cur.pos()) << "," << (new_cur.boundary() ? 1 : 0));
|
|
|
|
|
|
|
|
}
|
|
|
|
// normal movement to the left
|
|
|
|
else {
|
|
|
|
new_cur = *this;
|
|
|
|
// 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.
|
|
|
|
new_pos_is_RTL = paragraph().getFontSettings(
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->params(), left_pos).isVisibleRightToLeft();
|
2008-05-04 20:17:59 +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.
|
|
|
|
if (new_pos_is_RTL) {
|
|
|
|
new_cur.pos() = left_pos + 1;
|
|
|
|
// set the boundary to true in two situations:
|
|
|
|
if (
|
2008-11-01 17:00:58 +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
|
|
|
|
// 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()))
|
2008-05-04 20:17:59 +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);
|
|
|
|
}
|
|
|
|
// 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'.
|
|
|
|
else {
|
|
|
|
new_cur.pos() = left_pos;
|
|
|
|
new_cur.boundary(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool moved = (new_cur.pos() != pos()
|
|
|
|
|| new_cur.pit() != pit()
|
|
|
|
|| new_cur.boundary() != boundary());
|
|
|
|
|
|
|
|
if (moved) {
|
|
|
|
LYXERR(Debug::RTL, "moving to: " << new_cur.pos()
|
|
|
|
<< (new_cur.boundary() ? " (boundary)" : ""));
|
|
|
|
*this = new_cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
return moved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-10 19:52:45 +00:00
|
|
|
void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos)
|
|
|
|
{
|
|
|
|
// preparing bidi tables
|
|
|
|
Paragraph const & par = paragraph();
|
2008-11-17 11:46:07 +00:00
|
|
|
Buffer const & buf = *buffer();
|
2008-02-10 19:52:45 +00:00
|
|
|
Row const & row = textRow();
|
|
|
|
Bidi bidi;
|
|
|
|
bidi.computeTables(par, buf, row);
|
|
|
|
|
|
|
|
LYXERR(Debug::RTL, "bidi: " << row.pos() << "--" << row.endpos());
|
|
|
|
|
|
|
|
// The cursor is painted *before* the character at pos(), or, if 'boundary'
|
|
|
|
// is true, *after* the character at (pos() - 1). So we already have one
|
|
|
|
// known position around the cursor:
|
2009-02-26 21:37:58 +00:00
|
|
|
pos_type const known_pos = boundary() && pos() > 0 ? pos() - 1 : pos();
|
2008-02-10 19:52:45 +00:00
|
|
|
|
fix a visual cursor edge-case:
Only when an LTR paragraph *ends with* an RTL chunk of text, movement was
incorrect in two ways:
1. After moving into the pargraph from the end, and then trying to move towards
the beginning of the paragraph, the cursor would immediately jump to the
previous pargraph.
2. If the cursor were placed inside the RTL text, and then we would move left
towards the beginning of the paragraph, upon reaching the end (beginning?) of
the RTL chunk, cursor would jump to the end of the paragraph, and then continue
as in (1).
(Same thing, of course, with the reverse situation, i.e., RTL paragraph ending
with LTR text).
We now deal with both of these cases correctly.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23173 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-24 01:45:51 +00:00
|
|
|
// edge case: if we're at the end of the paragraph, things are a little
|
|
|
|
// different (because lastpos is a position which does not really "exist"
|
|
|
|
// --- there's no character there yet).
|
|
|
|
if (known_pos == lastpos()) {
|
|
|
|
if (par.isRTL(buf.params())) {
|
|
|
|
left_pos = -1;
|
|
|
|
right_pos = bidi.vis2log(row.pos());
|
2009-02-26 21:37:58 +00:00
|
|
|
} else {
|
|
|
|
// LTR paragraph
|
fix a visual cursor edge-case:
Only when an LTR paragraph *ends with* an RTL chunk of text, movement was
incorrect in two ways:
1. After moving into the pargraph from the end, and then trying to move towards
the beginning of the paragraph, the cursor would immediately jump to the
previous pargraph.
2. If the cursor were placed inside the RTL text, and then we would move left
towards the beginning of the paragraph, upon reaching the end (beginning?) of
the RTL chunk, cursor would jump to the end of the paragraph, and then continue
as in (1).
(Same thing, of course, with the reverse situation, i.e., RTL paragraph ending
with LTR text).
We now deal with both of these cases correctly.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23173 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-24 01:45:51 +00:00
|
|
|
right_pos = -1;
|
|
|
|
left_pos = bidi.vis2log(row.endpos() - 1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-10 19:52:45 +00:00
|
|
|
// Whether 'known_pos' is to the left or to the right of the cursor depends
|
|
|
|
// on whether it is an RTL or LTR character...
|
|
|
|
bool const cur_is_RTL =
|
|
|
|
par.getFontSettings(buf.params(), known_pos).isVisibleRightToLeft();
|
|
|
|
// ... in the following manner:
|
|
|
|
// For an RTL character, "before" means "to the right" and "after" means
|
|
|
|
// "to the left"; and for LTR, it's the reverse. So, 'known_pos' is to the
|
|
|
|
// right of the cursor if (RTL && boundary) or (!RTL && !boundary):
|
2009-02-26 21:37:58 +00:00
|
|
|
bool const known_pos_on_right = cur_is_RTL == boundary();
|
2008-02-10 19:52:45 +00:00
|
|
|
|
|
|
|
// So we now know one of the positions surrounding the cursor. Let's
|
2009-02-26 21:37:58 +00:00
|
|
|
// determine the other one:
|
2008-02-10 19:52:45 +00:00
|
|
|
if (known_pos_on_right) {
|
|
|
|
right_pos = known_pos;
|
|
|
|
// *visual* position of 'left_pos':
|
|
|
|
pos_type v_left_pos = bidi.log2vis(right_pos) - 1;
|
|
|
|
// If the position we just identified as 'left_pos' is a "skipped
|
|
|
|
// separator" (a separator which is at the logical end of a row,
|
|
|
|
// except for the last row in a paragraph; such separators are not
|
|
|
|
// painted, so they "are not really there"; note that in bidi text,
|
|
|
|
// such a separator could appear visually in the middle of a row),
|
|
|
|
// set 'left_pos' to the *next* position to the left.
|
|
|
|
if (bidi.inRange(v_left_pos)
|
|
|
|
&& bidi.vis2log(v_left_pos) + 1 == row.endpos()
|
|
|
|
&& row.endpos() < lastpos()
|
2009-02-26 21:37:58 +00:00
|
|
|
&& par.isSeparator(bidi.vis2log(v_left_pos)))
|
2008-02-10 19:52:45 +00:00
|
|
|
--v_left_pos;
|
2009-02-26 21:37:58 +00:00
|
|
|
|
2008-02-10 19:52:45 +00:00
|
|
|
// calculate the logical position of 'left_pos', if in row
|
|
|
|
if (!bidi.inRange(v_left_pos))
|
|
|
|
left_pos = -1;
|
|
|
|
else
|
|
|
|
left_pos = bidi.vis2log(v_left_pos);
|
|
|
|
// If the position we identified as 'right_pos' is a "skipped
|
|
|
|
// separator", set 'right_pos' to the *next* position to the right.
|
|
|
|
if (right_pos + 1 == row.endpos() && row.endpos() < lastpos()
|
|
|
|
&& par.isSeparator(right_pos)) {
|
2009-02-26 21:37:58 +00:00
|
|
|
pos_type const v_right_pos = bidi.log2vis(right_pos) + 1;
|
2008-02-10 19:52:45 +00:00
|
|
|
if (!bidi.inRange(v_right_pos))
|
|
|
|
right_pos = -1;
|
|
|
|
else
|
|
|
|
right_pos = bidi.vis2log(v_right_pos);
|
|
|
|
}
|
2009-02-26 21:37:58 +00:00
|
|
|
} else {
|
|
|
|
// known_pos is on the left
|
2008-02-10 19:52:45 +00:00
|
|
|
left_pos = known_pos;
|
|
|
|
// *visual* position of 'right_pos'
|
|
|
|
pos_type v_right_pos = bidi.log2vis(left_pos) + 1;
|
|
|
|
// If the position we just identified as 'right_pos' is a "skipped
|
|
|
|
// separator", set 'right_pos' to the *next* position to the right.
|
|
|
|
if (bidi.inRange(v_right_pos)
|
|
|
|
&& bidi.vis2log(v_right_pos) + 1 == row.endpos()
|
|
|
|
&& row.endpos() < lastpos()
|
2009-02-26 21:37:58 +00:00
|
|
|
&& par.isSeparator(bidi.vis2log(v_right_pos)))
|
2008-02-10 19:52:45 +00:00
|
|
|
++v_right_pos;
|
2009-02-26 21:37:58 +00:00
|
|
|
|
2008-02-10 19:52:45 +00:00
|
|
|
// calculate the logical position of 'right_pos', if in row
|
|
|
|
if (!bidi.inRange(v_right_pos))
|
|
|
|
right_pos = -1;
|
|
|
|
else
|
|
|
|
right_pos = bidi.vis2log(v_right_pos);
|
|
|
|
// If the position we identified as 'left_pos' is a "skipped
|
|
|
|
// separator", set 'left_pos' to the *next* position to the left.
|
|
|
|
if (left_pos + 1 == row.endpos() && row.endpos() < lastpos()
|
|
|
|
&& par.isSeparator(left_pos)) {
|
2009-02-26 21:37:58 +00:00
|
|
|
pos_type const v_left_pos = bidi.log2vis(left_pos) - 1;
|
2008-02-10 19:52:45 +00:00
|
|
|
if (!bidi.inRange(v_left_pos))
|
|
|
|
left_pos = -1;
|
|
|
|
else
|
|
|
|
left_pos = bidi.vis2log(v_left_pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::posVisToNewRow(bool movingLeft)
|
|
|
|
{
|
|
|
|
Paragraph const & par = paragraph();
|
2008-11-17 11:46:07 +00:00
|
|
|
Buffer const & buf = *buffer();
|
2008-02-10 19:52:45 +00:00
|
|
|
Row const & row = textRow();
|
|
|
|
bool par_is_LTR = !par.isRTL(buf.params());
|
2008-04-11 12:02:10 +00:00
|
|
|
|
|
|
|
// Inside a table, determining whether to move to the next or previous row
|
|
|
|
// should be done based on the table's direction.
|
|
|
|
int s = depth() - 1;
|
|
|
|
if (s >= 1 && (*this)[s].inset().asInsetTabular()) {
|
|
|
|
par_is_LTR = !(*this)[s].inset().asInsetTabular()->isRightToLeft(*this);
|
|
|
|
LYXERR(Debug::RTL, "Inside table! par_is_LTR=" << (par_is_LTR ? 1 : 0));
|
|
|
|
}
|
2008-02-10 19:52:45 +00:00
|
|
|
|
|
|
|
// if moving left in an LTR paragraph or moving right in an RTL one,
|
|
|
|
// move to previous row
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if moving left in an RTL paragraph or moving right in an LTR one,
|
|
|
|
// move to next row
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure we're at left-/right-most pos in new row
|
|
|
|
posVisToRowExtremity(!movingLeft);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::posVisToRowExtremity(bool left)
|
|
|
|
{
|
|
|
|
// prepare bidi tables
|
|
|
|
Paragraph const & par = paragraph();
|
2008-11-17 11:46:07 +00:00
|
|
|
Buffer const & buf = *buffer();
|
2008-02-10 19:52:45 +00:00
|
|
|
Row const & row = textRow();
|
|
|
|
Bidi bidi;
|
|
|
|
bidi.computeTables(par, buf, row);
|
|
|
|
|
|
|
|
LYXERR(Debug::RTL, "entering extremity: " << pit() << "," << pos() << ","
|
|
|
|
<< (boundary() ? 1 : 0));
|
|
|
|
|
|
|
|
if (left) { // move to leftmost position
|
|
|
|
// if this is an RTL paragraph, and we're at the last row in the
|
|
|
|
// paragraph, move to lastpos
|
|
|
|
if (par.isRTL(buf.params()) && row.endpos() == lastpos())
|
|
|
|
pos() = lastpos();
|
|
|
|
else {
|
|
|
|
pos() = bidi.vis2log(row.pos());
|
|
|
|
|
|
|
|
// Moving to the leftmost position in the row, the cursor should
|
|
|
|
// normally be placed to the *left* of the leftmost position.
|
|
|
|
// A very common exception, though, is if the leftmost character
|
|
|
|
// also happens to be the separator at the (logical) end of the row
|
|
|
|
// --- in this case, the separator is positioned beyond the left
|
|
|
|
// margin, and we don't want to move the cursor there (moving to
|
|
|
|
// the left of the separator is equivalent to moving to the next
|
|
|
|
// line). So, in this case we actually want to place the cursor
|
|
|
|
// to the *right* of the leftmost position (the separator).
|
|
|
|
// Another exception is if we're moving to the logically last
|
|
|
|
// position in the row, which is *not* a separator: this means
|
|
|
|
// that the entire row has no separators (if there were any, the
|
|
|
|
// row would have been broken there); and therefore in this case
|
|
|
|
// we also move to the *right* of the last position (this indicates
|
|
|
|
// to the user that there is no space after this position, and is
|
|
|
|
// consistent with the behavior in the middle of a row --- moving
|
|
|
|
// right or left moves to the next/previous character; if we were
|
|
|
|
// to move to the *left* of this position, that would simulate
|
|
|
|
// a separator which is not really there!).
|
|
|
|
// Finally, there is an exception to the previous exception: if
|
|
|
|
// this non-separator-but-last-position-in-row is an inset, then
|
|
|
|
// we *do* want to stay to the left of it anyway: this is the
|
|
|
|
// "boundary" which we simulate at insets.
|
2009-02-26 21:01:35 +00:00
|
|
|
// Another exception is when row.endpos() is 0.
|
2008-02-10 19:52:45 +00:00
|
|
|
|
2009-02-26 21:13:50 +00:00
|
|
|
// do we want to be to the right of pos?
|
2008-02-10 19:52:45 +00:00
|
|
|
// as explained above, if at last pos in row, stay to the right
|
2009-02-26 21:13:50 +00:00
|
|
|
bool const right_of_pos = row.endpos() > 0
|
|
|
|
&& pos() == row.endpos() - 1 && !par.isInset(pos());
|
2008-02-10 19:52:45 +00:00
|
|
|
|
|
|
|
// Now we know if we want to be to the left or to the right of pos,
|
|
|
|
// let's make sure we are where we want to be.
|
2009-02-26 21:13:50 +00:00
|
|
|
bool const new_pos_is_RTL =
|
2008-02-10 19:52:45 +00:00
|
|
|
par.getFontSettings(buf.params(), pos()).isVisibleRightToLeft();
|
|
|
|
|
2009-02-26 21:13:50 +00:00
|
|
|
if (new_pos_is_RTL != right_of_pos) {
|
2008-02-10 19:52:45 +00:00
|
|
|
++pos();
|
|
|
|
boundary(true);
|
|
|
|
}
|
|
|
|
}
|
2009-02-26 21:13:50 +00:00
|
|
|
} else {
|
|
|
|
// move to rightmost position
|
2008-02-10 19:52:45 +00:00
|
|
|
// if this is an LTR paragraph, and we're at the last row in the
|
|
|
|
// paragraph, move to lastpos
|
|
|
|
if (!par.isRTL(buf.params()) && row.endpos() == lastpos())
|
|
|
|
pos() = lastpos();
|
|
|
|
else {
|
2009-02-26 21:13:50 +00:00
|
|
|
pos() = row.endpos() > 0 ? bidi.vis2log(row.endpos() - 1) : 0;
|
2008-02-10 19:52:45 +00:00
|
|
|
|
|
|
|
// Moving to the rightmost position in the row, the cursor should
|
|
|
|
// normally be placed to the *right* of the rightmost position.
|
|
|
|
// A very common exception, though, is if the rightmost character
|
|
|
|
// also happens to be the separator at the (logical) end of the row
|
|
|
|
// --- in this case, the separator is positioned beyond the right
|
|
|
|
// margin, and we don't want to move the cursor there (moving to
|
|
|
|
// the right of the separator is equivalent to moving to the next
|
|
|
|
// line). So, in this case we actually want to place the cursor
|
|
|
|
// to the *left* of the rightmost position (the separator).
|
|
|
|
// Another exception is if we're moving to the logically last
|
|
|
|
// position in the row, which is *not* a separator: this means
|
|
|
|
// that the entire row has no separators (if there were any, the
|
|
|
|
// row would have been broken there); and therefore in this case
|
|
|
|
// we also move to the *left* of the last position (this indicates
|
|
|
|
// to the user that there is no space after this position, and is
|
|
|
|
// consistent with the behavior in the middle of a row --- moving
|
|
|
|
// right or left moves to the next/previous character; if we were
|
|
|
|
// to move to the *right* of this position, that would simulate
|
|
|
|
// a separator which is not really there!).
|
|
|
|
// Finally, there is an exception to the previous exception: if
|
|
|
|
// this non-separator-but-last-position-in-row is an inset, then
|
|
|
|
// we *do* want to stay to the right of it anyway: this is the
|
|
|
|
// "boundary" which we simulate at insets.
|
2009-02-26 21:01:35 +00:00
|
|
|
// Another exception is when row.endpos() is 0.
|
2008-02-10 19:52:45 +00:00
|
|
|
|
2009-02-26 21:13:50 +00:00
|
|
|
// do we want to be to the left of pos?
|
2009-02-26 21:01:35 +00:00
|
|
|
// as explained above, if at last pos in row, stay to the left,
|
|
|
|
// unless the last position is the same as the first.
|
2009-02-26 21:13:50 +00:00
|
|
|
bool const left_of_pos = row.endpos() > 0
|
2009-02-26 21:17:34 +00:00
|
|
|
&& pos() == row.endpos() - 1 && !par.isInset(pos());
|
2008-02-10 19:52:45 +00:00
|
|
|
|
|
|
|
// Now we know if we want to be to the left or to the right of pos,
|
|
|
|
// let's make sure we are where we want to be.
|
2009-02-26 21:13:50 +00:00
|
|
|
bool const new_pos_is_RTL =
|
2008-02-10 19:52:45 +00:00
|
|
|
par.getFontSettings(buf.params(), pos()).isVisibleRightToLeft();
|
|
|
|
|
|
|
|
if (new_pos_is_RTL == left_of_pos) {
|
|
|
|
++pos();
|
|
|
|
boundary(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LYXERR(Debug::RTL, "leaving extremity: " << pit() << "," << pos() << ","
|
|
|
|
<< (boundary() ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-15 17:49:15 +00:00
|
|
|
CursorSlice Cursor::normalAnchor() const
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
2009-06-23 14:54:35 +00:00
|
|
|
if (!selection())
|
|
|
|
return top();
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(anchor_.depth() >= depth(), /**/);
|
2005-02-08 13:18:05 +00:00
|
|
|
CursorSlice normal = anchor_[depth() - 1];
|
|
|
|
if (depth() < anchor_.depth() && top() <= normal) {
|
2004-04-07 13:15:34 +00:00
|
|
|
// anchor is behind cursor -> move anchor behind the inset
|
|
|
|
++normal.pos();
|
2004-04-07 08:07:26 +00:00
|
|
|
}
|
2004-04-07 13:15:34 +00:00
|
|
|
return normal;
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-15 18:16:07 +00:00
|
|
|
DocIterator & Cursor::realAnchor()
|
|
|
|
{
|
|
|
|
return anchor_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
CursorSlice Cursor::selBegin() const
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
|
|
|
if (!selection())
|
2005-02-08 13:18:05 +00:00
|
|
|
return top();
|
2010-04-15 17:49:15 +00:00
|
|
|
return normalAnchor() < top() ? normalAnchor() : top();
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
CursorSlice Cursor::selEnd() const
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
|
|
|
if (!selection())
|
2005-02-08 13:18:05 +00:00
|
|
|
return top();
|
2010-04-15 17:49:15 +00:00
|
|
|
return normalAnchor() > top() ? normalAnchor() : top();
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
DocIterator Cursor::selectionBegin() const
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
|
|
|
if (!selection())
|
2004-03-25 09:16:36 +00:00
|
|
|
return *this;
|
2008-09-13 23:03:33 +00:00
|
|
|
|
|
|
|
DocIterator di;
|
|
|
|
// FIXME: This is a work-around for the problem that
|
|
|
|
// CursorSlice doesn't keep track of the boundary.
|
2010-04-15 17:49:15 +00:00
|
|
|
if (normalAnchor() == top())
|
2008-09-13 23:03:33 +00:00
|
|
|
di = anchor_.boundary() > boundary() ? anchor_ : *this;
|
|
|
|
else
|
2010-04-15 17:49:15 +00:00
|
|
|
di = normalAnchor() < top() ? anchor_ : *this;
|
2005-11-07 15:02:08 +00:00
|
|
|
di.resize(depth());
|
|
|
|
return di;
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
DocIterator Cursor::selectionEnd() const
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
2004-02-11 14:45:44 +00:00
|
|
|
if (!selection())
|
2004-03-25 09:16:36 +00:00
|
|
|
return *this;
|
2008-09-13 23:03:33 +00:00
|
|
|
|
|
|
|
DocIterator di;
|
|
|
|
// FIXME: This is a work-around for the problem that
|
|
|
|
// CursorSlice doesn't keep track of the boundary.
|
2010-04-15 17:49:15 +00:00
|
|
|
if (normalAnchor() == top())
|
2008-09-13 23:03:33 +00:00
|
|
|
di = anchor_.boundary() < boundary() ? anchor_ : *this;
|
|
|
|
else
|
2010-04-15 17:49:15 +00:00
|
|
|
di = normalAnchor() > top() ? anchor_ : *this;
|
2008-09-13 23:03:33 +00:00
|
|
|
|
2005-11-07 15:02:08 +00:00
|
|
|
if (di.depth() > depth()) {
|
|
|
|
di.resize(depth());
|
|
|
|
++di.pos();
|
|
|
|
}
|
|
|
|
return di;
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::setSelection()
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
2008-09-24 21:27:41 +00:00
|
|
|
setSelection(true);
|
2005-07-14 17:30:24 +00:00
|
|
|
// A selection with no contents is not a selection
|
2007-08-10 11:47:12 +00:00
|
|
|
// FIXME: doesnt look ok
|
2010-04-15 17:49:15 +00:00
|
|
|
if (idx() == normalAnchor().idx() &&
|
|
|
|
pit() == normalAnchor().pit() &&
|
|
|
|
pos() == normalAnchor().pos())
|
2008-09-24 21:27:41 +00:00
|
|
|
setSelection(false);
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::setSelection(DocIterator const & where, int n)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2004-08-14 19:55:00 +00:00
|
|
|
setCursor(where);
|
2008-09-24 21:27:41 +00:00
|
|
|
setSelection(true);
|
2004-01-26 10:13:15 +00:00
|
|
|
anchor_ = where;
|
|
|
|
pos() += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::clearSelection()
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
2008-09-24 21:27:41 +00:00
|
|
|
setSelection(false);
|
2009-12-18 14:18:10 +00:00
|
|
|
setWordSelection(false);
|
2008-09-24 21:27:41 +00:00
|
|
|
setMark(false);
|
2004-01-20 14:25:24 +00:00
|
|
|
resetAnchor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::info(odocstream & os) const
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
|
|
|
for (int i = 1, n = depth(); i < n; ++i) {
|
2004-03-18 12:53:43 +00:00
|
|
|
operator[](i).inset().infoize(os);
|
2004-01-20 14:25:24 +00:00
|
|
|
os << " ";
|
|
|
|
}
|
2007-02-08 08:44:45 +00:00
|
|
|
if (pos() != 0) {
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset const * inset = prevInset();
|
2007-02-08 08:44:45 +00:00
|
|
|
// prevInset() can return 0 in certain case.
|
|
|
|
if (inset)
|
|
|
|
prevInset()->infoize2(os);
|
|
|
|
}
|
2004-01-20 14:25:24 +00:00
|
|
|
// overwite old message
|
|
|
|
os << " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool Cursor::selHandle(bool sel)
|
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())
|
|
|
|
sel = true;
|
2004-05-18 07:18:02 +00:00
|
|
|
if (sel == selection())
|
2006-10-22 11:46:36 +00:00
|
|
|
return false;
|
2004-04-20 08:51:15 +00:00
|
|
|
|
2007-07-10 12:44:19 +00:00
|
|
|
if (!sel)
|
|
|
|
cap::saveSelection(*this);
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
resetAnchor();
|
2008-09-24 21:27:41 +00:00
|
|
|
setSelection(sel);
|
2006-10-22 11:46:36 +00:00
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
ostream & operator<<(ostream & os, Cursor const & cur)
|
2004-01-20 14:25:24 +00:00
|
|
|
{
|
2004-08-13 12:05:27 +00:00
|
|
|
os << "\n cursor: | anchor:\n";
|
2005-02-08 13:18:05 +00:00
|
|
|
for (size_t i = 0, n = cur.depth(); i != n; ++i) {
|
|
|
|
os << " " << cur[i] << " | ";
|
|
|
|
if (i < cur.anchor_.depth())
|
2004-03-25 09:16:36 +00:00
|
|
|
os << cur.anchor_[i];
|
|
|
|
else
|
|
|
|
os << "-------------------------------";
|
|
|
|
os << "\n";
|
|
|
|
}
|
2005-02-08 13:18:05 +00:00
|
|
|
for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
|
2004-03-25 09:16:36 +00:00
|
|
|
os << "------------------------------- | " << cur.anchor_[i] << "\n";
|
|
|
|
}
|
|
|
|
os << " selection: " << cur.selection_
|
|
|
|
<< " x_target: " << cur.x_target_ << endl;
|
2004-02-06 16:50:29 +00:00
|
|
|
return os;
|
2004-01-20 14:25:24 +00:00
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
|
|
|
LyXErr & operator<<(LyXErr & os, Cursor const & cur)
|
|
|
|
{
|
|
|
|
os.stream() << cur;
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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/InsetMathGrid.h"
|
|
|
|
#include "mathed/InsetMathScript.h"
|
|
|
|
#include "mathed/InsetMathUnknown.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "mathed/MathFactory.h"
|
|
|
|
#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 {
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
//#define FILEDEBUG 1
|
|
|
|
|
|
|
|
|
2007-12-22 14:38:20 +00:00
|
|
|
bool Cursor::isInside(Inset const * p) const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2005-05-06 20:00:31 +00:00
|
|
|
for (size_t i = 0; i != depth(); ++i)
|
2004-03-18 12:53:43 +00:00
|
|
|
if (&operator[](i).inset() == p)
|
2004-01-26 10:13:15 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
void Cursor::leaveInset(Inset const & inset)
|
2005-05-06 18:54:36 +00:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i != depth(); ++i) {
|
|
|
|
if (&operator[](i).inset() == &inset) {
|
|
|
|
resize(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2005-02-08 13:18:05 +00:00
|
|
|
if (depth() >= anchor_.depth())
|
2004-01-26 10:13:15 +00:00
|
|
|
return false;
|
2007-11-01 22:17:22 +00:00
|
|
|
if (t.nucleus() != &anchor_[depth()].inset())
|
2004-01-26 10:13:15 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-16 10:39:44 +00:00
|
|
|
void Cursor::setScreenPos(int x, int /*y*/)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-05-29 20:53:32 +00:00
|
|
|
setTargetX(x);
|
2007-09-11 16:04:10 +00:00
|
|
|
//bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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::markInsert()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2006-04-09 02:30:40 +00:00
|
|
|
insert(char_type(0));
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::markErase()
|
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();
|
2010-07-09 14:37:00 +00:00
|
|
|
forceBufferUpdate();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::insert(docstring const & str)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2004-11-06 15:23:12 +00:00
|
|
|
for_each(str.begin(), str.end(),
|
2010-04-22 11:16:58 +00:00
|
|
|
bind(static_cast<void(Cursor::*)(char_type)>
|
2007-04-26 14:56:30 +00:00
|
|
|
(&Cursor::insert), this, _1));
|
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;
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(!empty(), /**/);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::insert(MathAtom const & t)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
//lyxerr << "Cursor::insert MathAtom '" << t << "'" << endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
macroModeClose();
|
2006-10-21 00:16:43 +00:00
|
|
|
cap::selClearOrDel(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
plainInsert(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-29 20:55:56 +00:00
|
|
|
void Cursor::insert(Inset * inset0)
|
2004-02-11 14:45:44 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(inset0, /**/);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-11 01:30:33 +00:00
|
|
|
void Cursor::niceInsert(docstring const & t, Parse::flags f, bool enter)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2009-11-15 01:03:03 +00:00
|
|
|
MathData ar(buffer());
|
2008-10-17 21:40:11 +00:00
|
|
|
asArray(t, ar, f);
|
2009-12-11 01:46:57 +00:00
|
|
|
if (ar.size() == 1 && (enter || selection()))
|
2004-01-26 10:13:15 +00:00
|
|
|
niceInsert(ar[0]);
|
|
|
|
else
|
|
|
|
insert(ar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::niceInsert(MathAtom const & t)
|
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()) {
|
2007-11-05 19:41:16 +00:00
|
|
|
posBackward();
|
|
|
|
// be careful here: don't use 'pushBackward(t)' as this we need to
|
2004-02-11 14:45:44 +00:00
|
|
|
// push the clone, not the original
|
2007-11-05 19:41:16 +00:00
|
|
|
pushBackward(*nextInset());
|
2006-02-28 19:16:38 +00:00
|
|
|
// We may not use niceInsert here (recursion)
|
2009-11-15 01:03:03 +00:00
|
|
|
MathData ar(buffer());
|
2006-10-22 10:15:23 +00:00
|
|
|
asArray(safe, ar);
|
2006-02-28 19:16:38 +00:00
|
|
|
insert(ar);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 16:06:39 +00:00
|
|
|
void Cursor::insert(MathData const & ar)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
macroModeClose();
|
|
|
|
if (selection())
|
2006-10-21 00:16:43 +00:00
|
|
|
cap::eraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
cell().insert(pos(), ar);
|
|
|
|
pos() += ar.size();
|
2010-07-09 14:37:00 +00:00
|
|
|
// FIXME audit setBuffer calls
|
2010-01-28 17:37:22 +00:00
|
|
|
inset().setBuffer(bv_->buffer());
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool Cursor::backspace()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
autocorrect() = false;
|
|
|
|
|
|
|
|
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 {
|
2007-03-29 21:58:15 +00:00
|
|
|
if (inMathed())
|
|
|
|
pullArg();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos() != 0 && prevAtom()->nargs() > 0) {
|
|
|
|
// let's require two backspaces for 'big stuff' and
|
|
|
|
// highlight on the first
|
2004-04-05 16:44:10 +00:00
|
|
|
resetAnchor();
|
2008-09-24 21:27:41 +00:00
|
|
|
setSelection(true);
|
2004-02-25 14:39:14 +00:00
|
|
|
--pos();
|
2004-01-26 10:13:15 +00:00
|
|
|
} else {
|
|
|
|
--pos();
|
|
|
|
plainErase();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool Cursor::erase()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
autocorrect() = false;
|
|
|
|
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
|
2005-10-03 12:22:19 +00:00
|
|
|
if (pos() != lastpos() && nextAtom()->nargs() > 0) {
|
2004-04-05 16:44:10 +00:00
|
|
|
resetAnchor();
|
2008-09-24 21:27:41 +00:00
|
|
|
setSelection(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);
|
2004-01-26 10:13:15 +00:00
|
|
|
autocorrect() = false;
|
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);
|
2004-01-26 10:13:15 +00:00
|
|
|
autocorrect() = false;
|
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::macroModeClose()
|
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());
|
|
|
|
|
|
|
|
// do nothing if the macro name is empty
|
|
|
|
if (s == "\\")
|
2006-01-11 17:08:50 +00:00
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
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
|
|
|
|
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;
|
2009-11-06 15:18:48 +00:00
|
|
|
MathAtom atom = buffer()->getMacro(name, *this, false) ?
|
2009-11-08 11:45:46 +00:00
|
|
|
MathAtom(new MathMacro(buffer(), name)) : 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;
|
2007-11-01 14:45:14 +00:00
|
|
|
MathMacro * atomAsMacro = atom.nucleus()->asMacro();
|
|
|
|
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());
|
2008-03-04 14:49:24 +00:00
|
|
|
if (selection.size() > 0 && data && data->numargs() - data->optionals() > 0) {
|
|
|
|
macroArg = true;
|
|
|
|
atomAsMacro->setDisplayMode(MathMacro::DISPLAY_INTERACTIVE_INIT, 1);
|
|
|
|
} else
|
|
|
|
// non-greedy case. Do not touch the arguments behind
|
|
|
|
atomAsMacro->setDisplayMode(MathMacro::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
|
|
|
|
else if (atom.nucleus()->nargs() > 0)
|
|
|
|
atom.nucleus()->cell(0).append(selection);
|
|
|
|
|
2007-11-01 14:40:15 +00:00
|
|
|
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())
|
2008-03-04 14:49:24 +00:00
|
|
|
plainInsert(MathAtom(new InsetMathBrace(selection)));
|
|
|
|
else
|
|
|
|
insert(selection);
|
|
|
|
}
|
|
|
|
|
2006-01-11 17:08:50 +00:00
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
docstring Cursor::macroName()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
return inMacroMode() ? activeMacro()->name() : docstring();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::handleNest(MathAtom const & a, int c)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
//lyxerr << "Cursor::handleNest: " << c << endl;
|
2004-01-30 11:41:12 +00:00
|
|
|
MathAtom t = a;
|
2006-10-22 10:15:23 +00:00
|
|
|
asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
|
2004-01-30 11:41:12 +00:00
|
|
|
insert(t);
|
2007-11-05 19:41:16 +00:00
|
|
|
posBackward();
|
|
|
|
pushBackward(*nextInset());
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
int Cursor::targetX() const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
if (x_target() != -1)
|
|
|
|
return x_target();
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2004-01-30 11:41:12 +00:00
|
|
|
getPos(x, y);
|
2004-01-26 10:13:15 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
int Cursor::textTargetOffset() const
|
|
|
|
{
|
|
|
|
return textTargetOffset_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::setTargetX()
|
2004-11-30 01:59:49 +00:00
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
2004-11-30 01:59:49 +00:00
|
|
|
getPos(x, y);
|
2007-05-29 20:53:32 +00:00
|
|
|
setTargetX(x);
|
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;
|
2004-08-13 12:05:27 +00:00
|
|
|
if (pos() == 0)
|
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
|
|
|
{
|
|
|
|
return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
InsetMathUnknown const * Cursor::activeMacro() const
|
|
|
|
{
|
|
|
|
return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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::touch()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-08-10 11:47:12 +00:00
|
|
|
// FIXME: look here
|
2004-01-26 10:13:15 +00:00
|
|
|
#if 0
|
2004-03-31 19:11:56 +00:00
|
|
|
DocIterator::const_iterator it = begin();
|
|
|
|
DocIterator::const_iterator et = end();
|
2004-01-26 10:13:15 +00:00
|
|
|
for ( ; it != et; ++it)
|
|
|
|
it->cell().touch();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2009-08-07 05:25:22 +00:00
|
|
|
WriteStream wi(os, false, true, WriteStream::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.
|
|
|
|
|
|
|
|
// 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
|
|
|
|
bool inRTL = isWithinRtlParagraph(*this);
|
|
|
|
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();
|
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
|
|
|
}
|
|
|
|
}
|
2007-05-29 20:53:32 +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;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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())
|
|
|
|
setCursor(bruteFind2(*this, xo, yo));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-16 18:03:52 +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;
|
|
|
|
}
|
|
|
|
|
2007-08-11 10:32:36 +00:00
|
|
|
bool Cursor::upDownInText(bool up, bool & updateNeeded)
|
2007-05-29 20:53:32 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(text(), /**/);
|
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()) {
|
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.
|
|
|
|
|
|
|
|
// 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
|
|
|
|
bool inRTL = isWithinRtlParagraph(*this);
|
|
|
|
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();
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// will a next dispatch follow and if there is a new
|
|
|
|
// dispatch will it move the cursor out ?
|
|
|
|
if (depth() > 1 && valid_destination) {
|
|
|
|
// The cursor hasn't changed yet. This happens when
|
|
|
|
// you e.g. move out of an inset. And to give the
|
|
|
|
// 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();
|
2010-07-09 14:37:00 +00:00
|
|
|
if (updateNeeded)
|
|
|
|
forceBufferUpdate();
|
2009-04-15 20:20:42 +00:00
|
|
|
}
|
2008-11-16 18:03:52 +00:00
|
|
|
return false;
|
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()) {
|
2010-04-21 13:03:04 +00:00
|
|
|
int yo = bv().getPos(*this).y_;
|
2007-05-29 20:53:32 +00:00
|
|
|
Cursor old = *this;
|
|
|
|
// To next/previous row
|
|
|
|
if (up)
|
2007-09-02 09:44:08 +00:00
|
|
|
tm.editXY(*this, xo, yo - textRow().ascent() - 1);
|
2007-05-29 20:53:32 +00:00
|
|
|
else
|
2007-09-02 09:44:08 +00:00
|
|
|
tm.editXY(*this, xo, yo + textRow().descent() + 1);
|
2007-05-29 20:53:32 +00:00
|
|
|
clearSelection();
|
2009-04-15 20:20:42 +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)
|
|
|
|
Cursor dummy = *this;
|
|
|
|
if (dummy == old)
|
|
|
|
++dummy.pos();
|
|
|
|
if (bv().checkDepm(dummy, old)) {
|
|
|
|
updateNeeded = true;
|
2010-07-09 14:37:00 +00:00
|
|
|
// Make sure that cur gets back whatever happened to dummy (Lgb)
|
2009-04-15 20:20:42 +00:00
|
|
|
operator=(dummy);
|
|
|
|
}
|
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();
|
2008-03-06 15:39:30 +00:00
|
|
|
TextMetrics & tm = bv_->textMetrics(text());
|
|
|
|
if (!tm.contains(pit()))
|
|
|
|
tm.newParMetricsUp();
|
|
|
|
ParagraphMetrics const & pmcur = tm.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();
|
2008-03-06 15:39:30 +00:00
|
|
|
TextMetrics & tm = bv_->textMetrics(text());
|
|
|
|
if (!tm.contains(pit()))
|
|
|
|
tm.newParMetricsDown();
|
2009-11-05 12:58:25 +00:00
|
|
|
next_row = 0;
|
2007-05-29 20:53:32 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-05 19:51:17 +00:00
|
|
|
top().pos() = min(tm.x2pos(pit(), next_row, xo), top().lastpos());
|
2007-06-14 20:32:28 +00:00
|
|
|
|
2009-11-15 22:01:12 +00:00
|
|
|
int const xpos = tm.x2pos(pit(), next_row, xo);
|
|
|
|
bool const at_end_row = xpos == tm.x2pos(pit(), next_row, tm.width());
|
|
|
|
bool const at_beg_row = xpos == tm.x2pos(pit(), next_row, 0);
|
|
|
|
|
|
|
|
if (at_end_row && at_beg_row)
|
|
|
|
// make sure the cursor ends up on this row
|
|
|
|
boundary(false);
|
|
|
|
else
|
|
|
|
boundary(at_end_row);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::message(docstring const & msg) const
|
2004-02-03 11:49:05 +00:00
|
|
|
{
|
2010-01-29 11:22:33 +00:00
|
|
|
disp_.setMessage(msg);
|
2004-02-03 11:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::errorMessage(docstring const & msg) const
|
2004-02-03 11:49:05 +00:00
|
|
|
{
|
2010-01-29 11:22:33 +00:00
|
|
|
disp_.setMessage(msg);
|
|
|
|
disp_.setError(true);
|
2004-02-03 11:49:05 +00:00
|
|
|
}
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
|
|
|
2010-11-06 15:06:19 +00:00
|
|
|
namespace {
|
|
|
|
docstring parbreak(Cursor const * cur)
|
2009-08-09 14:33:35 +00:00
|
|
|
{
|
|
|
|
odocstringstream os;
|
|
|
|
os << '\n';
|
2010-11-06 15:06:19 +00:00
|
|
|
// only add blank line if we're not in a ParbreakIsNewline situation
|
|
|
|
if (!cur->inset().getLayout().parbreakIsNewline()
|
|
|
|
&& !cur->paragraph().layout().parbreak_is_newline)
|
2009-08-09 14:33:35 +00:00
|
|
|
os << '\n';
|
|
|
|
return os.str();
|
|
|
|
}
|
2010-11-06 15:06:19 +00:00
|
|
|
}
|
2009-08-09 14:33:35 +00:00
|
|
|
|
|
|
|
|
2008-05-22 14:01:33 +00:00
|
|
|
docstring Cursor::selectionAsString(bool with_label) const
|
2004-02-11 14:45:44 +00:00
|
|
|
{
|
|
|
|
if (!selection())
|
2006-09-03 07:02:38 +00:00
|
|
|
return docstring();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
2009-08-09 14:38:54 +00:00
|
|
|
if (inMathed())
|
|
|
|
return cap::grabSelection(*this);
|
|
|
|
|
2008-05-22 14:01:33 +00:00
|
|
|
int const label = with_label
|
|
|
|
? AS_STR_LABEL | AS_STR_INSETS : AS_STR_INSETS;
|
|
|
|
|
2009-08-09 14:38:54 +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);
|
|
|
|
}
|
2004-02-11 14:45:44 +00:00
|
|
|
|
2009-08-09 14:38:54 +00:00
|
|
|
ParagraphList const & pars = text()->paragraphs();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
2009-08-09 14:38:54 +00:00
|
|
|
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)
|
2010-11-06 15:06:19 +00:00
|
|
|
+ parbreak(this);
|
2009-08-09 14:38:54 +00:00
|
|
|
|
|
|
|
// 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)
|
2010-11-06 15:06:19 +00:00
|
|
|
+ parbreak(this);
|
2004-02-11 14:45:44 +00:00
|
|
|
}
|
|
|
|
|
2009-08-09 14:38:54 +00:00
|
|
|
// Last paragraph in selection
|
|
|
|
result += pars[endpit].asString(0, endpos, label);
|
2005-10-12 18:44:53 +00:00
|
|
|
|
2009-08-09 14:38:54 +00:00
|
|
|
return result;
|
2004-02-11 14:45:44 +00:00
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
|
|
|
|
2008-08-13 13:46:19 +00:00
|
|
|
docstring Cursor::currentState() const
|
2004-02-13 07:30:59 +00:00
|
|
|
{
|
|
|
|
if (inMathed()) {
|
2006-10-22 10:15:23 +00:00
|
|
|
odocstringstream os;
|
2004-02-13 07:30:59 +00:00
|
|
|
info(os);
|
2006-12-21 13:58:28 +00:00
|
|
|
return os.str();
|
2004-02-13 07:30:59 +00:00
|
|
|
}
|
2004-03-18 12:53:43 +00:00
|
|
|
|
|
|
|
if (inTexted())
|
2005-02-08 13:18:05 +00:00
|
|
|
return text()->currentState(*this);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
2006-12-21 13:58:28 +00:00
|
|
|
return docstring();
|
2004-02-13 07:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 13:46:19 +00:00
|
|
|
docstring Cursor::getPossibleLabel() const
|
2004-02-13 13:51:12 +00:00
|
|
|
{
|
2006-11-11 11:27:47 +00:00
|
|
|
return inMathed() ? from_ascii("eq:") : text()->getPossibleLabel(*this);
|
2004-02-13 13:51:12 +00:00
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
Encoding const * Cursor::getEncoding() const
|
2004-02-16 11:58:51 +00:00
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
if (empty())
|
|
|
|
return 0;
|
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-04-29 18:17:15 +00:00
|
|
|
Font font = text.getPar(sl.pit()).getFont(
|
2009-08-09 18:35:39 +00:00
|
|
|
bv().buffer().params(), sl.pos(), text.outerFont(sl.pit()));
|
2004-03-18 12:53:43 +00:00
|
|
|
return font.language()->encoding();
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::undispatched()
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::dispatched()
|
2004-03-27 12:46:30 +00:00
|
|
|
{
|
|
|
|
disp_.dispatched(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-08 20:04:35 +00:00
|
|
|
void Cursor::screenUpdateFlags(Update::flags f)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-09 14:37:00 +00:00
|
|
|
void Cursor::forceBufferUpdate()
|
|
|
|
{
|
|
|
|
disp_.forceBufferUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::clearBufferUpdate()
|
|
|
|
{
|
|
|
|
disp_.clearBufferUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::needBufferUpdate() const
|
|
|
|
{
|
|
|
|
return disp_.needBufferUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-08 20:04:35 +00:00
|
|
|
void Cursor::noScreenUpdate()
|
2004-02-16 11:58:51 +00:00
|
|
|
{
|
2010-10-13 17:28:55 +00:00
|
|
|
disp_.screenUpdate(Update::None);
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
2005-01-10 09:28:06 +00:00
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
Font Cursor::getFont() const
|
2005-01-10 09:28:06 +00:00
|
|
|
{
|
2007-09-02 13:35:48 +00:00
|
|
|
// The logic here should more or less match to the Cursor::setCurrentFont
|
2007-06-07 20:40:01 +00:00
|
|
|
// logic, i.e. the cursor height should give a hint what will happen
|
|
|
|
// if a character is entered.
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
// on boundary, so we are really at the character before
|
|
|
|
pos_type pos = sl.pos();
|
|
|
|
if (pos > 0 && boundary())
|
|
|
|
--pos;
|
|
|
|
|
|
|
|
// 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()
|
2007-09-02 22:28:49 +00:00
|
|
|
|| (par.isSeparator(pos)
|
|
|
|
&& !tm.isRTLBoundary(sl.pit(), pos)))
|
2007-06-07 20:40:01 +00:00
|
|
|
--pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
2007-08-19 13:40:09 +00:00
|
|
|
bool Cursor::fixIfBroken()
|
2005-02-15 17:34:54 +00:00
|
|
|
{
|
2010-01-13 18:57:42 +00:00
|
|
|
bool const broken_cursor = DocIterator::fixIfBroken();
|
|
|
|
bool const broken_anchor = anchor_.fixIfBroken();
|
|
|
|
|
|
|
|
if (broken_cursor || broken_anchor) {
|
|
|
|
clearSelection();
|
|
|
|
return true;
|
2005-02-15 17:34:54 +00:00
|
|
|
}
|
2007-08-19 13:40:09 +00:00
|
|
|
return false;
|
2005-02-15 17:34:54 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
|
|
|
|
bool Cursor::textUndo()
|
|
|
|
{
|
|
|
|
DocIterator dit = *this;
|
|
|
|
// Undo::textUndo() will modify dit.
|
2008-11-17 11:46:07 +00:00
|
|
|
if (!buffer()->undo().textUndo(dit))
|
2007-10-18 11:51:17 +00:00
|
|
|
return false;
|
|
|
|
// Set cursor
|
|
|
|
setCursor(dit);
|
2008-08-13 15:13:37 +00:00
|
|
|
clearSelection();
|
2007-10-18 11:51:17 +00:00
|
|
|
fixIfBroken();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::textRedo()
|
|
|
|
{
|
|
|
|
DocIterator dit = *this;
|
|
|
|
// Undo::textRedo() will modify dit.
|
2008-11-17 11:46:07 +00:00
|
|
|
if (!buffer()->undo().textRedo(dit))
|
2007-10-18 11:51:17 +00:00
|
|
|
return false;
|
|
|
|
// Set cursor
|
|
|
|
setCursor(dit);
|
2008-08-13 15:13:37 +00:00
|
|
|
clearSelection();
|
2007-10-18 11:51:17 +00:00
|
|
|
fixIfBroken();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 13:46:19 +00:00
|
|
|
void Cursor::finishUndo() const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->undo().finishUndo();
|
2007-10-18 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-15 19:24:56 +00:00
|
|
|
void Cursor::beginUndoGroup() const
|
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->undo().beginUndoGroup();
|
2008-08-15 19:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::endUndoGroup() const
|
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->undo().endUndoGroup();
|
2008-08-15 19:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 13:46:19 +00:00
|
|
|
void Cursor::recordUndo(UndoKind kind, pit_type from, pit_type to) const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->undo().recordUndo(*this, kind, from, to);
|
2007-10-18 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 13:46:19 +00:00
|
|
|
void Cursor::recordUndo(UndoKind kind, pit_type from) const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->undo().recordUndo(*this, kind, from);
|
2007-10-18 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 13:46:19 +00:00
|
|
|
void Cursor::recordUndo(UndoKind kind) const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->undo().recordUndo(*this, kind);
|
2007-10-18 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 13:46:19 +00:00
|
|
|
void Cursor::recordUndoInset(UndoKind kind) const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->undo().recordUndoInset(*this, kind);
|
2007-10-18 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 13:46:19 +00:00
|
|
|
void Cursor::recordUndoFullDocument() const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->undo().recordUndoFullDocument(*this);
|
2007-10-18 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 13:46:19 +00:00
|
|
|
void Cursor::recordUndoSelection() const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2008-03-12 00:59:29 +00:00
|
|
|
if (inMathed()) {
|
|
|
|
if (cap::multipleCellsSelected(*this))
|
|
|
|
recordUndoInset();
|
|
|
|
else
|
|
|
|
recordUndo();
|
2008-11-17 11:46:07 +00:00
|
|
|
} else {
|
|
|
|
buffer()->undo().recordUndo(*this, ATOMIC_UNDO,
|
2008-03-12 00:59:29 +00:00
|
|
|
selBegin().pit(), selEnd().pit());
|
2008-11-17 11:46:07 +00:00
|
|
|
}
|
2007-10-18 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-12 21:38:51 +00:00
|
|
|
void Cursor::checkBufferStructure()
|
|
|
|
{
|
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())
|
|
|
|
// In case the master has no gui associated with it,
|
|
|
|
// the TocItem is not updated (part of bug 5699).
|
|
|
|
buffer()->tocBackend().updateItem(*this);
|
2008-01-12 21:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|