2004-03-30 12:14:01 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file DocIterator.cpp
|
2004-03-30 12:14:01 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2007-06-09 12:39:46 +00:00
|
|
|
* \author Alfredo Braunstein
|
2004-03-30 12:14:01 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2004-03-01 17:12:09 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DocIterator.h"
|
2004-03-01 17:12:09 +00:00
|
|
|
|
2008-11-17 11:46:07 +00:00
|
|
|
#include "Buffer.h"
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "Encoding.h"
|
|
|
|
#include "Font.h"
|
2007-10-18 15:29:51 +00:00
|
|
|
#include "InsetList.h"
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
#include "Language.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Paragraph.h"
|
2007-10-18 15:29:51 +00:00
|
|
|
#include "Text.h"
|
2004-03-01 17:12:09 +00:00
|
|
|
|
2007-04-26 16:06:39 +00:00
|
|
|
#include "mathed/MathData.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "mathed/InsetMath.h"
|
2008-11-16 00:12:21 +00:00
|
|
|
#include "mathed/InsetMathHull.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetTabular.h"
|
2004-03-01 17:12:09 +00:00
|
|
|
|
2017-01-09 22:15:16 +00:00
|
|
|
#include "support/convert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2013-04-25 21:27:10 +00:00
|
|
|
#include "support/ExceptionMessage.h"
|
|
|
|
#include "support/gettext.h"
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2009-03-28 19:02:49 +00:00
|
|
|
#include "support/lstrings.h"
|
2004-03-01 17:12:09 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
#include <ostream>
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
using namespace std;
|
2009-03-28 19:02:49 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-07-17 17:46:54 +00:00
|
|
|
namespace lyx {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
2008-11-17 11:46:07 +00:00
|
|
|
DocIterator doc_iterator_begin(const Buffer * buf0, const Inset * inset0)
|
2004-03-18 16:41:45 +00:00
|
|
|
{
|
2017-07-03 17:53:14 +00:00
|
|
|
Buffer * buf = const_cast<Buffer *>(buf0);
|
2008-11-17 11:46:07 +00:00
|
|
|
Inset * inset = const_cast<Inset *>(inset0);
|
|
|
|
DocIterator dit(buf, inset ? inset : &buf->inset());
|
2004-03-30 08:18:09 +00:00
|
|
|
dit.forwardPos();
|
|
|
|
return dit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-17 11:46:07 +00:00
|
|
|
DocIterator doc_iterator_end(const Buffer * buf0, const Inset * inset0)
|
2004-03-30 08:18:09 +00:00
|
|
|
{
|
2017-07-03 17:53:14 +00:00
|
|
|
Buffer * buf = const_cast<Buffer *>(buf0);
|
2008-11-17 11:46:07 +00:00
|
|
|
Inset * inset = const_cast<Inset *>(inset0);
|
|
|
|
return DocIterator(buf, inset ? inset : &buf->inset());
|
2004-03-18 16:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-09 14:47:47 +00:00
|
|
|
DocIterator DocIterator::clone(Buffer * buffer) const
|
|
|
|
{
|
|
|
|
LASSERT(buffer->isClone(), return DocIterator());
|
|
|
|
Inset * inset = &buffer->inset();
|
2010-01-09 15:41:07 +00:00
|
|
|
DocIterator dit(buffer);
|
2010-01-09 14:47:47 +00:00
|
|
|
size_t const n = slices_.size();
|
|
|
|
for (size_t i = 0 ; i != n; ++i) {
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(inset);
|
2010-01-09 15:41:07 +00:00
|
|
|
dit.push_back(slices_[i]);
|
2010-01-09 14:47:47 +00:00
|
|
|
dit.top().inset_ = inset;
|
|
|
|
if (i + 1 != n)
|
|
|
|
inset = dit.nextInset();
|
|
|
|
}
|
|
|
|
return dit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-16 00:12:21 +00:00
|
|
|
bool DocIterator::inRegexped() const
|
|
|
|
{
|
2010-10-27 07:04:58 +00:00
|
|
|
InsetMath * im = inset().asInsetMath();
|
2017-07-03 17:53:14 +00:00
|
|
|
if (!im)
|
2010-10-27 07:04:58 +00:00
|
|
|
return false;
|
|
|
|
InsetMathHull * hull = im->asHullInset();
|
|
|
|
return hull && hull->getType() == hullRegexp;
|
2008-11-16 00:12:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
LyXErr & operator<<(LyXErr & os, DocIterator const & it)
|
|
|
|
{
|
|
|
|
os.stream() << it;
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 21:13:01 +00:00
|
|
|
Inset * DocIterator::nextInset() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2020-02-29 05:06:30 +00:00
|
|
|
LASSERT(!empty(), return nullptr);
|
2004-03-01 17:12:09 +00:00
|
|
|
if (pos() == lastpos())
|
2020-02-29 05:06:30 +00:00
|
|
|
return nullptr;
|
2004-10-23 11:04:41 +00:00
|
|
|
if (pos() > lastpos()) {
|
2009-08-18 16:03:44 +00:00
|
|
|
LYXERR0("Should not happen, but it does: pos() = "
|
|
|
|
<< pos() << ", lastpos() = " << lastpos());
|
2020-02-29 05:06:30 +00:00
|
|
|
return nullptr;
|
2004-10-23 11:04:41 +00:00
|
|
|
}
|
2004-04-03 08:37:12 +00:00
|
|
|
if (inMathed())
|
2004-03-01 17:12:09 +00:00
|
|
|
return nextAtom().nucleus();
|
2008-02-09 10:41:49 +00:00
|
|
|
return paragraph().getInset(pos());
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 21:13:01 +00:00
|
|
|
Inset * DocIterator::prevInset() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2020-02-29 05:06:30 +00:00
|
|
|
LASSERT(!empty(), return nullptr);
|
2004-03-01 17:12:09 +00:00
|
|
|
if (pos() == 0)
|
2020-02-29 05:06:30 +00:00
|
|
|
return nullptr;
|
2007-09-16 10:36:57 +00:00
|
|
|
if (inMathed()) {
|
2007-02-08 08:44:45 +00:00
|
|
|
if (cell().empty())
|
|
|
|
// FIXME: this should not happen but it does.
|
|
|
|
// See bug 3189
|
2009-12-11 00:59:10 +00:00
|
|
|
// http://www.lyx.org/trac/ticket/3189
|
2020-02-29 05:06:30 +00:00
|
|
|
return nullptr;
|
2007-02-08 08:44:45 +00:00
|
|
|
else
|
|
|
|
return prevAtom().nucleus();
|
2007-09-16 10:36:57 +00:00
|
|
|
}
|
2008-02-09 10:41:49 +00:00
|
|
|
return paragraph().getInset(pos() - 1);
|
2005-11-24 16:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * DocIterator::realInset() const
|
2005-11-24 16:22:39 +00:00
|
|
|
{
|
2020-02-29 05:06:30 +00:00
|
|
|
LASSERT(inTexted(), return nullptr);
|
2005-11-24 16:22:39 +00:00
|
|
|
// if we are in a tabular, we need the cell
|
2007-10-13 09:04:52 +00:00
|
|
|
if (inset().lyxCode() == TABULAR_CODE) {
|
2010-10-26 16:45:21 +00:00
|
|
|
InsetTabular * tabular = inset().asInsetTabular();
|
|
|
|
return tabular->cell(idx()).get();
|
2005-11-24 16:22:39 +00:00
|
|
|
}
|
|
|
|
return &inset();
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
InsetMath & DocIterator::nextMath()
|
|
|
|
{
|
|
|
|
return *nextAtom().nucleus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetMath & DocIterator::prevMath()
|
|
|
|
{
|
|
|
|
return *prevAtom().nucleus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 21:13:01 +00:00
|
|
|
MathAtom & DocIterator::prevAtom() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(!empty(), /**/);
|
|
|
|
LASSERT(pos() > 0, /**/);
|
2004-03-01 17:12:09 +00:00
|
|
|
return cell()[pos() - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 21:13:01 +00:00
|
|
|
MathAtom & DocIterator::nextAtom() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(!empty(), /**/);
|
2004-04-13 06:27:29 +00:00
|
|
|
//lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(pos() < lastpos(), /**/);
|
2004-03-01 17:12:09 +00:00
|
|
|
return cell()[pos()];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 21:13:01 +00:00
|
|
|
Text * DocIterator::text() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2020-02-29 05:06:30 +00:00
|
|
|
LASSERT(!empty(), return nullptr);
|
2004-03-18 12:53:43 +00:00
|
|
|
return top().text();
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 21:13:01 +00:00
|
|
|
Paragraph & DocIterator::paragraph() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
if (!inTexted()) {
|
2007-11-28 22:12:03 +00:00
|
|
|
LYXERR0(*this);
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(false);
|
2013-04-25 21:27:10 +00:00
|
|
|
}
|
2004-03-18 12:53:43 +00:00
|
|
|
return top().paragraph();
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 21:13:01 +00:00
|
|
|
Paragraph & DocIterator::innerParagraph() const
|
2007-09-14 12:52:39 +00:00
|
|
|
{
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(!empty());
|
2007-09-14 12:52:39 +00:00
|
|
|
return innerTextSlice().paragraph();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-03 17:27:13 +00:00
|
|
|
FontSpan DocIterator::locateWord(word_location const loc) const
|
|
|
|
{
|
|
|
|
FontSpan f = FontSpan();
|
|
|
|
|
2011-02-08 09:42:00 +00:00
|
|
|
if (!top().text()->empty()) {
|
|
|
|
f.first = pos();
|
|
|
|
top().paragraph().locateWord(f.first, f.last, loc);
|
|
|
|
}
|
2011-02-03 17:27:13 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2017-01-09 22:15:16 +00:00
|
|
|
|
2007-09-14 12:52:39 +00:00
|
|
|
CursorSlice const & DocIterator::innerTextSlice() const
|
2007-04-30 11:46:02 +00:00
|
|
|
{
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(!empty());
|
2007-04-30 11:46:02 +00:00
|
|
|
// go up until first non-0 text is hit
|
|
|
|
// (innermost text is 0 in mathed)
|
|
|
|
for (int i = depth() - 1; i >= 0; --i)
|
|
|
|
if (slices_[i].text())
|
2007-09-14 12:52:39 +00:00
|
|
|
return slices_[i];
|
2007-04-30 11:46:02 +00:00
|
|
|
|
2013-12-15 11:18:49 +00:00
|
|
|
// This case is in principle not possible. We _must_
|
2007-09-14 12:52:39 +00:00
|
|
|
// be inside a Text.
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(false);
|
2013-04-25 21:27:10 +00:00
|
|
|
// Squash warning
|
|
|
|
static const CursorSlice c;
|
|
|
|
return c;
|
2007-04-30 11:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-09 22:15:16 +00:00
|
|
|
docstring DocIterator::paragraphGotoArgument() const
|
|
|
|
{
|
|
|
|
CursorSlice const & s = innerTextSlice();
|
|
|
|
return convert<docstring>(s.paragraph().id()) + ' ' +
|
|
|
|
convert<docstring>(s.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-30 22:25:03 +00:00
|
|
|
DocIterator DocIterator::getInnerText() const
|
|
|
|
{
|
|
|
|
DocIterator texted = *this;
|
2016-01-08 19:06:50 +00:00
|
|
|
while (!texted.inTexted())
|
2015-11-30 22:25:03 +00:00
|
|
|
texted.pop_back();
|
|
|
|
return texted;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
pit_type DocIterator::lastpit() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
|
|
|
return inMathed() ? 0 : text()->paragraphs().size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
pos_type DocIterator::lastpos() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
|
|
|
return inMathed() ? cell().size() : paragraph().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-20 22:06:05 +00:00
|
|
|
idx_type DocIterator::lastidx() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
return top().lastidx();
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
size_t DocIterator::nargs() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
|
|
|
// assume 1x1 grid for main text
|
2004-03-18 12:53:43 +00:00
|
|
|
return top().nargs();
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
size_t DocIterator::ncols() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
|
|
|
// assume 1x1 grid for main text
|
2004-03-18 12:53:43 +00:00
|
|
|
return top().ncols();
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
size_t DocIterator::nrows() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
|
|
|
// assume 1x1 grid for main text
|
2004-03-18 12:53:43 +00:00
|
|
|
return top().nrows();
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-20 22:06:05 +00:00
|
|
|
row_type DocIterator::row() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
return top().row();
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-20 22:06:05 +00:00
|
|
|
col_type DocIterator::col() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
return top().col();
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 21:13:01 +00:00
|
|
|
MathData & DocIterator::cell() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
// LASSERT(inMathed(), /**/);
|
2004-03-01 17:12:09 +00:00
|
|
|
return top().cell();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 21:13:01 +00:00
|
|
|
Text * DocIterator::innerText() const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2020-02-29 05:06:30 +00:00
|
|
|
LASSERT(!empty(), return nullptr);
|
2009-08-09 15:47:50 +00:00
|
|
|
return innerTextSlice().text();
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * DocIterator::innerInsetOfType(int code) const
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
for (int i = depth() - 1; i >= 0; --i)
|
|
|
|
if (slices_[i].inset_->lyxCode() == code)
|
|
|
|
return slices_[i].inset_;
|
2020-02-29 05:06:30 +00:00
|
|
|
return nullptr;
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-18 18:12:55 +00:00
|
|
|
bool DocIterator::posBackward()
|
|
|
|
{
|
|
|
|
if (pos() == 0)
|
|
|
|
return false;
|
|
|
|
--pos();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DocIterator::posForward()
|
|
|
|
{
|
|
|
|
if (pos() == lastpos())
|
|
|
|
return false;
|
|
|
|
++pos();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-12 23:08:21 +00:00
|
|
|
// This duplicates code above, but is in the critical path.
|
|
|
|
// So please think twice before adding stuff
|
|
|
|
void DocIterator::forwardPos()
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2008-01-12 23:08:21 +00:00
|
|
|
// this dog bites his tail
|
2004-03-30 08:18:09 +00:00
|
|
|
if (empty()) {
|
|
|
|
push_back(CursorSlice(*inset_));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-02-08 13:18:05 +00:00
|
|
|
CursorSlice & tip = top();
|
2004-03-25 09:16:36 +00:00
|
|
|
//lyxerr << "XXX\n" << *this << endl;
|
|
|
|
|
2008-02-29 15:29:58 +00:00
|
|
|
// not at cell/paragraph end?
|
|
|
|
if (tip.pos() != tip.lastpos()) {
|
|
|
|
// move into an inset to the right if possible
|
2020-02-29 05:06:30 +00:00
|
|
|
Inset * n = nullptr;
|
2008-02-09 10:41:49 +00:00
|
|
|
if (inMathed())
|
2005-02-08 13:18:05 +00:00
|
|
|
n = (tip.cell().begin() + tip.pos())->nucleus();
|
2008-02-09 10:41:49 +00:00
|
|
|
else
|
|
|
|
n = paragraph().getInset(tip.pos());
|
2008-02-29 15:29:58 +00:00
|
|
|
if (n && n->isActive()) {
|
|
|
|
//lyxerr << "... descend" << endl;
|
|
|
|
push_back(CursorSlice(*n));
|
|
|
|
return;
|
|
|
|
}
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2008-02-29 15:29:58 +00:00
|
|
|
// jump to the next cell/paragraph if possible
|
2007-08-13 13:36:19 +00:00
|
|
|
if (!tip.at_end()) {
|
|
|
|
tip.forwardPos();
|
2004-03-01 17:12:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-02-29 15:29:58 +00:00
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
// otherwise leave inset and jump over inset as a whole
|
2004-03-01 17:12:09 +00:00
|
|
|
pop_back();
|
2007-08-13 13:36:19 +00:00
|
|
|
// 'tip' is invalid now...
|
2006-08-13 15:29:59 +00:00
|
|
|
if (!empty())
|
|
|
|
++top().pos();
|
2005-02-14 08:17:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-12 23:08:21 +00:00
|
|
|
void DocIterator::forwardPosIgnoreCollapsed()
|
|
|
|
{
|
|
|
|
Inset * const nextinset = nextInset();
|
|
|
|
// FIXME: the check for asInsetMath() shouldn't be necessary
|
|
|
|
// but math insets do not return a sensible editable() state yet.
|
|
|
|
if (nextinset && !nextinset->asInsetMath()
|
2009-04-22 20:55:13 +00:00
|
|
|
&& !nextinset->editable()) {
|
2008-01-12 23:08:21 +00:00
|
|
|
++top().pos();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
forwardPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
void DocIterator::forwardPar()
|
2004-03-28 22:00:22 +00:00
|
|
|
{
|
|
|
|
forwardPos();
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
|
|
while (!empty() && (!inTexted() || pos() != 0)) {
|
|
|
|
if (inTexted()) {
|
|
|
|
pos_type const lastp = lastpos();
|
|
|
|
Paragraph const & par = paragraph();
|
|
|
|
pos_type & pos = top().pos();
|
2007-10-18 15:29:51 +00:00
|
|
|
if (par.insetList().empty())
|
2007-01-11 17:40:23 +00:00
|
|
|
pos = lastp;
|
|
|
|
else
|
|
|
|
while (pos < lastp && !par.isInset(pos))
|
|
|
|
++pos;
|
2005-02-25 11:55:36 +00:00
|
|
|
}
|
2004-03-28 22:00:22 +00:00
|
|
|
forwardPos();
|
2005-02-25 11:55:36 +00:00
|
|
|
}
|
2004-03-28 22:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
void DocIterator::forwardChar()
|
2004-03-25 09:16:36 +00:00
|
|
|
{
|
2004-03-28 22:00:22 +00:00
|
|
|
forwardPos();
|
2005-02-08 13:18:05 +00:00
|
|
|
while (!empty() && pos() == lastpos())
|
2004-04-03 08:37:12 +00:00
|
|
|
forwardPos();
|
2004-03-25 09:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
void DocIterator::forwardInset()
|
2004-03-27 12:37:41 +00:00
|
|
|
{
|
2004-04-03 08:37:12 +00:00
|
|
|
forwardPos();
|
2006-11-10 23:31:21 +00:00
|
|
|
|
|
|
|
while (!empty() && !nextInset()) {
|
|
|
|
if (inTexted()) {
|
|
|
|
pos_type const lastp = lastpos();
|
|
|
|
Paragraph const & par = paragraph();
|
|
|
|
pos_type & pos = top().pos();
|
|
|
|
while (pos < lastp && !par.isInset(pos))
|
|
|
|
++pos;
|
|
|
|
if (pos < lastp)
|
|
|
|
break;
|
|
|
|
}
|
2004-03-27 12:37:41 +00:00
|
|
|
forwardPos();
|
2006-11-10 23:31:21 +00:00
|
|
|
}
|
2004-03-27 12:37:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
void DocIterator::backwardChar()
|
2004-03-25 09:16:36 +00:00
|
|
|
{
|
2004-03-30 08:18:09 +00:00
|
|
|
backwardPos();
|
2005-02-08 13:18:05 +00:00
|
|
|
while (!empty() && pos() == lastpos())
|
2004-04-03 08:37:12 +00:00
|
|
|
backwardPos();
|
2004-03-30 08:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
void DocIterator::backwardPos()
|
2004-03-30 08:18:09 +00:00
|
|
|
{
|
|
|
|
//this dog bites his tail
|
|
|
|
if (empty()) {
|
|
|
|
push_back(CursorSlice(*inset_));
|
2005-02-08 13:18:05 +00:00
|
|
|
top().idx() = lastidx();
|
|
|
|
top().pit() = lastpit();
|
|
|
|
top().pos() = lastpos();
|
2004-03-30 08:18:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-29 15:29:58 +00:00
|
|
|
// at inset beginning?
|
2007-08-13 13:36:19 +00:00
|
|
|
if (top().at_begin()) {
|
2004-03-30 08:18:09 +00:00
|
|
|
pop_back();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-13 13:36:19 +00:00
|
|
|
top().backwardPos();
|
|
|
|
|
2008-02-29 15:29:58 +00:00
|
|
|
// entered another cell/paragraph from the right?
|
|
|
|
if (top().pos() == top().lastpos())
|
|
|
|
return;
|
|
|
|
|
2004-03-30 08:18:09 +00:00
|
|
|
// move into an inset to the left if possible
|
2020-02-29 05:06:30 +00:00
|
|
|
Inset * n = nullptr;
|
2008-02-09 10:41:49 +00:00
|
|
|
if (inMathed())
|
2007-08-13 13:36:19 +00:00
|
|
|
n = (top().cell().begin() + top().pos())->nucleus();
|
2008-02-09 10:41:49 +00:00
|
|
|
else
|
|
|
|
n = paragraph().getInset(top().pos());
|
2004-03-30 08:18:09 +00:00
|
|
|
if (n && n->isActive()) {
|
|
|
|
push_back(CursorSlice(*n));
|
2005-02-08 13:18:05 +00:00
|
|
|
top().idx() = lastidx();
|
|
|
|
top().pit() = lastpit();
|
|
|
|
top().pos() = lastpos();
|
2004-03-30 08:18:09 +00:00
|
|
|
}
|
2004-03-01 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-16 14:54:03 +00:00
|
|
|
void DocIterator::backwardPosIgnoreCollapsed()
|
|
|
|
{
|
|
|
|
backwardPos();
|
|
|
|
if (inTexted()) {
|
|
|
|
Inset const * ins = realInset();
|
|
|
|
if (ins && !ins->editable()) {
|
|
|
|
pop_back(); // move out of collapsed inset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-19 20:44:25 +00:00
|
|
|
#if 0
|
|
|
|
// works, but currently not needed
|
|
|
|
void DocIterator::backwardInset()
|
|
|
|
{
|
|
|
|
backwardPos();
|
|
|
|
|
|
|
|
while (!empty() && !nextInset()) {
|
|
|
|
if (inTexted()) {
|
|
|
|
pos_type const lastp = lastpos();
|
|
|
|
Paragraph const & par = paragraph();
|
|
|
|
pos_type & pos = top().pos();
|
|
|
|
while (pos > 0 && (pos == lastp || !par.isInset(pos)))
|
|
|
|
--pos;
|
|
|
|
if (pos > 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
backwardPos();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-08-14 21:03:55 +00:00
|
|
|
bool DocIterator::hasPart(DocIterator const & it) const
|
|
|
|
{
|
|
|
|
// it can't be a part if it is larger
|
2005-02-08 13:18:05 +00:00
|
|
|
if (it.depth() > depth())
|
2004-08-14 21:03:55 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// as inset adresses are the 'last' level
|
2005-02-08 13:18:05 +00:00
|
|
|
return &it.top().inset() == &slices_[it.depth() - 1].inset();
|
2004-08-14 21:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-08 09:13:32 +00:00
|
|
|
bool DocIterator::allowSpellCheck() const
|
|
|
|
{
|
|
|
|
/// spell check is disabled if the iterator position
|
|
|
|
/// is inside of an inset which disables the spell checker
|
|
|
|
size_t const n = depth();
|
|
|
|
for (size_t i = 0; i < n; ++i) {
|
|
|
|
if (!slices_[i].inset_->allowSpellCheck())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
void DocIterator::updateInsets(Inset * inset)
|
2005-10-25 09:14:11 +00:00
|
|
|
{
|
|
|
|
// this function re-creates the cache of inset pointers.
|
|
|
|
//lyxerr << "converting:\n" << *this << endl;
|
2007-11-01 10:56:18 +00:00
|
|
|
DocIterator dit = *this;
|
2005-10-25 09:14:11 +00:00
|
|
|
size_t const n = slices_.size();
|
2007-11-01 10:56:18 +00:00
|
|
|
slices_.resize(0);
|
2005-10-25 09:14:11 +00:00
|
|
|
for (size_t i = 0 ; i < n; ++i) {
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(inset);
|
2007-11-01 10:56:18 +00:00
|
|
|
push_back(dit[i]);
|
|
|
|
top().inset_ = inset;
|
2005-10-25 09:14:11 +00:00
|
|
|
if (i + 1 != n)
|
2007-11-01 10:56:18 +00:00
|
|
|
inset = nextInset();
|
2005-10-25 09:14:11 +00:00
|
|
|
}
|
|
|
|
//lyxerr << "converted:\n" << *this << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-25 23:17:24 +00:00
|
|
|
bool DocIterator::fixIfBroken()
|
|
|
|
{
|
2008-02-21 19:42:34 +00:00
|
|
|
if (empty())
|
|
|
|
return false;
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
// Go through the slice stack from the bottom.
|
2007-06-09 12:39:46 +00:00
|
|
|
// Check that all coordinates (idx, pit, pos) are correct and
|
|
|
|
// that the inset is the one which is claimed to be there
|
|
|
|
Inset * inset = &slices_[0].inset();
|
|
|
|
size_t i = 0;
|
|
|
|
size_t n = slices_.size();
|
|
|
|
for (; i != n; ++i) {
|
|
|
|
CursorSlice & cs = slices_[i];
|
2017-07-20 09:18:20 +00:00
|
|
|
if (&cs.inset() != inset || ! cs.inset().isActive()) {
|
2007-06-09 12:39:46 +00:00
|
|
|
// the whole slice is wrong, chop off this as well
|
|
|
|
--i;
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "fixIfBroken(): inset changed");
|
2007-06-09 12:39:46 +00:00
|
|
|
break;
|
|
|
|
} else if (cs.idx() > cs.lastidx()) {
|
|
|
|
cs.idx() = cs.lastidx();
|
|
|
|
cs.pit() = cs.lastpit();
|
|
|
|
cs.pos() = cs.lastpos();
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "fixIfBroken(): idx fixed");
|
2007-06-09 12:39:46 +00:00
|
|
|
break;
|
|
|
|
} else if (cs.pit() > cs.lastpit()) {
|
|
|
|
cs.pit() = cs.lastpit();
|
|
|
|
cs.pos() = cs.lastpos();
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "fixIfBroken(): pit fixed");
|
2007-06-09 12:39:46 +00:00
|
|
|
break;
|
|
|
|
} else if (cs.pos() > cs.lastpos()) {
|
|
|
|
cs.pos() = cs.lastpos();
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "fixIfBroken(): pos fixed");
|
2007-06-09 12:39:46 +00:00
|
|
|
break;
|
|
|
|
} else if (i != n - 1 && cs.pos() != cs.lastpos()) {
|
|
|
|
// get inset which is supposed to be in the next slice
|
|
|
|
if (cs.inset().inMathed())
|
|
|
|
inset = (cs.cell().begin() + cs.pos())->nucleus();
|
2008-02-09 10:41:49 +00:00
|
|
|
else if (Inset * csInset = cs.paragraph().getInset(cs.pos()))
|
|
|
|
inset = csInset;
|
2007-06-09 12:39:46 +00:00
|
|
|
else {
|
|
|
|
// there are slices left, so there must be another inset
|
|
|
|
break;
|
|
|
|
}
|
2007-05-25 23:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-09 12:39:46 +00:00
|
|
|
|
|
|
|
// Did we make it through the whole slice stack? Otherwise there
|
|
|
|
// was a problem at slice i, and we have to chop off above
|
|
|
|
if (i < n) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "fixIfBroken(): cursor chopped at " << i);
|
2007-06-09 12:39:46 +00:00
|
|
|
resize(i + 1);
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
2007-05-25 23:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-17 20:26:44 +00:00
|
|
|
void DocIterator::sanitize()
|
|
|
|
{
|
2012-08-20 15:20:59 +00:00
|
|
|
// keep a copy of the slices
|
|
|
|
vector<CursorSlice> const sl = slices_;
|
|
|
|
slices_.clear();
|
2012-07-17 20:26:44 +00:00
|
|
|
if (buffer_)
|
|
|
|
inset_ = &buffer_->inset();
|
|
|
|
Inset * inset = inset_;
|
2012-08-20 15:20:59 +00:00
|
|
|
// re-add the slices one by one, and adjust the inset pointer.
|
|
|
|
for (size_t i = 0, n = sl.size(); i != n; ++i) {
|
2020-02-29 05:06:30 +00:00
|
|
|
if (inset == nullptr) {
|
2012-07-17 20:26:44 +00:00
|
|
|
// FIXME
|
2020-04-13 10:02:26 +00:00
|
|
|
LYXERR0("Null inset on cursor stack.");
|
2012-07-17 20:26:44 +00:00
|
|
|
fixIfBroken();
|
|
|
|
break;
|
|
|
|
}
|
2015-05-22 16:16:23 +00:00
|
|
|
if (!inset->isActive()) {
|
2015-03-22 20:40:52 +00:00
|
|
|
LYXERR0("Inset found on cursor stack is not active.");
|
2015-03-09 10:14:26 +00:00
|
|
|
fixIfBroken();
|
|
|
|
break;
|
|
|
|
}
|
2012-08-20 15:20:59 +00:00
|
|
|
push_back(sl[i]);
|
|
|
|
top().inset_ = inset;
|
2012-07-17 20:26:44 +00:00
|
|
|
if (fixIfBroken())
|
|
|
|
break;
|
|
|
|
if (i + 1 != n)
|
2012-08-20 15:20:59 +00:00
|
|
|
inset = nextInset();
|
2012-07-17 20:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-26 14:59:35 +00:00
|
|
|
bool DocIterator::isInside(Inset const * p) const
|
|
|
|
{
|
|
|
|
for (CursorSlice const & sl : slices_)
|
|
|
|
if (&sl.inset() == p)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DocIterator::leaveInset(Inset const & inset)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i != slices_.size(); ++i) {
|
|
|
|
if (&slices_[i].inset() == &inset) {
|
|
|
|
resize(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-09 22:05:24 +00:00
|
|
|
int DocIterator::find(MathData const & cell) const
|
2007-11-01 10:56:18 +00:00
|
|
|
{
|
|
|
|
for (size_t l = 0; l != slices_.size(); ++l) {
|
|
|
|
if (slices_[l].asInsetMath() && &slices_[l].cell() == &cell)
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
int DocIterator::find(Inset const * inset) const
|
2007-11-01 10:56:18 +00:00
|
|
|
{
|
|
|
|
for (size_t l = 0; l != slices_.size(); ++l) {
|
2008-02-26 19:19:59 +00:00
|
|
|
if (&slices_[l].inset() == inset)
|
2007-11-01 10:56:18 +00:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-09 22:05:24 +00:00
|
|
|
void DocIterator::cutOff(int above, vector<CursorSlice> & cut)
|
2007-11-01 10:56:18 +00:00
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
cut = vector<CursorSlice>(slices_.begin() + above + 1, slices_.end());
|
2007-11-01 10:56:18 +00:00
|
|
|
slices_.resize(above + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-09 22:05:24 +00:00
|
|
|
void DocIterator::cutOff(int above)
|
2007-11-01 10:56:18 +00:00
|
|
|
{
|
|
|
|
slices_.resize(above + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
void DocIterator::append(vector<CursorSlice> const & x)
|
2007-11-01 10:56:18 +00:00
|
|
|
{
|
|
|
|
slices_.insert(slices_.end(), x.begin(), x.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-20 22:06:05 +00:00
|
|
|
void DocIterator::append(idx_type idx, pos_type pos)
|
2007-11-01 10:56:18 +00:00
|
|
|
{
|
|
|
|
slices_.push_back(CursorSlice());
|
|
|
|
top().idx() = idx;
|
|
|
|
top().pos() = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
docstring DocIterator::getPossibleLabel() const
|
|
|
|
{
|
|
|
|
return inMathed() ? from_ascii("eq:") : text()->getPossibleLabel(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Encoding const * DocIterator::getEncoding() const
|
|
|
|
{
|
|
|
|
if (empty())
|
2020-02-29 05:06:30 +00:00
|
|
|
return nullptr;
|
2018-01-26 07:37:06 +00:00
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
BufferParams const & bp = buffer()->params();
|
|
|
|
if (bp.useNonTeXFonts)
|
|
|
|
return encodings.fromLyXName("utf8-plain");
|
|
|
|
|
2019-04-18 13:20:06 +00:00
|
|
|
// With platex, we don't switch encodings (not even if forced).
|
|
|
|
if (bp.encoding().package() == Encoding::japanese)
|
|
|
|
return &bp.encoding();
|
|
|
|
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
CursorSlice const & sl = innerTextSlice();
|
|
|
|
Text const & text = *sl.text();
|
2018-01-26 07:37:06 +00:00
|
|
|
Language const * lang =
|
2020-02-07 15:03:56 +00:00
|
|
|
text.getPar(sl.pit()).getFont(bp, sl.pos(), text.outerFont(sl.pit())).language();
|
2019-03-13 10:13:44 +00:00
|
|
|
// If we have a custom encoding for the buffer, we don't switch
|
|
|
|
// encodings (see output_latex::switchEncoding())
|
2019-04-16 18:17:32 +00:00
|
|
|
bool const customenc = bp.inputenc != "auto-legacy" && bp.inputenc != "auto-legacy-plain";
|
2019-03-13 10:13:44 +00:00
|
|
|
Encoding const * enc = customenc ? &bp.encoding() : lang->encoding();
|
2018-01-26 07:37:06 +00:00
|
|
|
|
2018-01-26 07:38:52 +00:00
|
|
|
// Some insets force specific encodings sometimes (e.g., listings in
|
|
|
|
// multibyte context forces singlebyte).
|
|
|
|
if (inset().forcedEncoding(enc, encodings.fromLyXName("iso8859-1"))) {
|
|
|
|
// Get the language outside the inset
|
|
|
|
size_t const n = depth();
|
|
|
|
for (size_t i = 0; i < n; ++i) {
|
|
|
|
Text const & otext = *slices_[i].text();
|
|
|
|
Language const * olang =
|
|
|
|
otext.getPar(slices_[i].pit()).getFont(bp, slices_[i].pos(),
|
2020-02-07 15:03:56 +00:00
|
|
|
otext.outerFont(slices_[i].pit())).language();
|
2018-01-26 07:38:52 +00:00
|
|
|
Encoding const * oenc = olang->encoding();
|
|
|
|
if (oenc->name() != "inherit")
|
|
|
|
return inset().forcedEncoding(enc, oenc);
|
|
|
|
}
|
|
|
|
// Fall back to buffer encoding if no outer lang was found.
|
|
|
|
return inset().forcedEncoding(enc, &bp.encoding());
|
|
|
|
}
|
|
|
|
|
2018-01-26 07:37:06 +00:00
|
|
|
// Inherited encoding (latex_language) is determined by the context
|
|
|
|
// Look for the first outer encoding that is not itself "inherit"
|
|
|
|
if (lang->encoding()->name() == "inherit") {
|
2017-12-24 16:10:42 +00:00
|
|
|
size_t const n = depth();
|
|
|
|
for (size_t i = 0; i < n; ++i) {
|
|
|
|
Text const & otext = *slices_[i].text();
|
2018-01-26 07:37:06 +00:00
|
|
|
Language const * olang =
|
|
|
|
otext.getPar(slices_[i].pit()).getFont(bp, slices_[i].pos(),
|
2020-02-07 15:03:56 +00:00
|
|
|
otext.outerFont(slices_[i].pit())).language();
|
2018-01-26 07:37:06 +00:00
|
|
|
// Again, if we have a custom encoding, this is used
|
|
|
|
// instead of the language's.
|
2020-02-07 15:03:56 +00:00
|
|
|
Encoding const * oenc = customenc ? &bp.encoding() : olang->encoding();
|
2018-01-26 07:37:06 +00:00
|
|
|
if (olang->encoding()->name() != "inherit")
|
|
|
|
return oenc;
|
2017-12-24 16:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-26 07:37:06 +00:00
|
|
|
|
|
|
|
return enc;
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
ostream & operator<<(ostream & os, DocIterator const & dit)
|
2004-03-01 17:12:09 +00:00
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
for (size_t i = 0, n = dit.depth(); i != n; ++i)
|
|
|
|
os << " " << dit[i] << "\n";
|
2004-03-01 17:12:09 +00:00
|
|
|
return os;
|
|
|
|
}
|
2004-03-08 21:14:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
2016-06-06 19:55:39 +00:00
|
|
|
StableDocIterator::StableDocIterator(DocIterator const & dit) :
|
|
|
|
data_(dit.internalData())
|
2004-03-08 21:14:45 +00:00
|
|
|
{
|
|
|
|
for (size_t i = 0, n = data_.size(); i != n; ++i)
|
2020-02-29 05:06:30 +00:00
|
|
|
data_[i].inset_ = nullptr;
|
2004-03-08 21:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-17 11:46:07 +00:00
|
|
|
DocIterator StableDocIterator::asDocIterator(Buffer * buf) const
|
2004-03-08 21:14:45 +00:00
|
|
|
{
|
2012-08-20 15:20:59 +00:00
|
|
|
DocIterator dit(buf);
|
2012-07-17 20:26:44 +00:00
|
|
|
dit.slices_ = data_;
|
|
|
|
dit.sanitize();
|
2004-03-08 21:14:45 +00:00
|
|
|
return dit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
ostream & operator<<(ostream & os, StableDocIterator const & dit)
|
2004-03-08 21:14:45 +00:00
|
|
|
{
|
|
|
|
for (size_t i = 0, n = dit.data_.size(); i != n; ++i)
|
|
|
|
os << " " << dit.data_[i] << "\n";
|
|
|
|
return os;
|
|
|
|
}
|
2005-07-01 12:36:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool operator==(StableDocIterator const & dit1, StableDocIterator const & dit2)
|
|
|
|
{
|
|
|
|
return dit1.data_ == dit2.data_;
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|