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-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
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-05 22:54:53 +00:00
|
|
|
#include "support/docstream.h"
|
2013-04-25 21:27:10 +00:00
|
|
|
#include "support/ExceptionMessage.h"
|
|
|
|
#include "support/gettext.h"
|
|
|
|
#include "support/lassert.h"
|
2007-11-05 22:54:53 +00:00
|
|
|
|
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
|
|
|
// 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();
|
2011-03-23 17:43:13 +00:00
|
|
|
CoordCache const & cache = c.bv().coordCache();
|
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.
|
2011-03-23 17:43:13 +00:00
|
|
|
if (!cache.getInsets().has(inset)) {
|
2007-11-28 22:12:03 +00:00
|
|
|
it.top().pos() = 0;
|
|
|
|
return it;
|
|
|
|
}
|
2004-08-13 19:19:53 +00:00
|
|
|
|
2011-03-23 17:43:13 +00:00
|
|
|
Point const o = cache.getInsets().xy(inset);
|
2007-11-28 22:12:03 +00:00
|
|
|
inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
|
|
|
|
// Convert to absolute
|
|
|
|
xo += o.x_;
|
|
|
|
yo += o.y_;
|
|
|
|
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
|
|
|
|
// '<=' in order to take the last possible position
|
|
|
|
// this is important for clicking behind \sum in e.g. '\sum_i a'
|
|
|
|
LYXERR(Debug::DEBUG, "i: " << i << " d: " << d
|
|
|
|
<< " best: " << best_dist);
|
|
|
|
if (d <= best_dist) {
|
|
|
|
best_dist = d;
|
|
|
|
result = it;
|
|
|
|
}
|
|
|
|
if (it == et)
|
|
|
|
break;
|
|
|
|
it.forwardPos();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/// 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));
|
2015-05-15 22:05:23 +00:00
|
|
|
et.pit() = prev(cache.end(), 1)->first;
|
2007-11-28 22:12:03 +00:00
|
|
|
if (et.pit() >= et.lastpit())
|
|
|
|
et = doc_iterator_end(inset);
|
|
|
|
else
|
|
|
|
++et.pit();
|
|
|
|
|
2010-12-21 15:28:55 +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
|
|
|
|
2013-05-02 17:22:10 +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
|
2012-10-27 13:45:27 +00:00
|
|
|
&& (!cur.selection() || positionable(it, cur.realAnchor()))) {
|
|
|
|
// If this function is ever used again, check
|
|
|
|
// whether this is the same as "bv.getPos(it,
|
|
|
|
// false)" with boundary = false.
|
2010-04-21 13:03:04 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-05-02 17:22:10 +00:00
|
|
|
*/
|
2004-08-13 19:19:53 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
2012-07-15 16:16:09 +00:00
|
|
|
CursorData::CursorData()
|
|
|
|
: DocIterator(), anchor_(),
|
|
|
|
selection_(false), mark_(false), word_selection_(false),
|
2015-03-04 22:00:07 +00:00
|
|
|
logicalpos_(false), current_font(inherit_font),
|
|
|
|
autocorrect_(false), macromode_(false)
|
2012-07-15 16:16:09 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
CursorData::CursorData(Buffer * buffer)
|
|
|
|
: DocIterator(buffer), anchor_(),
|
|
|
|
selection_(false), mark_(false), word_selection_(false),
|
2015-03-04 22:00:07 +00:00
|
|
|
logicalpos_(false), current_font(inherit_font),
|
|
|
|
autocorrect_(false), macromode_(false)
|
2012-07-15 16:16:09 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
CursorData::CursorData(DocIterator const & dit)
|
|
|
|
: DocIterator(dit), anchor_(),
|
|
|
|
selection_(false), mark_(false), word_selection_(false),
|
2015-03-04 22:00:07 +00:00
|
|
|
logicalpos_(false), current_font(inherit_font),
|
|
|
|
autocorrect_(false), macromode_(false)
|
2012-07-15 16:16:09 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2015-03-10 14:53:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
ostream & operator<<(ostream & os, CursorData const & cur)
|
|
|
|
{
|
|
|
|
os << "\n cursor: | anchor:\n";
|
|
|
|
for (size_t i = 0, n = cur.depth(); i != n; ++i) {
|
|
|
|
os << " " << cur[i] << " | ";
|
|
|
|
if (i < cur.anchor_.depth())
|
|
|
|
os << cur.anchor_[i];
|
|
|
|
else
|
|
|
|
os << "-------------------------------";
|
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
|
|
|
|
os << "------------------------------- | " << cur.anchor_[i] << "\n";
|
|
|
|
}
|
|
|
|
os << " selection: " << cur.selection_
|
|
|
|
// << " x_target: " << cur.x_target_
|
|
|
|
<< " boundary: " << cur.boundary() << endl;
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXErr & operator<<(LyXErr & os, CursorData const & cur)
|
|
|
|
{
|
|
|
|
os.stream() << cur;
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-03 16:39:59 +00:00
|
|
|
// be careful: this is called from the bv's constructor, too, so
|
2004-11-30 01:59:49 +00:00
|
|
|
// bv functions are not yet available!
|
2007-04-26 14:56:30 +00:00
|
|
|
Cursor::Cursor(BufferView & bv)
|
2014-03-14 13:22:26 +00:00
|
|
|
: CursorData(&bv.buffer()), bv_(&bv),
|
2015-03-04 22:00:07 +00:00
|
|
|
x_target_(-1), textTargetOffset_(0),
|
|
|
|
beforeDispatchPosX_(0), beforeDispatchPosY_(0)
|
2003-11-10 09:06:48 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2009-10-29 22:46:04 +00:00
|
|
|
void Cursor::reset()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
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();
|
2012-12-11 09:14:47 +00:00
|
|
|
new_word_ = doc_iterator_begin(buffer());
|
|
|
|
new_word_.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
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-15 16:16:09 +00:00
|
|
|
void Cursor::setCursorToAnchor()
|
|
|
|
{
|
|
|
|
if (selection()) {
|
|
|
|
DocIterator normal = anchor_;
|
|
|
|
while (depth() < normal.depth())
|
|
|
|
normal.pop_back();
|
|
|
|
if (depth() < anchor_.depth() && top() <= anchor_[depth() - 1])
|
|
|
|
++normal.pos();
|
|
|
|
setCursor(normal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::setCursorData(CursorData const & data)
|
|
|
|
{
|
|
|
|
CursorData::operator=(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-13 14:32:51 +00:00
|
|
|
bool Cursor::getStatus(FuncRequest const & cmd, FuncStatus & status) const
|
|
|
|
{
|
|
|
|
Cursor cur = *this;
|
|
|
|
|
|
|
|
// Try to fix cursor in case it is broken.
|
|
|
|
cur.fixIfBroken();
|
|
|
|
|
|
|
|
// Is this a function that acts on inset at point?
|
|
|
|
Inset * inset = cur.nextInset();
|
2010-04-09 19:00:42 +00:00
|
|
|
if (lyxaction.funcHasFlag(cmd.action(), LyXAction::AtPoint)
|
2009-11-13 14:32:51 +00:00
|
|
|
&& inset && inset->getStatus(cur, cmd, status))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// This is, of course, a mess. Better create a new doc iterator and use
|
|
|
|
// this in Inset::getStatus. This might require an additional
|
|
|
|
// BufferView * arg, though (which should be avoided)
|
|
|
|
//Cursor safe = *this;
|
|
|
|
bool res = false;
|
|
|
|
for ( ; cur.depth(); cur.pop()) {
|
|
|
|
//lyxerr << "\nCursor::getStatus: cmd: " << cmd << endl << *this << endl;
|
2013-04-25 21:27:10 +00:00
|
|
|
// LASSERT: Is it safe to continue here, or should we return?
|
2009-11-13 14:32:51 +00:00
|
|
|
LASSERT(cur.idx() <= cur.lastidx(), /**/);
|
|
|
|
LASSERT(cur.pit() <= cur.lastpit(), /**/);
|
|
|
|
LASSERT(cur.pos() <= cur.lastpos(), /**/);
|
|
|
|
|
|
|
|
// The inset's getStatus() will return 'true' if it made
|
|
|
|
// a definitive decision on whether it want to handle the
|
|
|
|
// request or not. The result of this decision is put into
|
|
|
|
// the 'status' parameter.
|
|
|
|
if (cur.inset().getStatus(cur, cmd, status)) {
|
|
|
|
res = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-09 14:29:27 +00:00
|
|
|
void Cursor::saveBeforeDispatchPosXY()
|
|
|
|
{
|
|
|
|
getPos(beforeDispatchPosX_, beforeDispatchPosY_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::dispatch(FuncRequest const & cmd0)
|
2003-09-17 16:44:51 +00:00
|
|
|
{
|
2015-07-08 08:57:04 +00:00
|
|
|
LYXERR(Debug::ACTION, "Cursor::dispatch: cmd: " << cmd0 << '\n' << *this);
|
2004-03-18 12:53:43 +00:00
|
|
|
if (empty())
|
2004-08-13 14:56:06 +00:00
|
|
|
return;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
2005-02-15 17:34:54 +00:00
|
|
|
fixIfBroken();
|
2003-11-10 09:06:48 +00:00
|
|
|
FuncRequest cmd = cmd0;
|
2007-04-26 14:56:30 +00:00
|
|
|
Cursor safe = *this;
|
2010-12-05 00:57:04 +00:00
|
|
|
Cursor old = *this;
|
2010-10-17 12:06:47 +00:00
|
|
|
disp_ = DispatchResult();
|
2009-10-03 19:12:21 +00:00
|
|
|
|
2012-02-07 14:56:16 +00:00
|
|
|
beginUndoGroup();
|
2010-11-29 09:47:46 +00:00
|
|
|
|
2009-11-13 14:32:51 +00:00
|
|
|
// Is this a function that acts on inset at point?
|
2010-04-09 19:00:42 +00:00
|
|
|
if (lyxaction.funcHasFlag(cmd.action(), LyXAction::AtPoint)
|
2009-11-13 14:32:51 +00:00
|
|
|
&& nextInset()) {
|
2010-04-15 17:14:59 +00:00
|
|
|
disp_.dispatched(true);
|
2010-10-13 17:28:55 +00:00
|
|
|
disp_.screenUpdate(Update::FitCursor | Update::Force);
|
2009-11-13 14:32:51 +00:00
|
|
|
FuncRequest tmpcmd = cmd;
|
|
|
|
LYXERR(Debug::DEBUG, "Cursor::dispatch: (AtPoint) cmd: "
|
|
|
|
<< cmd0 << endl << *this);
|
|
|
|
nextInset()->dispatch(*this, tmpcmd);
|
2010-04-15 17:14:59 +00:00
|
|
|
if (disp_.dispatched()) {
|
2012-02-07 14:56:16 +00:00
|
|
|
endUndoGroup();
|
2009-11-13 14:32:51 +00:00
|
|
|
return;
|
2010-01-21 16:59:39 +00:00
|
|
|
}
|
2009-11-13 14:32:51 +00:00
|
|
|
}
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// store some values to be used inside of the handlers
|
2007-06-14 20:32:28 +00:00
|
|
|
beforeDispatchCursor_ = *this;
|
2008-02-29 08:27:22 +00:00
|
|
|
for (; depth(); pop(), boundary(false)) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "Cursor::dispatch: cmd: "
|
|
|
|
<< cmd0 << endl << *this);
|
2014-02-16 01:53:03 +00:00
|
|
|
|
|
|
|
// In any of these cases, the cursor is invalid, and we should
|
|
|
|
// try to save this document rather than crash.
|
|
|
|
LBUFERR(pos() <= lastpos());
|
|
|
|
LBUFERR(idx() <= lastidx());
|
|
|
|
LBUFERR(pit() <= lastpit());
|
2004-03-18 12:53:43 +00:00
|
|
|
|
2004-04-03 08:37:12 +00:00
|
|
|
// The common case is 'LFUN handled, need update', so make the
|
2004-03-18 12:53:43 +00:00
|
|
|
// LFUN handler's life easier by assuming this as default value.
|
|
|
|
// The handler can reset the update and val flags if necessary.
|
2010-10-13 17:28:55 +00:00
|
|
|
disp_.screenUpdate(Update::FitCursor | Update::Force);
|
2004-03-18 12:53:43 +00:00
|
|
|
disp_.dispatched(true);
|
|
|
|
inset().dispatch(*this, cmd);
|
|
|
|
if (disp_.dispatched())
|
|
|
|
break;
|
2003-09-17 16:44:51 +00:00
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
// it completely to get a 'bomb early' behaviour in case this
|
|
|
|
// object will be used again.
|
2004-03-25 09:16:36 +00:00
|
|
|
if (!disp_.dispatched()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "RESTORING OLD CURSOR!");
|
2009-04-15 20:20:42 +00:00
|
|
|
// We might have invalidated the cursor when removing an empty
|
|
|
|
// paragraph while the cursor could not be moved out the inset
|
|
|
|
// while we initially thought we could. This might happen when
|
2014-03-14 13:22:26 +00:00
|
|
|
// a multiline inset becomes an inline inset when the second
|
2009-04-15 20:20:42 +00:00
|
|
|
// paragraph is removed.
|
|
|
|
if (safe.pit() > safe.lastpit()) {
|
|
|
|
safe.pit() = safe.lastpit();
|
|
|
|
safe.pos() = safe.lastpos();
|
|
|
|
}
|
2004-03-18 13:57:20 +00:00
|
|
|
operator=(safe);
|
2010-10-13 17:28:55 +00:00
|
|
|
disp_.screenUpdate(Update::None);
|
2004-04-07 20:20:15 +00:00
|
|
|
disp_.dispatched(false);
|
2007-06-14 20:32:28 +00:00
|
|
|
} else {
|
|
|
|
// restore the previous one because nested Cursor::dispatch calls
|
|
|
|
// are possible which would change it
|
|
|
|
beforeDispatchCursor_ = safe.beforeDispatchCursor_;
|
2004-03-25 09:16:36 +00:00
|
|
|
}
|
2012-02-07 14:56:16 +00:00
|
|
|
endUndoGroup();
|
2010-12-05 00:57:04 +00:00
|
|
|
|
2015-06-05 09:43:05 +00:00
|
|
|
// NOTE: The code below has been copied to BufferView::dispatch.
|
|
|
|
// If you need to modify this, please update the other one too.
|
|
|
|
|
2010-12-05 00:57:04 +00:00
|
|
|
// notify insets we just left
|
|
|
|
if (*this != old) {
|
|
|
|
old.beginUndoGroup();
|
|
|
|
old.fixIfBroken();
|
|
|
|
bool badcursor = notifyCursorLeavesOrEnters(old, *this);
|
|
|
|
if (badcursor) {
|
|
|
|
fixIfBroken();
|
2011-02-21 15:26:28 +00:00
|
|
|
bv().resetInlineCompletionPos();
|
2010-12-05 00:57:04 +00:00
|
|
|
}
|
|
|
|
old.endUndoGroup();
|
|
|
|
}
|
2004-08-13 14:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-15 17:14:59 +00:00
|
|
|
DispatchResult const & Cursor::result() const
|
2004-08-13 14:56:06 +00:00
|
|
|
{
|
2004-02-16 11:58:51 +00:00
|
|
|
return disp_;
|
2003-09-17 16:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
BufferView & Cursor::bv() const
|
2003-11-06 10:30:43 +00:00
|
|
|
{
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(bv_);
|
2004-03-18 12:53:43 +00:00
|
|
|
return *bv_;
|
2004-03-11 17:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::pop()
|
2003-11-04 12:36:59 +00:00
|
|
|
{
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(depth() >= 1);
|
2004-03-01 17:12:09 +00:00
|
|
|
pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(!empty(), return Inset::UNDECIDED_MODE);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-04 22:26:16 +00:00
|
|
|
bool Cursor::inCoordCache() const
|
|
|
|
{
|
2016-03-11 14:13:05 +00:00
|
|
|
// the root inset is not in cache, but we do not need it.
|
|
|
|
if (depth() == 1)
|
|
|
|
return true;
|
2015-12-04 22:26:16 +00:00
|
|
|
CoordCache::Insets const & icache = bv_->coordCache().getInsets();
|
2016-03-11 14:13:05 +00:00
|
|
|
for (size_t i = 1 ; i < depth() ; ++i)
|
2015-12-04 22:26:16 +00:00
|
|
|
if (!icache.has(&(*this)[i].inset()))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::getPos(int & x, int & y) const
|
2003-11-10 09:06:48 +00:00
|
|
|
{
|
2010-04-21 13:03:04 +00:00
|
|
|
Point p = bv().getPos(*this);
|
2004-11-30 01:59:49 +00:00
|
|
|
x = p.x_;
|
|
|
|
y = p.y_;
|
2003-11-10 09:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
Row const & Cursor::textRow() const
|
2006-12-19 13:39:46 +00:00
|
|
|
{
|
2007-12-22 09:25:59 +00:00
|
|
|
CursorSlice const & cs = innerTextSlice();
|
|
|
|
ParagraphMetrics const & pm = bv().parMetrics(cs.text(), cs.pit());
|
2006-12-29 23:54:48 +00:00
|
|
|
return pm.getRow(pos(), boundary());
|
2006-12-19 13:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2011-02-03 17:27:13 +00:00
|
|
|
checkNewWordPosition();
|
2004-01-16 13:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-01 05:49:04 +00:00
|
|
|
void Cursor::markNewWordPosition()
|
2011-02-03 17:27:13 +00:00
|
|
|
{
|
2011-03-10 20:15:34 +00:00
|
|
|
if (lyxrc.spellcheck_continuously && inTexted() && new_word_.empty()) {
|
2011-04-01 05:49:04 +00:00
|
|
|
FontSpan nw = locateWord(WHOLE_WORD);
|
|
|
|
if (nw.size() == 1) {
|
2011-02-03 17:27:13 +00:00
|
|
|
LYXERR(Debug::DEBUG, "start new word: "
|
|
|
|
<< " par: " << pit()
|
2011-04-01 05:49:04 +00:00
|
|
|
<< " pos: " << nw.first);
|
2011-02-03 17:27:13 +00:00
|
|
|
new_word_ = *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::clearNewWordPosition()
|
|
|
|
{
|
|
|
|
if (!new_word_.empty()) {
|
|
|
|
LYXERR(Debug::DEBUG, "clear new word: "
|
|
|
|
<< " par: " << pit()
|
|
|
|
<< " pos: " << pos());
|
|
|
|
new_word_.resize(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::checkNewWordPosition()
|
|
|
|
{
|
2011-03-10 20:15:34 +00:00
|
|
|
if (!lyxrc.spellcheck_continuously || new_word_.empty())
|
2011-02-03 17:27:13 +00:00
|
|
|
return ;
|
|
|
|
if (!inTexted())
|
|
|
|
clearNewWordPosition();
|
|
|
|
else {
|
2011-03-15 10:27:41 +00:00
|
|
|
// forget the position of the current new word if
|
2011-03-10 20:15:34 +00:00
|
|
|
// 1) the paragraph changes or
|
2011-03-15 10:27:41 +00:00
|
|
|
// 2) the count of nested insets changes or
|
|
|
|
// 3) the cursor pos is out of paragraph bound
|
|
|
|
if (pit() != new_word_.pit() ||
|
|
|
|
depth() != new_word_.depth() ||
|
|
|
|
new_word_.pos() > new_word_.lastpos()) {
|
|
|
|
clearNewWordPosition();
|
|
|
|
} else if (new_word_.fixIfBroken())
|
|
|
|
// 4) or the remembered position was "broken"
|
2011-02-03 17:27:13 +00:00
|
|
|
clearNewWordPosition();
|
|
|
|
else {
|
|
|
|
FontSpan nw = locateWord(WHOLE_WORD);
|
2012-10-21 19:14:16 +00:00
|
|
|
if (!nw.empty()) {
|
2011-02-08 09:42:00 +00:00
|
|
|
FontSpan ow = new_word_.locateWord(WHOLE_WORD);
|
|
|
|
if (nw.intersect(ow).empty())
|
|
|
|
clearNewWordPosition();
|
|
|
|
else
|
|
|
|
LYXERR(Debug::DEBUG, "new word: "
|
|
|
|
<< " par: " << pit()
|
|
|
|
<< " pos: " << nw.first << ".." << nw.last);
|
|
|
|
} else {
|
2011-02-03 17:27:13 +00:00
|
|
|
clearNewWordPosition();
|
2011-02-08 09:42:00 +00:00
|
|
|
}
|
2011-02-03 17:27:13 +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
|
|
|
|
|
|
|
|
getSurroundingPos(left_pos, right_pos);
|
|
|
|
|
|
|
|
LYXERR(Debug::RTL, left_pos <<"|"<< right_pos << " (pos: "<< pos() <<")");
|
|
|
|
|
|
|
|
// Are we at an inset?
|
|
|
|
new_cur.pos() = right_pos;
|
|
|
|
new_cur.boundary(false);
|
|
|
|
if (!skip_inset &&
|
2008-08-13 19:58:00 +00:00
|
|
|
text()->checkAndActivateInsetVisual(new_cur, right_pos >= pos(), false)) {
|
2012-10-27 13:45:27 +00:00
|
|
|
// we actually move the cursor at the end of this
|
|
|
|
// function, for now we just keep track of the new
|
|
|
|
// position in new_cur...
|
2008-05-04 20:17:59 +00:00
|
|
|
LYXERR(Debug::RTL, "entering inset at: " << new_cur.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we already at rightmost pos in row?
|
|
|
|
else if (text()->empty() || right_pos == -1) {
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
new_cur = *this;
|
|
|
|
if (!new_cur.posVisToNewRow(false)) {
|
|
|
|
LYXERR(Debug::RTL, "not moving!");
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
// we actually move the cursor at the end of this
|
|
|
|
// function, for now just keep track of the new
|
|
|
|
// position in new_cur...
|
2014-03-14 13:22:26 +00:00
|
|
|
LYXERR(Debug::RTL, "right edge, moving: " << int(new_cur.pit()) << ","
|
2008-05-04 20:17:59 +00:00
|
|
|
<< int(new_cur.pos()) << "," << (new_cur.boundary() ? 1 : 0));
|
|
|
|
|
|
|
|
}
|
|
|
|
// normal movement to the right
|
|
|
|
else {
|
|
|
|
new_cur = *this;
|
2012-10-27 13:45:27 +00:00
|
|
|
// Recall, if the cursor is at position 'x', that
|
|
|
|
// means *before* the character at position 'x'. In
|
|
|
|
// RTL, "before" means "to the right of", in LTR, "to
|
|
|
|
// the left of". So currently our situation is this:
|
|
|
|
// the position to our right is 'right_pos' (i.e.,
|
|
|
|
// we're currently to the left of 'right_pos'). In
|
|
|
|
// order to move to the right, it depends whether or
|
|
|
|
// not the character at 'right_pos' is RTL.
|
2014-04-04 19:54:32 +00:00
|
|
|
bool const new_pos_is_RTL = paragraph().getFontSettings(
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->params(), right_pos).isVisibleRightToLeft();
|
2012-10-27 13:45:27 +00:00
|
|
|
// If the character at 'right_pos' *is* LTR, then in
|
|
|
|
// order to move to the right of it, we need to be
|
|
|
|
// *after* 'right_pos', i.e., move to position
|
|
|
|
// 'right_pos' + 1.
|
2008-05-04 20:17:59 +00:00
|
|
|
if (!new_pos_is_RTL) {
|
|
|
|
new_cur.pos() = right_pos + 1;
|
|
|
|
// set the boundary to true in two situations:
|
|
|
|
if (
|
2012-10-27 13:45:27 +00:00
|
|
|
// 1. if new_pos is now lastpos, and we're in
|
|
|
|
// an RTL paragraph (this means that we're
|
|
|
|
// moving right to the end of an LTR chunk
|
2008-11-01 17:00:58 +00:00
|
|
|
// which is at the end of an RTL paragraph);
|
|
|
|
(new_cur.pos() == lastpos()
|
2008-11-17 11:46:07 +00:00
|
|
|
&& paragraph().isRTL(buffer()->params()))
|
2012-10-27 13:45:27 +00:00
|
|
|
// 2. if the position *after* right_pos is RTL
|
|
|
|
// (we want to be *after* right_pos, not
|
|
|
|
// before right_pos + 1!)
|
2008-11-17 11:46:07 +00:00
|
|
|
|| paragraph().getFontSettings(buffer()->params(),
|
2008-05-04 20:17:59 +00:00
|
|
|
new_cur.pos()).isVisibleRightToLeft()
|
|
|
|
)
|
|
|
|
new_cur.boundary(true);
|
|
|
|
else // set the boundary to false
|
|
|
|
new_cur.boundary(false);
|
|
|
|
}
|
2012-10-27 13:45:27 +00:00
|
|
|
// Otherwise (if the character at position 'right_pos'
|
|
|
|
// is RTL), then moving to the right of it is as easy
|
|
|
|
// as setting the new position to 'right_pos'.
|
2008-05-04 20:17:59 +00:00
|
|
|
else {
|
|
|
|
new_cur.pos() = right_pos;
|
|
|
|
new_cur.boundary(false);
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 09:10:26 +00:00
|
|
|
bool const moved = new_cur != *this || new_cur.boundary() != boundary();
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
if (moved) {
|
2014-03-14 13:22:26 +00:00
|
|
|
LYXERR(Debug::RTL, "moving to: " << new_cur.pos()
|
2008-05-04 20:17:59 +00:00
|
|
|
<< (new_cur.boundary() ? " (boundary)" : ""));
|
|
|
|
*this = new_cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
return moved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::posVisLeft(bool skip_inset)
|
|
|
|
{
|
|
|
|
Cursor new_cur = *this; // where we will move to
|
|
|
|
pos_type left_pos; // position visually left of current cursor
|
|
|
|
pos_type right_pos; // position visually right of current cursor
|
|
|
|
|
|
|
|
getSurroundingPos(left_pos, right_pos);
|
|
|
|
|
|
|
|
LYXERR(Debug::RTL, left_pos <<"|"<< right_pos << " (pos: "<< pos() <<")");
|
|
|
|
|
|
|
|
// Are we at an inset?
|
|
|
|
new_cur.pos() = left_pos;
|
|
|
|
new_cur.boundary(false);
|
2014-03-14 13:22:26 +00:00
|
|
|
if (!skip_inset &&
|
2008-05-04 20:17:59 +00:00
|
|
|
text()->checkAndActivateInsetVisual(new_cur, left_pos >= pos(), true)) {
|
2012-10-27 13:45:27 +00:00
|
|
|
// we actually move the cursor at the end of this
|
|
|
|
// function, for now we just keep track of the new
|
|
|
|
// position in new_cur...
|
2008-05-04 20:17:59 +00:00
|
|
|
LYXERR(Debug::RTL, "entering inset at: " << new_cur.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we already at leftmost pos in row?
|
|
|
|
else if (text()->empty() || left_pos == -1) {
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
new_cur = *this;
|
|
|
|
if (!new_cur.posVisToNewRow(true)) {
|
|
|
|
LYXERR(Debug::RTL, "not moving!");
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
// we actually move the cursor at the end of this
|
|
|
|
// function, for now just keep track of the new
|
|
|
|
// position in new_cur...
|
2014-03-14 13:22:26 +00:00
|
|
|
LYXERR(Debug::RTL, "left edge, moving: " << int(new_cur.pit()) << ","
|
2008-05-04 20:17:59 +00:00
|
|
|
<< int(new_cur.pos()) << "," << (new_cur.boundary() ? 1 : 0));
|
|
|
|
|
|
|
|
}
|
|
|
|
// normal movement to the left
|
|
|
|
else {
|
|
|
|
new_cur = *this;
|
2012-10-27 13:45:27 +00:00
|
|
|
// Recall, if the cursor is at position 'x', that
|
|
|
|
// means *before* the character at position 'x'. In
|
|
|
|
// RTL, "before" means "to the right of", in LTR, "to
|
|
|
|
// the left of". So currently our situation is this:
|
|
|
|
// the position to our left is 'left_pos' (i.e., we're
|
|
|
|
// currently to the right of 'left_pos'). In order to
|
|
|
|
// move to the left, it depends whether or not the
|
|
|
|
// character at 'left_pos' is RTL.
|
2014-04-04 19:54:32 +00:00
|
|
|
bool const new_pos_is_RTL = paragraph().getFontSettings(
|
2008-11-17 11:46:07 +00:00
|
|
|
buffer()->params(), left_pos).isVisibleRightToLeft();
|
2012-10-27 13:45:27 +00:00
|
|
|
// If the character at 'left_pos' *is* RTL, then in
|
|
|
|
// order to move to the left of it, we need to be
|
|
|
|
// *after* 'left_pos', i.e., move to position
|
|
|
|
// 'left_pos' + 1.
|
2008-05-04 20:17:59 +00:00
|
|
|
if (new_pos_is_RTL) {
|
|
|
|
new_cur.pos() = left_pos + 1;
|
|
|
|
// set the boundary to true in two situations:
|
|
|
|
if (
|
2012-10-27 13:45:27 +00:00
|
|
|
// 1. if new_pos is now lastpos and we're in
|
|
|
|
// an LTR paragraph (this means that we're
|
|
|
|
// moving left to the end of an RTL chunk
|
2008-11-01 17:00:58 +00:00
|
|
|
// which is at the end of an LTR paragraph);
|
|
|
|
(new_cur.pos() == lastpos()
|
2008-11-17 11:46:07 +00:00
|
|
|
&& !paragraph().isRTL(buffer()->params()))
|
2012-10-27 13:45:27 +00:00
|
|
|
// 2. if the position *after* left_pos is not
|
|
|
|
// RTL (we want to be *after* left_pos, not
|
|
|
|
// before left_pos + 1!)
|
2008-11-17 11:46:07 +00:00
|
|
|
|| !paragraph().getFontSettings(buffer()->params(),
|
2008-05-04 20:17:59 +00:00
|
|
|
new_cur.pos()).isVisibleRightToLeft()
|
|
|
|
)
|
|
|
|
new_cur.boundary(true);
|
|
|
|
else // set the boundary to false
|
|
|
|
new_cur.boundary(false);
|
|
|
|
}
|
2012-10-27 13:45:27 +00:00
|
|
|
// Otherwise (if the character at position 'left_pos'
|
|
|
|
// is LTR), then moving to the left of it is as easy
|
|
|
|
// as setting the new position to 'left_pos'.
|
2008-05-04 20:17:59 +00:00
|
|
|
else {
|
|
|
|
new_cur.pos() = left_pos;
|
|
|
|
new_cur.boundary(false);
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 09:10:26 +00:00
|
|
|
bool const moved = new_cur != *this || new_cur.boundary() != boundary();
|
2008-05-04 20:17:59 +00:00
|
|
|
|
|
|
|
if (moved) {
|
2014-03-14 13:22:26 +00:00
|
|
|
LYXERR(Debug::RTL, "moving to: " << new_cur.pos()
|
2008-05-04 20:17:59 +00:00
|
|
|
<< (new_cur.boundary() ? " (boundary)" : ""));
|
|
|
|
*this = new_cur;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-05-04 20:17:59 +00:00
|
|
|
return moved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-14 20:13:39 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Return true on success
|
|
|
|
bool findNonVirtual(Row const & row, Row::const_iterator & cit, bool onleft)
|
|
|
|
{
|
|
|
|
if (onleft) {
|
|
|
|
while (cit != row.begin() && cit->isVirtual())
|
|
|
|
--cit;
|
|
|
|
} else {
|
|
|
|
while (cit != row.end() && cit->isVirtual())
|
|
|
|
++cit;
|
|
|
|
}
|
|
|
|
return cit != row.end() && !cit->isVirtual();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-09 13:10:39 +00:00
|
|
|
void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos) const
|
2015-09-14 20:13:39 +00:00
|
|
|
{
|
|
|
|
// by default, we know nothing.
|
|
|
|
left_pos = -1;
|
|
|
|
right_pos = -1;
|
|
|
|
|
|
|
|
Row const & row = textRow();
|
|
|
|
TextMetrics const & tm = bv_->textMetrics(text());
|
|
|
|
double dummy = 0;
|
|
|
|
Row::const_iterator cit = tm.findRowElement(row, pos(), boundary(), dummy);
|
|
|
|
// Handle the case of empty row
|
|
|
|
if (cit == row.end()) {
|
|
|
|
if (paragraph().isRTL(buffer()->params()))
|
|
|
|
right_pos = row.pos();
|
|
|
|
else
|
|
|
|
left_pos = row.pos() - 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip virtual elements and exit if no non-virtual one exists
|
|
|
|
if (!findNonVirtual(row, cit, !cit->isRTL()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if the position is at the left side of the element, we have to
|
|
|
|
// look at the previous element
|
|
|
|
if (pos() == cit->left_pos()) {
|
|
|
|
LYXERR(Debug::RTL, "getSurroundingPos(" << pos() << (boundary() ? "b" : "")
|
|
|
|
<< "), AT LEFT of *cit=" << *cit);
|
|
|
|
// this one is easy (see common case below)
|
|
|
|
right_pos = pos() - (cit->isRTL() ? 1 : 0);
|
|
|
|
// at the left of the row
|
|
|
|
if (cit == row.begin())
|
|
|
|
return;
|
|
|
|
--cit;
|
|
|
|
if (!findNonVirtual(row, cit, true))
|
|
|
|
return;
|
|
|
|
// [...[ is the row element, | is cursor position (! with boundary)
|
|
|
|
// [ 1 2 [ is a ltr row element with pos=1 and endpos=3
|
|
|
|
// ] 2 1] is an rtl row element with pos=1 and endpos=3
|
|
|
|
// [ 1 2 [ [|3 4 [ => (2, 3)
|
|
|
|
// or [ 1 2 [ ]!4 3 ] => (2, 4)
|
|
|
|
// or ] 2 1 ] [|3 4 [ => (1, 3)
|
|
|
|
// or ] 4 3 ] ]!2 1 ] => (3, 2)
|
|
|
|
left_pos = cit->right_pos() - (cit->isRTL() ? 0 : 1);
|
|
|
|
// happens with consecutive row of same direction
|
|
|
|
if (left_pos == right_pos) {
|
|
|
|
left_pos += cit->isRTL() ? 1 : -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// same code but with the element at the right
|
|
|
|
else if (pos() == cit->right_pos()) {
|
|
|
|
LYXERR(Debug::RTL, "getSurroundingPos(" << pos() << (boundary() ? "b" : "")
|
|
|
|
<< "), AT RIGHT of *cit=" << *cit);
|
|
|
|
// this one is easy (see common case below)
|
|
|
|
left_pos = pos() - (cit->isRTL() ? 0 : 1);
|
|
|
|
// at the right of the row
|
|
|
|
if (cit + 1 == row.end())
|
|
|
|
return;
|
|
|
|
++cit;
|
|
|
|
if (!findNonVirtual(row, cit, false))
|
|
|
|
return;
|
|
|
|
// [ 1 2![ [ 3 4 [ => (2, 3)
|
|
|
|
// or [ 1 2![ ] 4 3 ] => (2, 4)
|
|
|
|
// or ] 2 1|] [ 3 4 [ => (1, 3)
|
|
|
|
// or ] 4 3|] ] 2 1 ] => (3, 2)
|
|
|
|
right_pos = cit->left_pos() - (cit->isRTL() ? 1 : 0);
|
|
|
|
// happens with consecutive row of same direction
|
|
|
|
if (right_pos == left_pos)
|
|
|
|
right_pos += cit->isRTL() ? -1 : 1;
|
|
|
|
}
|
|
|
|
// common case: both positions are inside the row element
|
|
|
|
else {
|
|
|
|
// [ 1 2|3 [ => (2, 3)
|
|
|
|
// or ] 3|2 1 ] => (3, 2)
|
|
|
|
left_pos = pos() - (cit->isRTL() ? 0 : 1);
|
|
|
|
right_pos = pos() - (cit->isRTL() ? 1 : 0);
|
|
|
|
}
|
2008-02-10 19:52:45 +00:00
|
|
|
|
2015-10-09 13:10:39 +00:00
|
|
|
// Note that debug message does not catch all early returns above
|
2015-09-14 20:13:39 +00:00
|
|
|
LYXERR(Debug::RTL,"getSurroundingPos(" << pos() << (boundary() ? "b" : "")
|
|
|
|
<< ") => (" << left_pos << ", " << right_pos <<")");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-10 19:52:45 +00:00
|
|
|
bool Cursor::posVisToNewRow(bool movingLeft)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
// Inside a table, determining whether to move to the next or
|
|
|
|
// previous row should be done based on the table's direction.
|
2015-10-09 13:48:59 +00:00
|
|
|
if (inset().asInsetTabular()) {
|
|
|
|
par_is_LTR = !inset().asInsetTabular()->isRightToLeft(*this);
|
2008-04-11 12:02:10 +00:00
|
|
|
LYXERR(Debug::RTL, "Inside table! par_is_LTR=" << (par_is_LTR ? 1 : 0));
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
// if moving left in an LTR paragraph or moving right in an
|
|
|
|
// RTL one, move to previous row
|
2008-02-10 19:52:45 +00:00
|
|
|
if (par_is_LTR == movingLeft) {
|
|
|
|
if (row.pos() == 0) { // we're at first row in paragraph
|
|
|
|
if (pit() == 0) // no previous paragraph! don't move
|
|
|
|
return false;
|
|
|
|
// move to last pos in previous par
|
|
|
|
--pit();
|
|
|
|
pos() = lastpos();
|
|
|
|
boundary(false);
|
|
|
|
} else { // move to previous row in this par
|
|
|
|
pos() = row.pos() - 1; // this is guaranteed to be in previous row
|
|
|
|
boundary(false);
|
|
|
|
}
|
|
|
|
}
|
2012-10-27 13:45:27 +00:00
|
|
|
// if moving left in an RTL paragraph or moving right in an
|
|
|
|
// LTR one, move to next row
|
2008-02-10 19:52:45 +00:00
|
|
|
else {
|
|
|
|
if (row.endpos() == lastpos()) { // we're at last row in paragraph
|
|
|
|
if (pit() == lastpit()) // last paragraph! don't move
|
|
|
|
return false;
|
|
|
|
// move to first row in next par
|
|
|
|
++pit();
|
|
|
|
pos() = 0;
|
|
|
|
boundary(false);
|
|
|
|
} else { // move to next row in this par
|
|
|
|
pos() = row.endpos();
|
|
|
|
boundary(false);
|
|
|
|
}
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-02-10 19:52:45 +00:00
|
|
|
// make sure we're at left-/right-most pos in new row
|
|
|
|
posVisToRowExtremity(!movingLeft);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 13:22:26 +00:00
|
|
|
void Cursor::posVisToRowExtremity(bool left)
|
2008-02-10 19:52:45 +00:00
|
|
|
{
|
|
|
|
LYXERR(Debug::RTL, "entering extremity: " << pit() << "," << pos() << ","
|
|
|
|
<< (boundary() ? 1 : 0));
|
|
|
|
|
2015-07-17 22:39:55 +00:00
|
|
|
TextMetrics const & tm = bv_->textMetrics(text());
|
|
|
|
// Looking for extremities is like clicking on the left or the
|
|
|
|
// right of the row.
|
|
|
|
int x = tm.origin().x_ + (left ? 0 : textRow().width());
|
|
|
|
bool b = false;
|
|
|
|
pos() = tm.getPosNearX(textRow(), x, b);
|
|
|
|
boundary(b);
|
|
|
|
|
2008-02-10 19:52:45 +00:00
|
|
|
LYXERR(Debug::RTL, "leaving extremity: " << pit() << "," << pos() << ","
|
|
|
|
<< (boundary() ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-16 09:55:45 +00:00
|
|
|
bool Cursor::reverseDirectionNeeded() const
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We determine the directions based on the direction of the
|
|
|
|
* bottom() --- i.e., outermost --- paragraph, because that is
|
|
|
|
* the only way to achieve consistency of the arrow's movements
|
|
|
|
* within a paragraph, and thus avoid situations in which the
|
|
|
|
* cursor gets stuck.
|
|
|
|
*/
|
|
|
|
return bottom().paragraph().isRTL(bv().buffer().params());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2013-04-27 09:19:19 +00:00
|
|
|
// LASSERT: There have been several bugs around this code, that seem
|
|
|
|
// to involve failures to reset the anchor. We can at least not crash
|
|
|
|
// in release mode by resetting it ourselves.
|
2016-03-18 17:03:22 +00:00
|
|
|
if (anchor_.depth() < depth()) {
|
|
|
|
LYXERR0("Cursor is deeper than anchor. PLEASE REPORT.\nCursor is"
|
|
|
|
<< *this);
|
|
|
|
const_cast<DocIterator &>(anchor_) = *this;
|
|
|
|
}
|
2013-04-27 09:19:19 +00:00
|
|
|
|
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);
|
2014-03-14 13:22:26 +00:00
|
|
|
if (idx() == normalAnchor().idx() &&
|
|
|
|
pit() == normalAnchor().pit() &&
|
2010-04-15 17:49:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
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 {
|
|
|
|
|
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();
|
2015-11-30 22:25:03 +00:00
|
|
|
checkBufferStructure();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::insert(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;
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(!empty(), return);
|
2004-03-18 12:53:43 +00:00
|
|
|
if (inMathed()) {
|
2006-10-21 00:16:43 +00:00
|
|
|
cap::selClearOrDel(*this);
|
2006-09-16 18:11:38 +00:00
|
|
|
insert(new InsetMathChar(c));
|
2004-03-18 12:53:43 +00:00
|
|
|
} else {
|
|
|
|
text()->insertChar(*this, c);
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(inset0, return);
|
2004-02-11 14:45:44 +00:00
|
|
|
if (inMathed())
|
2010-10-26 16:45:21 +00:00
|
|
|
insert(MathAtom(inset0->asInsetMath()));
|
2008-03-02 18:49:49 +00:00
|
|
|
else {
|
2008-02-29 20:55:56 +00:00
|
|
|
text()->insertInset(*this, inset0);
|
2008-03-02 18:49:49 +00:00
|
|
|
inset0->setBuffer(bv_->buffer());
|
2008-03-03 17:58:26 +00:00
|
|
|
inset0->initView();
|
2010-07-09 14:37:00 +00:00
|
|
|
if (inset0->isLabeled())
|
|
|
|
forceBufferUpdate();
|
2008-03-02 18:49:49 +00:00
|
|
|
}
|
2004-02-11 14:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-27 00:43:25 +00:00
|
|
|
int Cursor::niceInsert(docstring const & t, Parse::flags f, bool enter)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2009-11-15 01:03:03 +00:00
|
|
|
MathData ar(buffer());
|
2008-10-17 21:40:11 +00:00
|
|
|
asArray(t, ar, f);
|
2011-01-28 09:52:12 +00:00
|
|
|
if (ar.size() == 1 && (enter || selection()))
|
2004-01-26 10:13:15 +00:00
|
|
|
niceInsert(ar[0]);
|
2011-01-28 09:52:12 +00:00
|
|
|
else
|
2004-01-26 10:13:15 +00:00
|
|
|
insert(ar);
|
2011-01-28 09:52:12 +00:00
|
|
|
return ar.size();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::niceInsert(MathAtom const & t)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
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);
|
2007-05-29 20:53:32 +00:00
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool Cursor::down()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
macroModeClose();
|
2004-03-31 19:11:56 +00:00
|
|
|
DocIterator save = *this;
|
2007-05-29 20:53:32 +00:00
|
|
|
FuncRequest cmd(selection() ? LFUN_DOWN_SELECT : LFUN_DOWN, docstring());
|
|
|
|
this->dispatch(cmd);
|
|
|
|
if (disp_.dispatched())
|
2004-01-26 10:13:15 +00:00
|
|
|
return true;
|
2004-08-14 19:55:00 +00:00
|
|
|
setCursor(save);
|
2007-05-29 20:53:32 +00:00
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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());
|
2012-10-21 19:14:16 +00:00
|
|
|
if (!selection.empty() && data && data->numargs() - data->optionals() > 0) {
|
2008-03-04 14:49:24 +00:00
|
|
|
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);
|
2014-03-14 13:22:26 +00:00
|
|
|
|
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);
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
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;
|
2011-01-10 10:23:10 +00:00
|
|
|
if (pos() == 0 || cell().empty())
|
2004-01-26 10:13:15 +00:00
|
|
|
return false;
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathUnknown const * p = prevAtom()->asUnknownInset();
|
2004-01-26 10:13:15 +00:00
|
|
|
return p && !p->final();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
InsetMathUnknown * Cursor::activeMacro()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
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;
|
2015-10-07 03:13:21 +00:00
|
|
|
TexRow texrow(false);
|
|
|
|
otexrowstream ots(os,texrow);
|
|
|
|
WriteStream wi(ots, 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.
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// We want to keep the x-target on subsequent up/down movements
|
|
|
|
// that cross beyond the end of short lines. Thus a special
|
2007-08-11 10:32:36 +00:00
|
|
|
// handling when the cursor is at the end of line: Use the new
|
2007-05-29 20:53:32 +00:00
|
|
|
// x-target only if the old one was before the end of line
|
|
|
|
// or the old one was after the beginning of the line
|
2015-07-16 09:55:45 +00:00
|
|
|
bool inRTL = innerParagraph().isRTL(bv().buffer().params());
|
2007-05-29 20:53:32 +00:00
|
|
|
bool left;
|
|
|
|
bool right;
|
|
|
|
if (inRTL) {
|
|
|
|
left = pos() == textRow().endpos();
|
|
|
|
right = pos() == textRow().pos();
|
|
|
|
} else {
|
|
|
|
left = pos() == textRow().pos();
|
|
|
|
right = pos() == textRow().endpos();
|
|
|
|
}
|
|
|
|
if ((!left && !right) ||
|
2007-08-11 10:32:36 +00:00
|
|
|
(left && !right && xo < x_target_) ||
|
2007-05-29 20:53:32 +00:00
|
|
|
(!left && right && x_target_ < xo))
|
|
|
|
setTargetX(xo);
|
|
|
|
else
|
|
|
|
xo = targetX();
|
2007-08-11 10:32:36 +00:00
|
|
|
} else
|
2007-05-29 20:53:32 +00:00
|
|
|
xo = targetX();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
// try neigbouring script insets
|
2007-05-29 20:53:32 +00:00
|
|
|
Cursor old = *this;
|
|
|
|
if (inMathed() && !selection()) {
|
2004-01-26 10:13:15 +00:00
|
|
|
// try left
|
|
|
|
if (pos() != 0) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathScript const * p = prevAtom()->asScriptInset();
|
2004-01-26 10:13:15 +00:00
|
|
|
if (p && p->has(up)) {
|
|
|
|
--pos();
|
2006-09-16 18:11:38 +00:00
|
|
|
push(*const_cast<InsetMathScript*>(p));
|
2005-07-17 12:28:02 +00:00
|
|
|
idx() = p->idxOfScript(up);
|
2004-01-26 10:13:15 +00:00
|
|
|
pos() = lastpos();
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// we went in the right direction? Otherwise don't jump into the script
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
getPos(x, y);
|
2010-02-09 14:29:27 +00:00
|
|
|
int oy = beforeDispatchPosY_;
|
2007-12-17 18:13:02 +00:00
|
|
|
if ((!up && y <= oy) ||
|
|
|
|
(up && y >= oy))
|
2007-05-29 20:53:32 +00:00
|
|
|
operator=(old);
|
|
|
|
else
|
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
// try right
|
|
|
|
if (pos() != lastpos()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathScript const * p = nextAtom()->asScriptInset();
|
2004-01-26 10:13:15 +00:00
|
|
|
if (p && p->has(up)) {
|
2006-09-16 18:11:38 +00:00
|
|
|
push(*const_cast<InsetMathScript*>(p));
|
2005-07-17 12:28:02 +00:00
|
|
|
idx() = p->idxOfScript(up);
|
2004-01-26 10:13:15 +00:00
|
|
|
pos() = 0;
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// we went in the right direction? Otherwise don't jump into the script
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
getPos(x, y);
|
2010-02-09 14:29:27 +00:00
|
|
|
int oy = beforeDispatchPosY_;
|
2007-12-17 18:13:02 +00:00
|
|
|
if ((!up && y <= oy) ||
|
|
|
|
(up && y >= oy))
|
2007-05-29 20:53:32 +00:00
|
|
|
operator=(old);
|
|
|
|
else
|
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// try to find an inset that knows better then we,
|
|
|
|
if (inset().idxUpDown(*this, up)) {
|
|
|
|
//lyxerr << "idxUpDown triggered" << endl;
|
|
|
|
// try to find best position within this inset
|
|
|
|
if (!selection())
|
|
|
|
setCursor(bruteFind2(*this, xo, yo));
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// any improvement going just out of inset?
|
2007-11-05 19:41:16 +00:00
|
|
|
if (popBackward() && inMathed()) {
|
|
|
|
//lyxerr << "updown: popBackward succeeded" << endl;
|
2005-02-08 13:18:05 +00:00
|
|
|
int xnew;
|
|
|
|
int ynew;
|
2010-02-09 14:29:27 +00:00
|
|
|
int yold = beforeDispatchPosY_;
|
2004-01-30 11:41:12 +00:00
|
|
|
getPos(xnew, ynew);
|
2007-12-17 18:13:02 +00:00
|
|
|
if (up ? ynew < yold : ynew > yold)
|
2004-01-26 10:13:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// no success, we are probably at the document top or bottom
|
|
|
|
operator=(old);
|
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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());
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-11-16 18:03:52 +00:00
|
|
|
int row;
|
|
|
|
if (pos() && boundary())
|
|
|
|
row = pm.pos2row(pos() - 1);
|
|
|
|
else
|
|
|
|
row = pm.pos2row(pos());
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2008-11-16 18:03:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
|
2007-08-11 10:32:36 +00:00
|
|
|
bool Cursor::upDownInText(bool up, bool & updateNeeded)
|
2007-05-29 20:53:32 +00:00
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(text(), return false);
|
2007-05-29 20:53:32 +00:00
|
|
|
|
|
|
|
// where are we?
|
|
|
|
int xo = 0;
|
|
|
|
int yo = 0;
|
|
|
|
getPos(xo, yo);
|
2010-02-09 14:29:27 +00:00
|
|
|
xo = beforeDispatchPosX_;
|
2007-12-17 18:13:02 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// update the targetX - this is here before the "return false"
|
|
|
|
// to set a new target which can be used by InsetTexts above
|
|
|
|
// if we cannot move up/down inside this inset anymore
|
|
|
|
if (x_target_ == -1)
|
|
|
|
setTargetX(xo);
|
2007-08-11 10:32:36 +00:00
|
|
|
else if (xo - textTargetOffset() != x_target() &&
|
2007-06-14 20:32:28 +00:00
|
|
|
depth() == beforeDispatchCursor_.depth()) {
|
2012-10-27 13:45:27 +00:00
|
|
|
// In text mode inside the line (not left or right)
|
|
|
|
// possibly set a new target_x, but only if we are
|
|
|
|
// somewhere else than the previous target-offset.
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
// We want to keep the x-target on subsequent up/down
|
|
|
|
// movements that cross beyond the end of short lines.
|
|
|
|
// Thus a special handling when the cursor is at the
|
|
|
|
// end of line: Use the new x-target only if the old
|
|
|
|
// one was before the end of line or the old one was
|
|
|
|
// after the beginning of the line
|
2015-07-16 09:55:45 +00:00
|
|
|
bool inRTL = innerParagraph().isRTL(bv().buffer().params());
|
2007-05-29 20:53:32 +00:00
|
|
|
bool left;
|
|
|
|
bool right;
|
|
|
|
if (inRTL) {
|
|
|
|
left = pos() == textRow().endpos();
|
|
|
|
right = pos() == textRow().pos();
|
|
|
|
} else {
|
|
|
|
left = pos() == textRow().pos();
|
|
|
|
right = pos() == textRow().endpos();
|
|
|
|
}
|
|
|
|
if ((!left && !right) ||
|
2007-08-11 10:32:36 +00:00
|
|
|
(left && !right && xo < x_target_) ||
|
2007-05-29 20:53:32 +00:00
|
|
|
(!left && right && x_target_ < xo))
|
|
|
|
setTargetX(xo);
|
|
|
|
else
|
|
|
|
xo = targetX();
|
2007-08-11 10:32:36 +00:00
|
|
|
} else
|
2007-05-29 20:53:32 +00:00
|
|
|
xo = targetX();
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
// first get the current line
|
2007-09-02 09:44:08 +00:00
|
|
|
TextMetrics & tm = bv_->textMetrics(text());
|
2007-05-29 20:53:32 +00:00
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(pit());
|
|
|
|
int row;
|
|
|
|
if (pos() && boundary())
|
|
|
|
row = pm.pos2row(pos() - 1);
|
|
|
|
else
|
|
|
|
row = pm.pos2row(pos());
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2009-03-25 21:21:00 +00:00
|
|
|
if (atFirstOrLastRow(up)) {
|
2009-04-15 20:20:42 +00:00
|
|
|
// Is there a place for the cursor to go ? If yes, we
|
|
|
|
// can execute the DEPM, otherwise we should keep the
|
|
|
|
// paragraph to host the cursor.
|
2009-03-25 21:21:00 +00:00
|
|
|
Cursor dummy = *this;
|
2009-04-15 20:20:42 +00:00
|
|
|
bool valid_destination = false;
|
|
|
|
for(; dummy.depth(); dummy.pop())
|
|
|
|
if (!dummy.atFirstOrLastRow(up)) {
|
|
|
|
valid_destination = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-14 13:22:26 +00:00
|
|
|
// will a next dispatch follow and if there is a new
|
2009-04-15 20:20:42 +00:00
|
|
|
// dispatch will it move the cursor out ?
|
|
|
|
if (depth() > 1 && valid_destination) {
|
|
|
|
// The cursor hasn't changed yet. This happens when
|
2014-03-14 13:22:26 +00:00
|
|
|
// you e.g. move out of an inset. And to give the
|
2009-04-15 20:20:42 +00:00
|
|
|
// DEPM the possibility of doing something we must
|
|
|
|
// provide it with two different cursors. (Lgb, vfr)
|
|
|
|
dummy = *this;
|
|
|
|
dummy.pos() = dummy.pos() == 0 ? dummy.lastpos() : 0;
|
|
|
|
dummy.pit() = dummy.pit() == 0 ? dummy.lastpit() : 0;
|
|
|
|
|
|
|
|
updateNeeded |= bv().checkDepm(dummy, *this);
|
|
|
|
updateTextTargetOffset();
|
2013-05-19 12:42:27 +00:00
|
|
|
if (updateNeeded)
|
2010-07-09 14:37:00 +00:00
|
|
|
forceBufferUpdate();
|
2009-04-15 20:20:42 +00:00
|
|
|
}
|
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();
|
2014-03-14 13:22:26 +00:00
|
|
|
|
|
|
|
// This happens when you move out of an inset.
|
|
|
|
// And to give the DEPM the possibility of doing
|
|
|
|
// something we must provide it with two different
|
|
|
|
// cursors. (Lgb)
|
2009-04-15 20:20:42 +00:00
|
|
|
Cursor dummy = *this;
|
|
|
|
if (dummy == old)
|
|
|
|
++dummy.pos();
|
|
|
|
if (bv().checkDepm(dummy, old)) {
|
|
|
|
updateNeeded = true;
|
2014-03-14 13:22:26 +00:00
|
|
|
// Make sure that cur gets back whatever happened to dummy (Lgb)
|
2009-04-15 20:20:42 +00:00
|
|
|
operator=(dummy);
|
|
|
|
}
|
2016-01-28 13:13:17 +00:00
|
|
|
if (inTexted() && pos() && paragraph().isEnvSeparator(pos() - 1))
|
2016-01-09 23:08:10 +00:00
|
|
|
posBackward();
|
2007-05-29 20:53:32 +00:00
|
|
|
} else {
|
2009-11-05 12:58:25 +00:00
|
|
|
// if there is a selection, we stay out of any inset,
|
|
|
|
// and just jump to the right position:
|
2007-05-29 20:53:32 +00:00
|
|
|
Cursor old = *this;
|
2009-11-05 12:58:25 +00:00
|
|
|
int next_row = row;
|
2007-05-29 20:53:32 +00:00
|
|
|
if (up) {
|
|
|
|
if (row > 0) {
|
2009-11-05 12:58:25 +00:00
|
|
|
--next_row;
|
2007-05-29 20:53:32 +00:00
|
|
|
} else if (pit() > 0) {
|
|
|
|
--pit();
|
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
|
|
|
}
|
|
|
|
}
|
2007-06-14 20:32:28 +00:00
|
|
|
|
2014-03-17 10:15:42 +00:00
|
|
|
Row const & real_next_row = tm.parMetrics(pit()).rows()[next_row];
|
|
|
|
bool bound = false;
|
2014-05-02 13:55:10 +00:00
|
|
|
top().pos() = tm.getPosNearX(real_next_row, xo, bound);
|
2014-03-17 10:15:42 +00:00
|
|
|
boundary(bound);
|
2009-11-15 22:01:12 +00:00
|
|
|
|
2007-05-30 19:38:22 +00:00
|
|
|
updateNeeded |= bv().checkDepm(*this, old);
|
2007-05-29 20:53:32 +00:00
|
|
|
}
|
2007-06-14 20:32:28 +00:00
|
|
|
|
2010-07-09 14:37:00 +00:00
|
|
|
if (updateNeeded)
|
|
|
|
forceBufferUpdate();
|
2007-05-29 20:53:32 +00:00
|
|
|
updateTextTargetOffset();
|
|
|
|
return true;
|
2014-03-14 13:22:26 +00:00
|
|
|
}
|
2007-05-29 20:53:32 +00:00
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Cursor::handleFont(string const & font)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR(Debug::DEBUG, font);
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring safe;
|
2004-01-26 10:13:15 +00:00
|
|
|
if (selection()) {
|
|
|
|
macroModeClose();
|
2006-10-21 00:16:43 +00:00
|
|
|
safe = cap::grabAndEraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
2008-09-14 17:51:46 +00:00
|
|
|
recordUndoInset();
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
if (lastpos() != 0) {
|
|
|
|
// something left in the cell
|
|
|
|
if (pos() == 0) {
|
|
|
|
// cursor in first position
|
2007-11-05 19:41:16 +00:00
|
|
|
popBackward();
|
2004-01-26 10:13:15 +00:00
|
|
|
} else if (pos() == lastpos()) {
|
|
|
|
// cursor in last position
|
2007-11-05 19:41:16 +00:00
|
|
|
popForward();
|
2004-01-26 10:13:15 +00:00
|
|
|
} else {
|
|
|
|
// cursor in between. split cell
|
2007-04-26 16:06:39 +00:00
|
|
|
MathData::iterator bt = cell().begin();
|
2009-11-08 11:45:46 +00:00
|
|
|
MathAtom at = createInsetMath(from_utf8(font), buffer());
|
|
|
|
at.nucleus()->cell(0) = MathData(buffer(), bt, bt + pos());
|
2004-01-26 10:13:15 +00:00
|
|
|
cell().erase(bt, bt + pos());
|
2007-11-05 19:41:16 +00:00
|
|
|
popBackward();
|
2004-01-26 10:13:15 +00:00
|
|
|
plainInsert(at);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// nothing left in the cell
|
2008-09-14 17:51:46 +00:00
|
|
|
popBackward();
|
2004-01-26 10:13:15 +00:00
|
|
|
plainErase();
|
2008-09-14 17:51:46 +00:00
|
|
|
resetAnchor();
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
insert(safe);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 {
|
2012-10-27 13:45:27 +00:00
|
|
|
|
2010-11-06 15:06:19 +00:00
|
|
|
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
|
2014-03-14 13:22:26 +00:00
|
|
|
if (!cur->inset().getLayout().parbreakIsNewline()
|
2010-11-06 15:06:19 +00:00
|
|
|
&& !cur->paragraph().layout().parbreak_is_newline)
|
2009-08-09 14:33:35 +00:00
|
|
|
os << '\n';
|
|
|
|
return os.str();
|
|
|
|
}
|
2012-10-27 13:45:27 +00:00
|
|
|
|
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);
|
2015-10-13 23:23:12 +00:00
|
|
|
#ifdef DEVEL_VERSION
|
|
|
|
InsetMath * math = inset().asInsetMath();
|
|
|
|
if (math)
|
|
|
|
os << _(", Inset: ") << math->id();
|
|
|
|
os << _(", Cell: ") << idx();
|
|
|
|
os << _(", Position: ") << pos();
|
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::undispatched() const
|
2004-02-16 11:58:51 +00:00
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
disp_.dispatched(false);
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::dispatched() const
|
2004-03-27 12:46:30 +00:00
|
|
|
{
|
|
|
|
disp_.dispatched(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::screenUpdateFlags(Update::flags f) const
|
2004-08-13 14:56:06 +00:00
|
|
|
{
|
2010-10-13 17:28:55 +00:00
|
|
|
disp_.screenUpdate(f);
|
2004-08-13 14:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::forceBufferUpdate() const
|
2010-07-09 14:37:00 +00:00
|
|
|
{
|
|
|
|
disp_.forceBufferUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::clearBufferUpdate() const
|
2010-07-09 14:37:00 +00:00
|
|
|
{
|
|
|
|
disp_.clearBufferUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::needBufferUpdate() const
|
|
|
|
{
|
|
|
|
return disp_.needBufferUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 09:38:20 +00:00
|
|
|
void Cursor::noScreenUpdate() const
|
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
|
|
|
{
|
2012-10-27 13:45:27 +00:00
|
|
|
// The logic here should more or less match to the
|
|
|
|
// Cursor::setCurrentFont logic, i.e. the cursor height should
|
|
|
|
// give a hint what will happen if a character is entered.
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2005-01-10 09:28:06 +00:00
|
|
|
// HACK. far from being perfect...
|
2008-02-07 17:07:27 +00:00
|
|
|
|
|
|
|
CursorSlice const & sl = innerTextSlice();
|
2007-04-29 23:33:02 +00:00
|
|
|
Text const & text = *sl.text();
|
2007-06-07 20:40:01 +00:00
|
|
|
Paragraph const & par = text.getPar(sl.pit());
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-06-07 20:40:01 +00:00
|
|
|
// on boundary, so we are really at the character before
|
|
|
|
pos_type pos = sl.pos();
|
|
|
|
if (pos > 0 && boundary())
|
|
|
|
--pos;
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-06-07 20:40:01 +00:00
|
|
|
// on space? Take the font before (only for RTL boundary stay)
|
|
|
|
if (pos > 0) {
|
2007-09-02 21:48:49 +00:00
|
|
|
TextMetrics const & tm = bv().textMetrics(&text);
|
2007-06-07 20:40:01 +00:00
|
|
|
if (pos == sl.lastpos()
|
2014-03-14 13:22:26 +00:00
|
|
|
|| (par.isSeparator(pos)
|
2007-09-02 22:28:49 +00:00
|
|
|
&& !tm.isRTLBoundary(sl.pit(), pos)))
|
2007-06-07 20:40:01 +00:00
|
|
|
--pos;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-06-07 20:40:01 +00:00
|
|
|
// get font at the position
|
2008-11-17 11:46:07 +00:00
|
|
|
Font font = par.getFont(buffer()->params(), pos,
|
2009-08-09 18:35:39 +00:00
|
|
|
text.outerFont(sl.pit()));
|
2005-02-08 13:18:05 +00:00
|
|
|
|
2005-01-10 09:28:06 +00:00
|
|
|
return font;
|
|
|
|
}
|
2005-02-15 17:34:54 +00:00
|
|
|
|
|
|
|
|
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();
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2010-01-13 18:57:42 +00:00
|
|
|
if (broken_cursor || broken_anchor) {
|
2011-03-15 10:27:41 +00:00
|
|
|
clearNewWordPosition();
|
2010-01-13 18:57:42 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2012-07-17 20:26:44 +00:00
|
|
|
void Cursor::sanitize()
|
|
|
|
{
|
|
|
|
setBuffer(&bv_->buffer());
|
|
|
|
DocIterator::sanitize();
|
2015-03-10 14:53:25 +00:00
|
|
|
if (selection())
|
|
|
|
anchor_.sanitize();
|
|
|
|
else
|
|
|
|
resetAnchor();
|
2012-07-17 20:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-15 17:11:01 +00:00
|
|
|
bool notifyCursorLeavesOrEnters(Cursor const & old, Cursor & cur)
|
2007-06-14 20:32:28 +00:00
|
|
|
{
|
|
|
|
// find inset in common
|
|
|
|
size_type i;
|
|
|
|
for (i = 0; i < old.depth() && i < cur.depth(); ++i) {
|
2008-02-09 22:05:24 +00:00
|
|
|
if (&old[i].inset() != &cur[i].inset())
|
2007-06-14 20:32:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-26 19:20:12 +00:00
|
|
|
|
|
|
|
// update words if we just moved to another paragraph
|
|
|
|
if (i == old.depth() && i == cur.depth()
|
2008-11-17 11:46:07 +00:00
|
|
|
&& !cur.buffer()->isClean()
|
2008-02-26 19:20:12 +00:00
|
|
|
&& cur.inTexted() && old.inTexted()
|
|
|
|
&& cur.pit() != old.pit()) {
|
2009-05-01 09:56:20 +00:00
|
|
|
old.paragraph().updateWords();
|
2008-02-26 19:20:12 +00:00
|
|
|
}
|
2008-11-15 17:11:01 +00:00
|
|
|
|
2007-06-14 20:32:28 +00:00
|
|
|
// notify everything on top of the common part in old cursor,
|
|
|
|
// but stop if the inset claims the cursor to be invalid now
|
2008-11-15 17:11:01 +00:00
|
|
|
for (size_type j = i; j < old.depth(); ++j) {
|
2009-11-22 21:45:51 +00:00
|
|
|
Cursor inset_pos = old;
|
|
|
|
inset_pos.cutOff(j);
|
|
|
|
if (old[j].inset().notifyCursorLeaves(inset_pos, cur))
|
2008-11-15 17:11:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// notify everything on top of the common part in new cursor,
|
|
|
|
// but stop if the inset claims the cursor to be invalid now
|
|
|
|
for (; i < cur.depth(); ++i) {
|
|
|
|
if (cur[i].inset().notifyCursorEnters(cur))
|
2007-06-14 20:32:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-14 13:22:26 +00:00
|
|
|
|
2007-06-14 20:32:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2012-07-15 16:16:09 +00:00
|
|
|
if (!buffer()->undo().textUndo(*this))
|
2007-10-18 11:51:17 +00:00
|
|
|
return false;
|
2012-07-17 20:26:44 +00:00
|
|
|
sanitize();
|
2007-10-18 11:51:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::textRedo()
|
|
|
|
{
|
2012-07-15 16:16:09 +00:00
|
|
|
if (!buffer()->undo().textRedo(*this))
|
2007-10-18 11:51:17 +00:00
|
|
|
return false;
|
2012-07-17 20:26:44 +00:00
|
|
|
sanitize();
|
2007-10-18 11:51:17 +00:00
|
|
|
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
|
|
|
|
{
|
2015-07-16 12:13:13 +00:00
|
|
|
buffer()->undo().beginUndoGroup(*this);
|
2008-08-15 19:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::endUndoGroup() const
|
|
|
|
{
|
2012-02-07 14:56:16 +00:00
|
|
|
buffer()->undo().endUndoGroup(*this);
|
2008-08-15 19:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-12 14:57:29 +00:00
|
|
|
void Cursor::recordUndo(pit_type from, pit_type to) const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2015-03-12 14:57:29 +00:00
|
|
|
buffer()->undo().recordUndo(*this, from, to);
|
2007-10-18 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-12 14:57:29 +00:00
|
|
|
void Cursor::recordUndo(pit_type from) const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2015-03-12 14:57:29 +00:00
|
|
|
buffer()->undo().recordUndo(*this, from, pit());
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-12 14:57:29 +00:00
|
|
|
void Cursor::recordUndoInset(Inset const * in) const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2015-05-20 10:09:12 +00:00
|
|
|
buffer()->undo().recordUndoInset(*this, in);
|
2007-10-18 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-17 19:38:22 +00:00
|
|
|
void Cursor::recordUndoFullBuffer() const
|
2007-10-18 11:51:17 +00:00
|
|
|
{
|
2015-01-17 19:38:22 +00:00
|
|
|
buffer()->undo().recordUndoFullBuffer(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::recordUndoBufferParams() const
|
|
|
|
{
|
|
|
|
buffer()->undo().recordUndoBufferParams(*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 {
|
2015-03-12 14:57:29 +00:00
|
|
|
buffer()->undo().recordUndo(*this,
|
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())
|
2014-03-14 13:22:26 +00:00
|
|
|
// In case the master has no gui associated with it,
|
2009-02-19 00:29:04 +00:00
|
|
|
// the TocItem is not updated (part of bug 5699).
|
|
|
|
buffer()->tocBackend().updateItem(*this);
|
2008-01-12 21:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|