mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 11:08:41 +00:00
replace ParagraphList::iterator by lyx::paroffset_type to prevent cursor
invalidation if the paragraphlist is changed. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7883 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
fc1437e74e
commit
dcd8fb0428
@ -270,7 +270,7 @@ bool BufferView::insertLyXFile(string const & filen)
|
||||
|
||||
text->breakParagraph(buffer()->paragraphs());
|
||||
|
||||
bool res = buffer()->readFile(fname, text->cursor.par());
|
||||
bool res = buffer()->readFile(fname, text->cursorPar());
|
||||
|
||||
resize();
|
||||
return res;
|
||||
@ -301,15 +301,10 @@ void BufferView::setCursorFromRow(int row)
|
||||
|
||||
buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
|
||||
|
||||
ParagraphList::iterator texrowpar;
|
||||
|
||||
if (tmpid == -1) {
|
||||
texrowpar = text->ownerParagraphs().begin();
|
||||
tmppos = 0;
|
||||
} else {
|
||||
texrowpar = buffer()->getParFromID(tmpid).pit();
|
||||
}
|
||||
text->setCursor(texrowpar, tmppos);
|
||||
if (tmpid == -1)
|
||||
text->setCursor(0, 0);
|
||||
else
|
||||
text->setCursor(buffer()->getParFromID(tmpid).pit(), tmppos);
|
||||
}
|
||||
|
||||
|
||||
@ -327,7 +322,9 @@ void BufferView::gotoLabel(string const & label)
|
||||
it->getLabelList(*buffer(), labels);
|
||||
if (find(labels.begin(),labels.end(),label) != labels.end()) {
|
||||
beforeChange(text);
|
||||
text->setCursor(it.getPar(), it.getPos());
|
||||
text->setCursor(
|
||||
std::distance(text->ownerParagraphs().begin(), it.getPar()),
|
||||
it.getPos());
|
||||
text->selection.cursor = text->cursor;
|
||||
update();
|
||||
return;
|
||||
@ -424,39 +421,40 @@ bool BufferView::lockInset(UpdatableInset * inset)
|
||||
{
|
||||
if (!inset)
|
||||
return false;
|
||||
|
||||
// don't relock if we're already locked
|
||||
if (theLockingInset() == inset)
|
||||
return true;
|
||||
if (!theLockingInset()) {
|
||||
// first check if it's the inset under the cursor we want lock
|
||||
// should be most of the time
|
||||
if (text->cursor.pos() < text->cursor.par()->size()
|
||||
&& text->cursor.par()->getChar(text->cursor.pos()) ==
|
||||
Paragraph::META_INSET) {
|
||||
InsetOld * in = text->cursor.par()->getInset(text->cursor.pos());
|
||||
if (inset == in) {
|
||||
|
||||
if (theLockingInset())
|
||||
return theLockingInset()->lockInsetInInset(this, inset);
|
||||
|
||||
// first check if it's the inset under the cursor we want lock
|
||||
// should be most of the time
|
||||
if (text->cursor.pos() < text->cursorPar()->size()
|
||||
&& text->cursorPar()->getChar(text->cursor.pos()) ==
|
||||
Paragraph::META_INSET) {
|
||||
if (inset == text->cursorPar()->getInset(text->cursor.pos())) {
|
||||
theLockingInset(inset);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// then do a deep look at the inset and lock the right one
|
||||
ParagraphList::iterator pit = buffer()->paragraphs().begin();
|
||||
ParagraphList::iterator pend = buffer()->paragraphs().end();
|
||||
for (int par = 0; pit != pend; ++pit, ++par) {
|
||||
InsetList::iterator it = pit->insetlist.begin();
|
||||
InsetList::iterator end = pit->insetlist.end();
|
||||
for (; it != end; ++it) {
|
||||
if (it->inset == inset) {
|
||||
text->setCursorIntern(par, it->pos);
|
||||
theLockingInset(inset);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Then do a deep look of the inset and lock the right one
|
||||
int const id = inset->id();
|
||||
ParagraphList::iterator pit = buffer()->paragraphs().begin();
|
||||
ParagraphList::iterator pend = buffer()->paragraphs().end();
|
||||
for (; pit != pend; ++pit) {
|
||||
InsetList::iterator it = pit->insetlist.begin();
|
||||
InsetList::iterator end = pit->insetlist.end();
|
||||
for (; it != end; ++it) {
|
||||
if (it->inset == inset) {
|
||||
text->setCursorIntern(pit, it->pos);
|
||||
theLockingInset(inset);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return theLockingInset()->lockInsetInInset(this, inset);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -487,7 +485,7 @@ int BufferView::unlockInset(UpdatableInset * inset)
|
||||
inset->insetUnlock(this);
|
||||
theLockingInset(0);
|
||||
// make sure we update the combo !
|
||||
owner()->setLayout(getLyXText()->cursor.par()->layout()->name());
|
||||
owner()->setLayout(getLyXText()->cursorPar()->layout()->name());
|
||||
// Tell the paragraph dialog that we changed paragraph
|
||||
dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
|
||||
finishUndo();
|
||||
@ -560,14 +558,15 @@ Language const * BufferView::getParentLanguage(InsetOld * inset) const
|
||||
|
||||
Encoding const * BufferView::getEncoding() const
|
||||
{
|
||||
LyXText * t = getLyXText();
|
||||
if (!t)
|
||||
LyXText * text = getLyXText();
|
||||
if (!text)
|
||||
return 0;
|
||||
|
||||
LyXCursor const & c = t->cursor;
|
||||
LyXFont const font = c.par()->getFont(buffer()->params(), c.pos(),
|
||||
outerFont(c.par(), t->ownerParagraphs()));
|
||||
return font.language()->encoding();
|
||||
return text->cursorPar()->getFont(
|
||||
buffer()->params(),
|
||||
text->cursor.pos(),
|
||||
outerFont(text->cursorPar(), text->ownerParagraphs())
|
||||
).language()->encoding();
|
||||
}
|
||||
|
||||
|
||||
|
@ -358,7 +358,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
|
||||
if (buffer_) {
|
||||
// Don't forget to update the Layout
|
||||
string const layoutname =
|
||||
bv_->text->cursor.par()->layout()->name();
|
||||
bv_->text->cursorPar()->layout()->name();
|
||||
owner_->setLayout(layoutname);
|
||||
}
|
||||
|
||||
@ -404,9 +404,9 @@ void BufferView::Pimpl::resizeCurrentBuffer()
|
||||
{
|
||||
lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
|
||||
|
||||
ParagraphList::iterator par;
|
||||
ParagraphList::iterator selstartpar;
|
||||
ParagraphList::iterator selendpar;
|
||||
int par = -1;
|
||||
int selstartpar = -1;
|
||||
int selendpar = -1;
|
||||
UpdatableInset * the_locking_inset = 0;
|
||||
|
||||
pos_type pos = 0;
|
||||
@ -451,17 +451,13 @@ void BufferView::Pimpl::resizeCurrentBuffer()
|
||||
bv_->text = new LyXText(bv_, 0, false, bv_->buffer()->paragraphs());
|
||||
bv_->text->init(bv_);
|
||||
}
|
||||
|
||||
par = bv_->text->ownerParagraphs().end();
|
||||
selstartpar = bv_->text->ownerParagraphs().end();
|
||||
selendpar = bv_->text->ownerParagraphs().end();
|
||||
}
|
||||
|
||||
#warning does not help much
|
||||
//bv_->text->redoParagraphs(bv_->text->ownerParagraphs().begin(),
|
||||
// bv_->text->ownerParagraphs().end());
|
||||
|
||||
if (par != bv_->text->ownerParagraphs().end()) {
|
||||
if (par != -1) {
|
||||
bv_->text->selection.set(true);
|
||||
// At this point just to avoid the Delete-Empty-Paragraph-
|
||||
// Mechanism when setting the cursor.
|
||||
@ -699,8 +695,8 @@ Change const BufferView::Pimpl::getCurrentChange()
|
||||
if (!text->selection.set())
|
||||
return Change(Change::UNCHANGED);
|
||||
|
||||
LyXCursor const & cur = text->selection.start;
|
||||
return cur.par()->lookupChangeFull(cur.pos());
|
||||
return text->getPar(text->selection.start)
|
||||
->lookupChangeFull(text->selection.start.pos());
|
||||
}
|
||||
|
||||
|
||||
@ -715,7 +711,7 @@ void BufferView::Pimpl::savePosition(unsigned int i)
|
||||
if (i >= saved_positions_num)
|
||||
return;
|
||||
saved_positions[i] = Position(buffer_->fileName(),
|
||||
bv_->text->cursor.par()->id(),
|
||||
bv_->text->cursorPar()->id(),
|
||||
bv_->text->cursor.pos());
|
||||
if (i > 0)
|
||||
owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i)));
|
||||
@ -732,14 +728,14 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
|
||||
beforeChange(bv_->text);
|
||||
|
||||
if (fname != buffer_->fileName()) {
|
||||
Buffer * b;
|
||||
Buffer * b = 0;
|
||||
if (bufferlist.exists(fname))
|
||||
b = bufferlist.getBuffer(fname);
|
||||
else {
|
||||
b = bufferlist.newBuffer(fname);
|
||||
::loadLyXFile(b, fname); // don't ask, just load it
|
||||
}
|
||||
if (b != 0)
|
||||
if (b)
|
||||
buffer(b);
|
||||
}
|
||||
|
||||
@ -837,7 +833,7 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
|
||||
LyXCursor cursor = bv_->getLyXText()->cursor;
|
||||
Buffer::inset_iterator it =
|
||||
find_if(Buffer::inset_iterator(
|
||||
cursor.par(), cursor.pos()),
|
||||
cursorPar(), cursor.pos()),
|
||||
buffer_->inset_iterator_end(),
|
||||
lyx::compare_memfun(&Inset::lyxCode, code));
|
||||
return it != buffer_->inset_iterator_end() ? (*it) : 0;
|
||||
@ -846,22 +842,22 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
|
||||
// should work for now. Better infrastructure is coming. (Lgb)
|
||||
|
||||
Buffer * b = bv_->buffer();
|
||||
LyXCursor cursor = bv_->getLyXText()->cursor;
|
||||
LyXText * text = bv_->getLyXText();
|
||||
|
||||
Buffer::inset_iterator beg = b->inset_iterator_begin();
|
||||
Buffer::inset_iterator end = b->inset_iterator_end();
|
||||
|
||||
bool cursor_par_seen = false;
|
||||
bool cursorPar_seen = false;
|
||||
|
||||
for (; beg != end; ++beg) {
|
||||
if (beg.getPar() == cursor.par()) {
|
||||
cursor_par_seen = true;
|
||||
if (beg.getPar() == text->cursorPar()) {
|
||||
cursorPar_seen = true;
|
||||
}
|
||||
if (cursor_par_seen) {
|
||||
if (beg.getPar() == cursor.par()
|
||||
&& beg.getPos() >= cursor.pos()) {
|
||||
if (cursorPar_seen) {
|
||||
if (beg.getPar() == text->cursorPar()
|
||||
&& beg.getPos() >= text->cursor.pos()) {
|
||||
break;
|
||||
} else if (beg.getPar() != cursor.par()) {
|
||||
} else if (beg.getPar() != text->cursorPar()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -948,7 +944,7 @@ void BufferView::Pimpl::trackChanges()
|
||||
buf->undostack().clear();
|
||||
} else {
|
||||
update();
|
||||
bv_->text->setCursor(buf->paragraphs().begin(), 0);
|
||||
bv_->text->setCursor(0, 0);
|
||||
#warning changes FIXME
|
||||
//moveCursorUpdate(false);
|
||||
|
||||
@ -1227,7 +1223,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
|
||||
|
||||
case LFUN_LAYOUT_PARAGRAPH: {
|
||||
string data;
|
||||
params2string(*bv_->getLyXText()->cursor.par(), data);
|
||||
params2string(*bv_->getLyXText()->cursorPar(), data);
|
||||
|
||||
data = "show\n" + data;
|
||||
bv_->owner()->getDialogs().show("paragraph", data);
|
||||
@ -1237,7 +1233,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
|
||||
case LFUN_PARAGRAPH_UPDATE: {
|
||||
if (!bv_->owner()->getDialogs().visible("paragraph"))
|
||||
break;
|
||||
Paragraph const & par = *bv_->getLyXText()->cursor.par();
|
||||
Paragraph const & par = *bv_->getLyXText()->cursorPar();
|
||||
|
||||
string data;
|
||||
params2string(par, data);
|
||||
@ -1286,7 +1282,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
|
||||
break;
|
||||
|
||||
case LFUN_ACCEPT_ALL_CHANGES: {
|
||||
bv_->text->setCursor(bv_->buffer()->paragraphs().begin(), 0);
|
||||
bv_->text->setCursor(0, 0);
|
||||
#warning FIXME changes
|
||||
//moveCursorUpdate(false);
|
||||
|
||||
@ -1298,7 +1294,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
|
||||
}
|
||||
|
||||
case LFUN_REJECT_ALL_CHANGES: {
|
||||
bv_->text->setCursor(bv_->buffer()->paragraphs().begin(), 0);
|
||||
bv_->text->setCursor(0, 0);
|
||||
#warning FIXME changes
|
||||
//moveCursorUpdate(false);
|
||||
|
||||
@ -1351,7 +1347,7 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
|
||||
if (!lout.empty()) {
|
||||
bv_->text->breakParagraph(bv_->buffer()->paragraphs());
|
||||
|
||||
if (!bv_->text->cursor.par()->empty()) {
|
||||
if (!bv_->text->cursorPar()->empty()) {
|
||||
bv_->text->cursorLeft(bv_);
|
||||
bv_->text->breakParagraph(bv_->buffer()->paragraphs());
|
||||
}
|
||||
@ -1396,7 +1392,7 @@ void BufferView::Pimpl::updateInset(InsetOld const * inset)
|
||||
bv_->text->redoParagraph(outerPar(*bv_->buffer(), inset));
|
||||
|
||||
// this should not be needed, but it is...
|
||||
// bv_->text->redoParagraph(bv_->text->cursor.par());
|
||||
// bv_->text->redoParagraph(bv_->text->cursorPar());
|
||||
// bv_->text->fullRebreak();
|
||||
|
||||
update();
|
||||
@ -1433,10 +1429,10 @@ bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code,
|
||||
// FIXME
|
||||
|
||||
// The test it.size()==1 was needed to prevent crashes.
|
||||
// How to set the cursor corretly when it.size()>1 ??
|
||||
// How to set the cursor correctly when it.size()>1 ??
|
||||
if (it.size() == 1) {
|
||||
bv_->text->setCursorIntern(it.pit(), 0);
|
||||
bv_->text->redoParagraph(bv_->text->cursor.par());
|
||||
bv_->text->setCursorIntern(bv_->text->parOffset(it.pit()), 0);
|
||||
bv_->text->redoParagraph(bv_->text->cursorPar());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,23 @@
|
||||
|
||||
2003-10-09 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
* lyxcursor.h: use paroffset_type instead of ParagraphList::iterator
|
||||
|
||||
* BufferView.C:
|
||||
* BufferView_pimpl.C:
|
||||
* bufferview_funcs.C:
|
||||
* lyx_cb.C:
|
||||
* lyxcursor.C:
|
||||
* lyxfind.C:
|
||||
* lyxfunc.C:
|
||||
* lyxtext.h:
|
||||
* text.C:
|
||||
* text2.C:
|
||||
* text3.C:
|
||||
* text_funcs.[Ch]:
|
||||
* textcursor.[Ch]:
|
||||
* undo_funcs.C: adjust
|
||||
|
||||
2003-10-08 Lars Gullik Bjønnes <larsbj@gullik.net>
|
||||
|
||||
* text2.C (incrementItemDepth): new function, use a backtracking
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
#include "support/types.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class InsetOld;
|
||||
class BufferView;
|
||||
|
||||
|
@ -301,19 +301,18 @@ string const currentState(BufferView * bv)
|
||||
|
||||
LyXText * text = bv->getLyXText();
|
||||
Buffer * buffer = bv->buffer();
|
||||
LyXCursor const & c(text->cursor);
|
||||
LyXCursor const & c = text->cursor;
|
||||
|
||||
bool const show_change = buffer->params().tracking_changes
|
||||
&& c.pos() != c.par()->size()
|
||||
&& c.par()->lookupChange(c.pos()) != Change::UNCHANGED;
|
||||
&& text->cursor.pos() != text->cursorPar()->size()
|
||||
&& text->cursorPar()->lookupChange(c.pos()) != Change::UNCHANGED;
|
||||
|
||||
if (show_change) {
|
||||
Change change(c.par()->lookupChangeFull(c.pos()));
|
||||
Author const & a(bv->buffer()->params().authors().get(change.author));
|
||||
Change change = text->cursorPar()->lookupChangeFull(c.pos());
|
||||
Author const & a = bv->buffer()->params().authors().get(change.author);
|
||||
state << _("Change: ") << a.name();
|
||||
if (!a.email().empty()) {
|
||||
if (!a.email().empty())
|
||||
state << " (" << a.email() << ")";
|
||||
}
|
||||
if (change.changetime)
|
||||
state << _(" at ") << ctime(&change.changetime);
|
||||
state << " : ";
|
||||
@ -322,9 +321,7 @@ string const currentState(BufferView * bv)
|
||||
// I think we should only show changes from the default
|
||||
// font. (Asger)
|
||||
LyXFont font = text->real_current_font;
|
||||
LyXFont const & defaultfont =
|
||||
buffer->params().getLyXTextClass().defaultfont();
|
||||
font.reduce(defaultfont);
|
||||
font.reduce(buffer->params().getLyXTextClass().defaultfont());
|
||||
|
||||
// avoid _(...) re-entrance problem
|
||||
string const s = font.stateText(&buffer->params());
|
||||
@ -339,9 +336,9 @@ string const currentState(BufferView * bv)
|
||||
|
||||
// The paragraph spacing, but only if different from
|
||||
// buffer spacing.
|
||||
if (!text->cursor.par()->params().spacing().isDefault()) {
|
||||
if (!text->cursorPar()->params().spacing().isDefault()) {
|
||||
Spacing::Space cur_space =
|
||||
text->cursor.par()->params().spacing().getSpace();
|
||||
text->cursorPar()->params().spacing().getSpace();
|
||||
state << _(", Spacing: ");
|
||||
|
||||
switch (cur_space) {
|
||||
@ -356,7 +353,7 @@ string const currentState(BufferView * bv)
|
||||
break;
|
||||
case Spacing::Other:
|
||||
state << _("Other (")
|
||||
<< text->cursor.par()->params().spacing().getValue()
|
||||
<< text->cursorPar()->params().spacing().getValue()
|
||||
<< ')';
|
||||
break;
|
||||
case Spacing::Default:
|
||||
@ -365,12 +362,12 @@ string const currentState(BufferView * bv)
|
||||
}
|
||||
}
|
||||
#ifdef DEVEL_VERSION
|
||||
state << _(", Paragraph: ") << text->cursor.par()->id();
|
||||
state << _(", Paragraph: ") << text->cursorPar()->id();
|
||||
state << _(", Position: ") << text->cursor.pos();
|
||||
RowList::iterator rit = text->cursorRow();
|
||||
state << bformat(_(", Row b:%1$d e:%2$d"), rit->pos(), rit->end());
|
||||
state << _(", Inset: ");
|
||||
InsetOld * inset = text->cursor.par()->inInset();
|
||||
InsetOld * inset = text->cursorPar()->inInset();
|
||||
if (inset)
|
||||
state << inset << " id: " << inset->id()
|
||||
<< " text: " << inset->getLyXText(bv, true)
|
||||
@ -402,10 +399,10 @@ void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
|
||||
if (font.language() != ignore_language ||
|
||||
font.number() != LyXFont::IGNORE) {
|
||||
LyXCursor & cursor = text->cursor;
|
||||
text->computeBidiTables(text->cursor.par(), *bv->buffer(),
|
||||
text->computeBidiTables(text->cursorPar(), *bv->buffer(),
|
||||
text->cursorRow());
|
||||
if (cursor.boundary() !=
|
||||
text->isBoundary(*bv->buffer(), *cursor.par(), cursor.pos(),
|
||||
text->isBoundary(*bv->buffer(), *text->cursorPar(), cursor.pos(),
|
||||
text->real_current_font))
|
||||
text->setCursor(cursor.par(), cursor.pos(),
|
||||
false, !cursor.boundary());
|
||||
|
@ -149,7 +149,7 @@ void LyXView::updateLayoutChoice()
|
||||
}
|
||||
|
||||
string const & layout =
|
||||
bufferview_->getLyXText()->cursor.par()->layout()->name();
|
||||
bufferview_->getLyXText()->cursorPar()->layout()->name();
|
||||
|
||||
if (layout != current_layout) {
|
||||
toolbar_->setLayout(layout);
|
||||
|
@ -32,8 +32,7 @@ void ControlErrorList::clearParams()
|
||||
{}
|
||||
|
||||
|
||||
ErrorList const &
|
||||
ControlErrorList::errorList() const
|
||||
ErrorList const & ControlErrorList::errorList() const
|
||||
{
|
||||
return errorlist_;
|
||||
}
|
||||
|
@ -334,20 +334,18 @@ void InsetText::insetUnlock(BufferView * bv)
|
||||
no_selection = true;
|
||||
locked = false;
|
||||
|
||||
if (text_.selection.set()) {
|
||||
if (text_.selection.set())
|
||||
text_.clearSelection();
|
||||
} else if (owner()) {
|
||||
else if (owner())
|
||||
bv->owner()->setLayout(owner()->getLyXText(bv)
|
||||
->cursor.par()->layout()->name());
|
||||
} else
|
||||
bv->owner()->setLayout(bv->text->cursor.par()->layout()->name());
|
||||
->cursorPar()->layout()->name());
|
||||
else
|
||||
bv->owner()->setLayout(bv->text->cursorPar()->layout()->name());
|
||||
// hack for deleteEmptyParMech
|
||||
ParagraphList::iterator first_par = paragraphs.begin();
|
||||
if (!first_par->empty()) {
|
||||
text_.setCursor(first_par, 0);
|
||||
} else if (paragraphs.size() > 1) {
|
||||
text_.setCursor(boost::next(first_par), 0);
|
||||
}
|
||||
if (!paragraphs.begin()->empty())
|
||||
text_.setCursor(0, 0);
|
||||
else if (paragraphs.size() > 1)
|
||||
text_.setCursor(1, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -359,7 +357,7 @@ void InsetText::lockInset(BufferView * bv)
|
||||
inset_boundary = false;
|
||||
inset_par = paragraphs.end();
|
||||
old_par = paragraphs.end();
|
||||
text_.setCursorIntern(paragraphs.begin(), 0);
|
||||
text_.setCursorIntern(0, 0);
|
||||
text_.clearSelection();
|
||||
finishUndo();
|
||||
// If the inset is empty set the language of the current font to the
|
||||
@ -400,7 +398,8 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
|
||||
for (; it != end; ++it) {
|
||||
if (it->inset == inset) {
|
||||
lyxerr << "InsetText::lockInsetInInset: 1 a" << endl;
|
||||
text_.setCursorIntern(pit, it->pos);
|
||||
text_.setCursorIntern(
|
||||
std::distance(paragraphs.begin(), pit), it->pos);
|
||||
lyxerr << "InsetText::lockInsetInInset: 1 b" << endl;
|
||||
lyxerr << "bv: " << bv << " inset: " << inset << endl;
|
||||
lockInset(bv, inset);
|
||||
@ -630,11 +629,9 @@ InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd)
|
||||
|
||||
if (cmd.argument.size()) {
|
||||
if (cmd.argument == "left")
|
||||
text_.setCursorIntern(paragraphs.begin(), 0);
|
||||
else {
|
||||
ParagraphList::iterator it = boost::prior(paragraphs.end());
|
||||
text_.setCursor(it, it->size());
|
||||
}
|
||||
text_.setCursorIntern(0, 0);
|
||||
else
|
||||
text_.setCursor(paragraphs.size() - 1, paragraphs.back().size());
|
||||
} else {
|
||||
int tmp_y = (cmd.y < 0) ? 0 : cmd.y;
|
||||
// we put here -1 and not button as now the button in the
|
||||
@ -751,7 +748,7 @@ InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd)
|
||||
* true (on). */
|
||||
#if 0
|
||||
// This should not be needed here and is also WRONG!
|
||||
recordUndo(bv, Undo::INSERT, text_.cursor.par());
|
||||
recordUndo(bv, Undo::INSERT, text_.cursorPar());
|
||||
#endif
|
||||
bv->switchKeyMap();
|
||||
|
||||
@ -1201,7 +1198,7 @@ void InsetText::fitInsetCursor(BufferView * bv) const
|
||||
|
||||
InsetOld::RESULT InsetText::moveRight(BufferView * bv)
|
||||
{
|
||||
if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params()))
|
||||
if (text_.cursorPar()->isRightToLeftPar(bv->buffer()->params()))
|
||||
return moveLeftIntern(bv, false, true, false);
|
||||
else
|
||||
return moveRightIntern(bv, true, true, false);
|
||||
@ -1210,7 +1207,7 @@ InsetOld::RESULT InsetText::moveRight(BufferView * bv)
|
||||
|
||||
InsetOld::RESULT InsetText::moveLeft(BufferView * bv)
|
||||
{
|
||||
if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params()))
|
||||
if (text_.cursorPar()->isRightToLeftPar(bv->buffer()->params()))
|
||||
return moveRightIntern(bv, true, true, false);
|
||||
else
|
||||
return moveLeftIntern(bv, false, true, false);
|
||||
@ -1358,7 +1355,7 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
|
||||
|
||||
|
||||
if (text_.selection.set())
|
||||
recordUndo(bv, Undo::ATOMIC, text_.cursor.par());
|
||||
recordUndo(bv, Undo::ATOMIC, text_.cursorPar());
|
||||
|
||||
if (selectall) {
|
||||
text_.cursorTop();
|
||||
@ -1479,7 +1476,7 @@ int InsetText::cx() const
|
||||
{
|
||||
int x = text_.cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
|
||||
if (the_locking_inset) {
|
||||
LyXFont font = text_.getFont(text_.cursor.par(), text_.cursor.pos());
|
||||
LyXFont font = text_.getFont(text_.cursorPar(), text_.cursor.pos());
|
||||
if (font.isVisibleRightToLeft())
|
||||
x -= the_locking_inset->width();
|
||||
}
|
||||
@ -1501,7 +1498,7 @@ pos_type InsetText::cpos() const
|
||||
|
||||
ParagraphList::iterator InsetText::cpar() const
|
||||
{
|
||||
return text_.cursor.par();
|
||||
return text_.cursorPar();
|
||||
}
|
||||
|
||||
|
||||
@ -1722,8 +1719,7 @@ bool InsetText::searchBackward(BufferView * bv, string const & str,
|
||||
return true;
|
||||
}
|
||||
if (!locked) {
|
||||
ParagraphList::iterator pit = boost::prior(paragraphs.end());
|
||||
text_.setCursor(pit, pit->size());
|
||||
text_.setCursor(paragraphs.size() - 1, paragraphs.back().size());
|
||||
}
|
||||
lyx::find::SearchResult result =
|
||||
lyx::find::find(bv, &text_, str, false, cs, mw);
|
||||
@ -1750,30 +1746,30 @@ bool InsetText::checkInsertChar(LyXFont & font)
|
||||
void InsetText::collapseParagraphs(BufferView * bv)
|
||||
{
|
||||
while (paragraphs.size() > 1) {
|
||||
ParagraphList::iterator first_par = paragraphs.begin();
|
||||
ParagraphList::iterator next_par = boost::next(first_par);
|
||||
size_t const first_par_size = first_par->size();
|
||||
ParagraphList::iterator const first = paragraphs.begin();
|
||||
ParagraphList::iterator second = first;
|
||||
advance(second, 1);
|
||||
size_t const first_par_size = first->size();
|
||||
|
||||
if (!first_par->empty() &&
|
||||
!next_par->empty() &&
|
||||
!first_par->isSeparator(first_par_size - 1)) {
|
||||
first_par->insertChar(first_par_size, ' ');
|
||||
if (!first->empty() &&
|
||||
!second->empty() &&
|
||||
!first->isSeparator(first_par_size - 1)) {
|
||||
first->insertChar(first_par_size, ' ');
|
||||
}
|
||||
|
||||
#warning probably broken
|
||||
if (text_.selection.set()) {
|
||||
if (text_.selection.start.par() == next_par) {
|
||||
text_.selection.start.par(first_par);
|
||||
text_.selection.start.pos(
|
||||
text_.selection.start.pos() + first_par_size);
|
||||
if (text_.selection.start.par() == 1) {
|
||||
text_.selection.start.par(1);
|
||||
text_.selection.start.pos(text_.selection.start.pos() + first_par_size);
|
||||
}
|
||||
if (text_.selection.end.par() == next_par) {
|
||||
text_.selection.end.par(first_par);
|
||||
text_.selection.end.pos(
|
||||
text_.selection.end.pos() + first_par_size);
|
||||
if (text_.selection.end.par() == 2) {
|
||||
text_.selection.end.par(1);
|
||||
text_.selection.end.pos(text_.selection.end.pos() + first_par_size);
|
||||
}
|
||||
}
|
||||
|
||||
mergeParagraph(bv->buffer()->params(), paragraphs, first_par);
|
||||
mergeParagraph(bv->buffer()->params(), paragraphs, first);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -427,7 +427,7 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap
|
||||
|
||||
string const getPossibleLabel(BufferView const & bv)
|
||||
{
|
||||
ParagraphList::iterator pit = bv.getLyXText()->cursor.par();
|
||||
ParagraphList::iterator pit = bv.getLyXText()->cursorPar();
|
||||
ParagraphList & plist = bv.getLyXText()->ownerParagraphs();
|
||||
|
||||
LyXLayout_ptr layout = pit->layout();
|
||||
|
@ -17,18 +17,17 @@
|
||||
|
||||
|
||||
LyXCursor::LyXCursor()
|
||||
: par_(), pos_(0), boundary_(false),
|
||||
x_(0), x_fix_(0), y_(0)
|
||||
: par_(-1), pos_(0), boundary_(false), x_(0), x_fix_(0), y_(0)
|
||||
{}
|
||||
|
||||
|
||||
void LyXCursor::par(ParagraphList::iterator pit)
|
||||
void LyXCursor::par(lyx::paroffset_type par)
|
||||
{
|
||||
par_ = pit;
|
||||
par_ = par;
|
||||
}
|
||||
|
||||
|
||||
ParagraphList::iterator LyXCursor::par() const
|
||||
lyx::paroffset_type LyXCursor::par() const
|
||||
{
|
||||
return par_;
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
#ifndef LYXCURSOR_H
|
||||
#define LYXCURSOR_H
|
||||
|
||||
#include "ParagraphList_fwd.h"
|
||||
#include "support/types.h"
|
||||
|
||||
/**
|
||||
@ -31,9 +30,9 @@ class LyXCursor {
|
||||
public:
|
||||
LyXCursor();
|
||||
/// set the paragraph that contains this cursor
|
||||
void par(ParagraphList::iterator pit);
|
||||
void par(lyx::paroffset_type pit);
|
||||
/// return the paragraph this cursor is in
|
||||
ParagraphList::iterator par() const;
|
||||
lyx::paroffset_type par() const;
|
||||
/// set the position within the paragraph
|
||||
void pos(lyx::pos_type p);
|
||||
/// return the position within the paragraph
|
||||
@ -68,7 +67,7 @@ public:
|
||||
|
||||
private:
|
||||
/// The paragraph the cursor is in.
|
||||
ParagraphList::iterator par_;
|
||||
lyx::paroffset_type par_;
|
||||
/// The position inside the paragraph
|
||||
lyx::pos_type pos_;
|
||||
/**
|
||||
|
@ -31,10 +31,10 @@ using lyx::support::uppercase;
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
namespace find {
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// returns true if the specified string is at the specified position
|
||||
@ -45,7 +45,7 @@ bool isStringInText(Paragraph const & par, pos_type pos,
|
||||
string::size_type size = str.length();
|
||||
pos_type i = 0;
|
||||
pos_type parsize = par.size();
|
||||
while (((pos + i) < parsize)
|
||||
while ((pos + i < parsize)
|
||||
&& (string::size_type(i) < size)
|
||||
&& (cs ? (str[i] == par.getChar(pos + i))
|
||||
: (uppercase(str[i]) == uppercase(par.getChar(pos + i))))) {
|
||||
@ -71,7 +71,7 @@ bool isStringInText(Paragraph const & par, pos_type pos,
|
||||
SearchResult searchForward(BufferView * bv, LyXText * text, string const & str,
|
||||
bool const & cs, bool const & mw)
|
||||
{
|
||||
ParagraphList::iterator pit = text->cursor.par();
|
||||
ParagraphList::iterator pit = text->cursorPar();
|
||||
ParagraphList::iterator pend = text->ownerParagraphs().end();
|
||||
pos_type pos = text->cursor.pos();
|
||||
UpdatableInset * inset;
|
||||
@ -93,8 +93,8 @@ SearchResult searchForward(BufferView * bv, LyXText * text, string const & str,
|
||||
if (pit != pend) {
|
||||
text->setCursor(pit, pos);
|
||||
return SR_FOUND;
|
||||
} else
|
||||
return SR_NOT_FOUND;
|
||||
}
|
||||
return SR_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ SearchResult searchBackward(BufferView * bv, LyXText * text,
|
||||
string const & str,
|
||||
bool const & cs, bool const & mw)
|
||||
{
|
||||
ParagraphList::iterator pit = text->cursor.par();
|
||||
ParagraphList::iterator pit = text->cursorPar();
|
||||
ParagraphList::iterator pbegin = text->ownerParagraphs().begin();
|
||||
pos_type pos = text->cursor.pos();
|
||||
|
||||
@ -150,6 +150,7 @@ SearchResult searchBackward(BufferView * bv, LyXText * text,
|
||||
} // anon namespace
|
||||
|
||||
|
||||
|
||||
int replace(BufferView * bv,
|
||||
string const & searchstr, string const & replacestr,
|
||||
bool forward, bool casesens, bool matchwrd, bool replaceall,
|
||||
@ -303,7 +304,7 @@ SearchResult find(BufferView * bv, LyXText * text,
|
||||
|
||||
SearchResult nextChange(BufferView * bv, LyXText * text, pos_type & length)
|
||||
{
|
||||
ParagraphList::iterator pit = text->cursor.par();
|
||||
ParagraphList::iterator pit = text->cursorPar();
|
||||
ParagraphList::iterator pend = text->ownerParagraphs().end();
|
||||
pos_type pos = text->cursor.pos();
|
||||
|
||||
|
@ -372,13 +372,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
|
||||
|
||||
case LFUN_LAYOUT:
|
||||
case LFUN_LAYOUT_PARAGRAPH: {
|
||||
InsetOld * inset = view()->getLyXText()->cursor.par()->inInset();
|
||||
InsetOld * inset = view()->getLyXText()->cursorPar()->inInset();
|
||||
disable = inset && inset->forceDefaultParagraphs(inset);
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_INSET_OPTARG:
|
||||
disable = (view()->getLyXText()->cursor.par()->layout()->optionalargs == 0);
|
||||
disable = (view()->getLyXText()->cursorPar()->layout()->optionalargs == 0);
|
||||
break;
|
||||
|
||||
case LFUN_TABULAR_FEATURE:
|
||||
@ -736,7 +736,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
|
||||
flag.setOnOff(buf->isReadonly());
|
||||
break;
|
||||
case LFUN_APPENDIX:
|
||||
flag.setOnOff(view()->getLyXText()->cursor.par()->params().startOfAppendix());
|
||||
flag.setOnOff(view()->getLyXText()->cursorPar()->params().startOfAppendix());
|
||||
break;
|
||||
case LFUN_SWITCHBUFFER:
|
||||
// toggle on the current buffer, but do not toggle off
|
||||
@ -911,7 +911,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
|
||||
int dummy_y;
|
||||
inset->getCursorPos(view(), inset_x, dummy_y);
|
||||
#endif
|
||||
if ((action == LFUN_UNKNOWN_ACTION)
|
||||
if (action == LFUN_UNKNOWN_ACTION
|
||||
&& argument.empty()) {
|
||||
argument = encoded_last_key;
|
||||
}
|
||||
@ -1003,14 +1003,14 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
|
||||
owner->view_state_changed();
|
||||
break;
|
||||
case LFUN_RIGHT:
|
||||
if (!view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
|
||||
if (!view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) {
|
||||
view()->text->cursorRight(view());
|
||||
moveCursorUpdate();
|
||||
owner->view_state_changed();
|
||||
}
|
||||
goto exit_with_message;
|
||||
case LFUN_LEFT:
|
||||
if (view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params())) {
|
||||
if (view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) {
|
||||
view()->text->cursorRight(view());
|
||||
moveCursorUpdate();
|
||||
owner->view_state_changed();
|
||||
|
@ -170,10 +170,18 @@ private:
|
||||
RowList::iterator
|
||||
getRow(ParagraphList::iterator pit, lyx::pos_type pos) const;
|
||||
public:
|
||||
/// returns a pointer cursor row
|
||||
/// returns an iterator pointing to a cursor row
|
||||
RowList::iterator getRow(LyXCursor const & cursor) const;
|
||||
/// convenience
|
||||
RowList::iterator cursorRow() const;
|
||||
/// returns an iterator pointing to a cursor paragraph
|
||||
ParagraphList::iterator getPar(LyXCursor const & cursor) const;
|
||||
///
|
||||
ParagraphList::iterator getPar(lyx::paroffset_type par) const;
|
||||
///
|
||||
int parOffset(ParagraphList::iterator pit) const;
|
||||
/// convenience
|
||||
ParagraphList::iterator cursorPar() const;
|
||||
/**
|
||||
* Return the next row, when cursor is at the end of the
|
||||
* previous row, for insets that take a full row.
|
||||
@ -223,17 +231,19 @@ public:
|
||||
void selectSelectedWord();
|
||||
/// re-computes the cached coordinates in the cursor
|
||||
void redoCursor();
|
||||
///
|
||||
void setCursor(ParagraphList::iterator pit, lyx::pos_type pos);
|
||||
/// returns true if par was empty and was removed
|
||||
bool setCursor(ParagraphList::iterator pit,
|
||||
bool setCursor(lyx::paroffset_type par,
|
||||
lyx::pos_type pos,
|
||||
bool setfont = true,
|
||||
bool boundary = false);
|
||||
///
|
||||
void setCursor(LyXCursor &, ParagraphList::iterator pit,
|
||||
void setCursor(LyXCursor &, lyx::paroffset_type par,
|
||||
lyx::pos_type pos,
|
||||
bool boundary = false);
|
||||
///
|
||||
void setCursorIntern(ParagraphList::iterator pit,
|
||||
void setCursorIntern(lyx::paroffset_type par,
|
||||
lyx::pos_type pos,
|
||||
bool setfont = true,
|
||||
bool boundary = false);
|
||||
@ -494,6 +504,9 @@ public:
|
||||
void previousRow(ParagraphList::iterator & pit,
|
||||
RowList::iterator & rit) const;
|
||||
|
||||
///
|
||||
std::string selectionAsString(Buffer const & buffer, bool label) const;
|
||||
|
||||
private:
|
||||
/** Cursor related data.
|
||||
Later this variable has to be removed. There should be now internal
|
||||
|
@ -16,28 +16,29 @@
|
||||
#ifndef LYX_TYPES_H
|
||||
#define LYX_TYPES_H
|
||||
|
||||
// this probably could be improved by using <cstddef>...
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
|
||||
namespace lyx
|
||||
{
|
||||
/// a type for positions used in paragraphs
|
||||
// needs to be signed for a while to hold the special value -1 that is
|
||||
// used there...
|
||||
typedef std::vector<char>::difference_type pos_type;
|
||||
typedef ptrdiff_t pos_type;
|
||||
|
||||
/// a type for paragraph offsets
|
||||
typedef ptrdiff_t paroffset_type;
|
||||
|
||||
/// a type for the nesting depth of a paragraph
|
||||
typedef unsigned int depth_type;
|
||||
typedef size_t depth_type;
|
||||
|
||||
// set this to '0' if you want to have really safe types
|
||||
#if 1
|
||||
|
||||
/// a type for sizes
|
||||
typedef std::vector<char>::size_type size_type;
|
||||
typedef size_t size_type;
|
||||
|
||||
/// a type used for numbering text classes
|
||||
// used to be LyXTextClassList::size_type
|
||||
typedef std::vector<char>::size_type textclass_type;
|
||||
typedef size_t textclass_type;
|
||||
|
||||
#else
|
||||
|
||||
@ -47,7 +48,7 @@ namespace lyx
|
||||
|
||||
struct size_type {
|
||||
///
|
||||
typedef std::vector<char>::size_type base_type;
|
||||
typedef size_t base_type;
|
||||
///
|
||||
size_type(base_type t) { data_ = t; }
|
||||
///
|
||||
@ -59,7 +60,7 @@ namespace lyx
|
||||
|
||||
struct textclass_type {
|
||||
///
|
||||
typedef std::vector<char>::size_type base_type;
|
||||
typedef size_t base_type;
|
||||
///
|
||||
textclass_type(base_type t) { data_ = t; }
|
||||
///
|
||||
|
@ -383,9 +383,6 @@ void LyXTabular::init(BufferParams const & bp, int rows_arg, int columns_arg)
|
||||
|
||||
void LyXTabular::fixCellNums()
|
||||
{
|
||||
BOOST_ASSERT(rows_ == row_info.size());
|
||||
BOOST_ASSERT(columns_ == column_info.size());
|
||||
BOOST_ASSERT(rows_ == cell_info.size());
|
||||
int cellno = 0;
|
||||
for (int i = 0; i < rows_; ++i) {
|
||||
for (int j = 0; j < columns_; ++j) {
|
||||
@ -396,19 +393,17 @@ void LyXTabular::fixCellNums()
|
||||
}
|
||||
|
||||
set_row_column_number_info();
|
||||
BOOST_ASSERT(rows_ == row_info.size());
|
||||
BOOST_ASSERT(columns_ == column_info.size());
|
||||
BOOST_ASSERT(rows_ == cell_info.size());
|
||||
}
|
||||
|
||||
|
||||
void LyXTabular::setOwner(InsetTabular * inset)
|
||||
{
|
||||
for (int i = 0; i < rows_; ++i)
|
||||
for (int i = 0; i < rows_; ++i) {
|
||||
for (int j = 0; j < columns_; ++j) {
|
||||
cell_info[i][j].inset.setOwner(inset);
|
||||
cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
295
src/text.C
295
src/text.C
@ -1192,28 +1192,28 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
|
||||
void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
||||
{
|
||||
// allow only if at start or end, or all previous is new text
|
||||
if (cursor.pos() && cursor.pos() != cursor.par()->size()
|
||||
&& cursor.par()->isChangeEdited(0, cursor.pos()))
|
||||
if (cursor.pos() && cursor.pos() != cursorPar()->size()
|
||||
&& cursorPar()->isChangeEdited(0, cursor.pos()))
|
||||
return;
|
||||
|
||||
LyXTextClass const & tclass =
|
||||
bv()->buffer()->params().getLyXTextClass();
|
||||
LyXLayout_ptr const & layout = cursor.par()->layout();
|
||||
LyXLayout_ptr const & layout = cursorPar()->layout();
|
||||
|
||||
// this is only allowed, if the current paragraph is not empty or caption
|
||||
// and if it has not the keepempty flag active
|
||||
if (cursor.par()->empty() && !cursor.par()->allowEmpty()
|
||||
if (cursorPar()->empty() && !cursorPar()->allowEmpty()
|
||||
&& layout->labeltype != LABEL_SENSITIVE)
|
||||
return;
|
||||
|
||||
recordUndo(bv(), Undo::ATOMIC, cursor.par());
|
||||
recordUndo(bv(), Undo::ATOMIC, cursorPar());
|
||||
|
||||
// Always break behind a space
|
||||
//
|
||||
// It is better to erase the space (Dekel)
|
||||
if (cursor.pos() < cursor.par()->size()
|
||||
&& cursor.par()->isLineSeparator(cursor.pos()))
|
||||
cursor.par()->erase(cursor.pos());
|
||||
if (cursor.pos() < cursorPar()->size()
|
||||
&& cursorPar()->isLineSeparator(cursor.pos()))
|
||||
cursorPar()->erase(cursor.pos());
|
||||
|
||||
// break the paragraph
|
||||
if (keep_layout)
|
||||
@ -1225,21 +1225,21 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
||||
// breakParagraph call should return a bool if it inserts the
|
||||
// paragraph before or behind and we should react on that one
|
||||
// but we can fix this in 1.3.0 (Jug 20020509)
|
||||
bool const isempty = (cursor.par()->allowEmpty() && cursor.par()->empty());
|
||||
::breakParagraph(bv()->buffer()->params(), paragraphs, cursor.par(),
|
||||
bool const isempty = (cursorPar()->allowEmpty() && cursorPar()->empty());
|
||||
::breakParagraph(bv()->buffer()->params(), paragraphs, cursorPar(),
|
||||
cursor.pos(), keep_layout);
|
||||
|
||||
#warning Trouble Point! (Lgb)
|
||||
// When ::breakParagraph is called from within an inset we must
|
||||
// ensure that the correct ParagraphList is used. Today that is not
|
||||
// the case and the Buffer::paragraphs is used. Not good. (Lgb)
|
||||
ParagraphList::iterator next_par = boost::next(cursor.par());
|
||||
ParagraphList::iterator next_par = boost::next(cursorPar());
|
||||
|
||||
// well this is the caption hack since one caption is really enough
|
||||
if (layout->labeltype == LABEL_SENSITIVE) {
|
||||
if (!cursor.pos())
|
||||
// set to standard-layout
|
||||
cursor.par()->applyLayout(tclass.defaultLayout());
|
||||
cursorPar()->applyLayout(tclass.defaultLayout());
|
||||
else
|
||||
// set to standard-layout
|
||||
next_par->applyLayout(tclass.defaultLayout());
|
||||
@ -1250,7 +1250,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
||||
// This touches only the screen-update. Otherwise we would may have
|
||||
// an empty row on the screen
|
||||
if (cursor.pos() && cursorRow()->pos() == cursor.pos()
|
||||
&& !cursor.par()->isNewline(cursor.pos() - 1))
|
||||
&& !cursorPar()->isNewline(cursor.pos() - 1))
|
||||
{
|
||||
cursorLeft(bv());
|
||||
}
|
||||
@ -1259,7 +1259,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
||||
next_par->erase(0);
|
||||
|
||||
updateCounters();
|
||||
redoParagraph(cursor.par());
|
||||
redoParagraph(cursorPar());
|
||||
redoParagraph(next_par);
|
||||
|
||||
// This check is necessary. Otherwise the new empty paragraph will
|
||||
@ -1267,7 +1267,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
||||
if (cursor.pos() || isempty)
|
||||
setCursor(next_par, 0);
|
||||
else
|
||||
setCursor(cursor.par(), 0);
|
||||
setCursor(cursorPar(), 0);
|
||||
}
|
||||
|
||||
|
||||
@ -1275,7 +1275,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
||||
void LyXText::redoParagraph()
|
||||
{
|
||||
clearSelection();
|
||||
redoParagraph(cursor.par());
|
||||
redoParagraph(cursorPar());
|
||||
setCursorIntern(cursor.par(), cursor.pos());
|
||||
}
|
||||
|
||||
@ -1284,13 +1284,13 @@ void LyXText::redoParagraph()
|
||||
// same Paragraph one to the right and make a rebreak
|
||||
void LyXText::insertChar(char c)
|
||||
{
|
||||
recordUndo(bv(), Undo::INSERT, cursor.par());
|
||||
recordUndo(bv(), Undo::INSERT, cursorPar());
|
||||
|
||||
// When the free-spacing option is set for the current layout,
|
||||
// disable the double-space checking
|
||||
|
||||
bool const freeSpacing = cursor.par()->layout()->free_spacing ||
|
||||
cursor.par()->isFreeSpacing();
|
||||
bool const freeSpacing = cursorPar()->layout()->free_spacing ||
|
||||
cursorPar()->isFreeSpacing();
|
||||
|
||||
if (lyxrc.auto_number) {
|
||||
static string const number_operators = "+-/*";
|
||||
@ -1301,9 +1301,9 @@ void LyXText::insertChar(char c)
|
||||
if (!IsDigit(c) && !contains(number_operators, c) &&
|
||||
!(contains(number_seperators, c) &&
|
||||
cursor.pos() >= 1 &&
|
||||
cursor.pos() < cursor.par()->size() &&
|
||||
getFont(cursor.par(), cursor.pos()).number() == LyXFont::ON &&
|
||||
getFont(cursor.par(), cursor.pos() - 1).number() == LyXFont::ON)
|
||||
cursor.pos() < cursorPar()->size() &&
|
||||
getFont(cursorPar(), cursor.pos()).number() == LyXFont::ON &&
|
||||
getFont(cursorPar(), cursor.pos() - 1).number() == LyXFont::ON)
|
||||
)
|
||||
number(bv()); // Set current_font.number to OFF
|
||||
} else if (IsDigit(c) &&
|
||||
@ -1311,23 +1311,23 @@ void LyXText::insertChar(char c)
|
||||
number(bv()); // Set current_font.number to ON
|
||||
|
||||
if (cursor.pos() > 0) {
|
||||
char const c = cursor.par()->getChar(cursor.pos() - 1);
|
||||
char const c = cursorPar()->getChar(cursor.pos() - 1);
|
||||
if (contains(number_unary_operators, c) &&
|
||||
(cursor.pos() == 1 ||
|
||||
cursor.par()->isSeparator(cursor.pos() - 2) ||
|
||||
cursor.par()->isNewline(cursor.pos() - 2))
|
||||
cursorPar()->isSeparator(cursor.pos() - 2) ||
|
||||
cursorPar()->isNewline(cursor.pos() - 2))
|
||||
) {
|
||||
setCharFont(
|
||||
cursor.par(),
|
||||
cursorPar(),
|
||||
cursor.pos() - 1,
|
||||
current_font);
|
||||
} else if (contains(number_seperators, c) &&
|
||||
cursor.pos() >= 2 &&
|
||||
getFont(
|
||||
cursor.par(),
|
||||
cursorPar(),
|
||||
cursor.pos() - 2).number() == LyXFont::ON) {
|
||||
setCharFont(
|
||||
cursor.par(),
|
||||
cursorPar(),
|
||||
cursor.pos() - 1,
|
||||
current_font);
|
||||
}
|
||||
@ -1354,9 +1354,9 @@ void LyXText::insertChar(char c)
|
||||
|
||||
if (!freeSpacing && IsLineSeparatorChar(c)) {
|
||||
if ((cursor.pos() > 0
|
||||
&& cursor.par()->isLineSeparator(cursor.pos() - 1))
|
||||
&& cursorPar()->isLineSeparator(cursor.pos() - 1))
|
||||
|| (cursor.pos() > 0
|
||||
&& cursor.par()->isNewline(cursor.pos() - 1))
|
||||
&& cursorPar()->isNewline(cursor.pos() - 1))
|
||||
|| (cursor.pos() == 0)) {
|
||||
static bool sent_space_message = false;
|
||||
if (!sent_space_message) {
|
||||
@ -1373,13 +1373,13 @@ void LyXText::insertChar(char c)
|
||||
|
||||
// Here case LyXText::InsertInset already inserted the character
|
||||
if (c != Paragraph::META_INSET)
|
||||
cursor.par()->insertChar(cursor.pos(), c);
|
||||
cursorPar()->insertChar(cursor.pos(), c);
|
||||
|
||||
setCharFont(cursor.par(), cursor.pos(), rawtmpfont);
|
||||
setCharFont(cursorPar(), cursor.pos(), rawtmpfont);
|
||||
|
||||
current_font = rawtmpfont;
|
||||
real_current_font = realtmpfont;
|
||||
redoParagraph(cursor.par());
|
||||
redoParagraph(cursorPar());
|
||||
setCursor(cursor.par(), cursor.pos() + 1, false, cursor.boundary());
|
||||
|
||||
charInserted();
|
||||
@ -1518,8 +1518,8 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit,
|
||||
|
||||
void LyXText::cursorRightOneWord()
|
||||
{
|
||||
::cursorRightOneWord(cursor, ownerParagraphs());
|
||||
setCursor(cursor.par(), cursor.pos());
|
||||
::cursorRightOneWord(*this, cursor, ownerParagraphs());
|
||||
setCursor(cursorPar(), cursor.pos());
|
||||
}
|
||||
|
||||
|
||||
@ -1528,8 +1528,8 @@ void LyXText::cursorRightOneWord()
|
||||
void LyXText::cursorLeftOneWord()
|
||||
{
|
||||
LyXCursor tmpcursor = cursor;
|
||||
::cursorLeftOneWord(tmpcursor, ownerParagraphs());
|
||||
setCursor(tmpcursor.par(), tmpcursor.pos());
|
||||
::cursorLeftOneWord(*this, tmpcursor, ownerParagraphs());
|
||||
setCursor(getPar(tmpcursor), tmpcursor.pos());
|
||||
}
|
||||
|
||||
|
||||
@ -1537,7 +1537,7 @@ void LyXText::selectWord(word_location loc)
|
||||
{
|
||||
LyXCursor from = cursor;
|
||||
LyXCursor to;
|
||||
::getWord(from, to, loc, ownerParagraphs());
|
||||
::getWord(*this, from, to, loc, ownerParagraphs());
|
||||
if (cursor != from)
|
||||
setCursor(from.par(), from.pos());
|
||||
if (to == from)
|
||||
@ -1562,17 +1562,17 @@ bool LyXText::selectWordWhenUnderCursor(word_location loc)
|
||||
|
||||
void LyXText::acceptChange()
|
||||
{
|
||||
if (!selection.set() && cursor.par()->size())
|
||||
if (!selection.set() && cursorPar()->size())
|
||||
return;
|
||||
|
||||
if (selection.start.par() == selection.end.par()) {
|
||||
LyXCursor & startc = selection.start;
|
||||
LyXCursor & endc = selection.end;
|
||||
recordUndo(bv(), Undo::INSERT, startc.par());
|
||||
startc.par()->acceptChange(startc.pos(), endc.pos());
|
||||
recordUndo(bv(), Undo::INSERT, getPar(startc));
|
||||
getPar(startc)->acceptChange(startc.pos(), endc.pos());
|
||||
finishUndo();
|
||||
clearSelection();
|
||||
redoParagraph(startc.par());
|
||||
redoParagraph(getPar(startc));
|
||||
setCursorIntern(startc.par(), 0);
|
||||
}
|
||||
#warning handle multi par selection
|
||||
@ -1581,17 +1581,17 @@ void LyXText::acceptChange()
|
||||
|
||||
void LyXText::rejectChange()
|
||||
{
|
||||
if (!selection.set() && cursor.par()->size())
|
||||
if (!selection.set() && cursorPar()->size())
|
||||
return;
|
||||
|
||||
if (selection.start.par() == selection.end.par()) {
|
||||
LyXCursor & startc = selection.start;
|
||||
LyXCursor & endc = selection.end;
|
||||
recordUndo(bv(), Undo::INSERT, startc.par());
|
||||
startc.par()->rejectChange(startc.pos(), endc.pos());
|
||||
recordUndo(bv(), Undo::INSERT, getPar(startc));
|
||||
getPar(startc)->rejectChange(startc.pos(), endc.pos());
|
||||
finishUndo();
|
||||
clearSelection();
|
||||
redoParagraph(startc.par());
|
||||
redoParagraph(getPar(startc));
|
||||
setCursorIntern(startc.par(), 0);
|
||||
}
|
||||
#warning handle multi par selection
|
||||
@ -1600,8 +1600,7 @@ void LyXText::rejectChange()
|
||||
|
||||
// This function is only used by the spellchecker for NextWord().
|
||||
// It doesn't handle LYX_ACCENTs and probably never will.
|
||||
WordLangTuple const
|
||||
LyXText::selectNextWordToSpellcheck(float & value)
|
||||
WordLangTuple const LyXText::selectNextWordToSpellcheck(float & value)
|
||||
{
|
||||
if (the_locking_inset) {
|
||||
WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
|
||||
@ -1611,33 +1610,33 @@ LyXText::selectNextWordToSpellcheck(float & value)
|
||||
return word;
|
||||
}
|
||||
// we have to go on checking so move cursor to the next char
|
||||
if (cursor.pos() == cursor.par()->size()) {
|
||||
if (boost::next(cursor.par()) == ownerParagraphs().end())
|
||||
if (cursor.pos() == cursorPar()->size()) {
|
||||
if (cursor.par() + 1 == int(ownerParagraphs().size()))
|
||||
return word;
|
||||
cursor.par(boost::next(cursor.par()));
|
||||
cursor.par(cursor.par() + 1);
|
||||
cursor.pos(0);
|
||||
} else
|
||||
cursor.pos(cursor.pos() + 1);
|
||||
cursor.pos(cursor.pos() + 1);
|
||||
}
|
||||
ParagraphList::iterator tmppit = cursor.par();
|
||||
int const tmppar = cursor.par();
|
||||
|
||||
// If this is not the very first word, skip rest of
|
||||
// current word because we are probably in the middle
|
||||
// of a word if there is text here.
|
||||
if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
|
||||
while (cursor.pos() < cursor.par()->size()
|
||||
&& cursor.par()->isLetter(cursor.pos()))
|
||||
if (cursor.pos() || cursor.par() != 0) {
|
||||
while (cursor.pos() < cursorPar()->size()
|
||||
&& cursorPar()->isLetter(cursor.pos()))
|
||||
cursor.pos(cursor.pos() + 1);
|
||||
}
|
||||
|
||||
// Now, skip until we have real text (will jump paragraphs)
|
||||
while (true) {
|
||||
ParagraphList::iterator cpit = cursor.par();
|
||||
pos_type const cpos(cursor.pos());
|
||||
ParagraphList::iterator cpit = cursorPar();
|
||||
pos_type const cpos = cursor.pos();
|
||||
|
||||
if (cpos == cpit->size()) {
|
||||
if (boost::next(cpit) != ownerParagraphs().end()) {
|
||||
cursor.par(boost::next(cpit));
|
||||
if (cursor.par() + 1 != int(ownerParagraphs().size())) {
|
||||
cursor.par(cursor.par() + 1);
|
||||
cursor.pos(0);
|
||||
continue;
|
||||
}
|
||||
@ -1655,18 +1654,18 @@ LyXText::selectNextWordToSpellcheck(float & value)
|
||||
}
|
||||
|
||||
// now check if we hit an inset so it has to be a inset containing text!
|
||||
if (cursor.pos() < cursor.par()->size() &&
|
||||
cursor.par()->isInset(cursor.pos())) {
|
||||
if (cursor.pos() < cursorPar()->size() &&
|
||||
cursorPar()->isInset(cursor.pos())) {
|
||||
// lock the inset!
|
||||
FuncRequest cmd(bv(), LFUN_INSET_EDIT, "left");
|
||||
cursor.par()->getInset(cursor.pos())->localDispatch(cmd);
|
||||
cursorPar()->getInset(cursor.pos())->localDispatch(cmd);
|
||||
// now call us again to do the above trick
|
||||
// but obviously we have to start from down below ;)
|
||||
return bv()->text->selectNextWordToSpellcheck(value);
|
||||
}
|
||||
|
||||
// Update the value if we changed paragraphs
|
||||
if (cursor.par() != tmppit) {
|
||||
if (cursor.par() != tmppar) {
|
||||
setCursor(cursor.par(), cursor.pos());
|
||||
value = float(cursor.y())/float(height);
|
||||
}
|
||||
@ -1674,12 +1673,12 @@ LyXText::selectNextWordToSpellcheck(float & value)
|
||||
// Start the selection from here
|
||||
selection.cursor = cursor;
|
||||
|
||||
string lang_code = getFont(cursor.par(), cursor.pos()).language()->code();
|
||||
string lang_code = getFont(cursorPar(), cursor.pos()).language()->code();
|
||||
// and find the end of the word (insets like optional hyphens
|
||||
// and ligature break are part of a word)
|
||||
while (cursor.pos() < cursor.par()->size()
|
||||
&& cursor.par()->isLetter(cursor.pos())
|
||||
&& !isDeletedText(*cursor.par(), cursor.pos()))
|
||||
while (cursor.pos() < cursorPar()->size()
|
||||
&& cursorPar()->isLetter(cursor.pos())
|
||||
&& !isDeletedText(*cursorPar(), cursor.pos()))
|
||||
cursor.pos(cursor.pos() + 1);
|
||||
|
||||
// Finally, we copy the word to a string and return it
|
||||
@ -1687,8 +1686,8 @@ LyXText::selectNextWordToSpellcheck(float & value)
|
||||
if (selection.cursor.pos() < cursor.pos()) {
|
||||
pos_type i;
|
||||
for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
|
||||
if (!cursor.par()->isInset(i))
|
||||
str += cursor.par()->getChar(i);
|
||||
if (!cursorPar()->isInset(i))
|
||||
str += cursorPar()->getChar(i);
|
||||
}
|
||||
}
|
||||
return WordLangTuple(str, lang_code);
|
||||
@ -1709,11 +1708,11 @@ void LyXText::selectSelectedWord()
|
||||
selection.cursor = cursor;
|
||||
|
||||
// now find the end of the word
|
||||
while (cursor.pos() < cursor.par()->size()
|
||||
&& cursor.par()->isLetter(cursor.pos()))
|
||||
while (cursor.pos() < cursorPar()->size()
|
||||
&& cursorPar()->isLetter(cursor.pos()))
|
||||
cursor.pos(cursor.pos() + 1);
|
||||
|
||||
setCursor(cursor.par(), cursor.pos());
|
||||
setCursor(cursorPar(), cursor.pos());
|
||||
|
||||
// finally set the selection
|
||||
setSelection();
|
||||
@ -1723,7 +1722,7 @@ void LyXText::selectSelectedWord()
|
||||
// Delete from cursor up to the end of the current or next word.
|
||||
void LyXText::deleteWordForward()
|
||||
{
|
||||
if (cursor.par()->empty())
|
||||
if (cursorPar()->empty())
|
||||
cursorRight(bv());
|
||||
else {
|
||||
LyXCursor tmpcursor = cursor;
|
||||
@ -1743,7 +1742,7 @@ void LyXText::deleteWordForward()
|
||||
// Delete from cursor to start of current or prior word.
|
||||
void LyXText::deleteWordBackward()
|
||||
{
|
||||
if (cursor.par()->empty())
|
||||
if (cursorPar()->empty())
|
||||
cursorLeft(bv());
|
||||
else {
|
||||
LyXCursor tmpcursor = cursor;
|
||||
@ -1761,7 +1760,7 @@ void LyXText::deleteWordBackward()
|
||||
// Kill to end of line.
|
||||
void LyXText::deleteLineForward()
|
||||
{
|
||||
if (cursor.par()->empty())
|
||||
if (cursorPar()->empty())
|
||||
// Paragraph is empty, so we just go to the right
|
||||
cursorRight(bv());
|
||||
else {
|
||||
@ -1794,19 +1793,20 @@ void LyXText::changeCase(LyXText::TextCase action)
|
||||
to = selection.end;
|
||||
} else {
|
||||
from = cursor;
|
||||
::getWord(from, to, lyx::PARTIAL_WORD, ownerParagraphs());
|
||||
::getWord(*this, from, to, lyx::PARTIAL_WORD, ownerParagraphs());
|
||||
setCursor(to.par(), to.pos() + 1);
|
||||
}
|
||||
|
||||
recordUndo(bv(), Undo::ATOMIC, from.par(), to.par());
|
||||
recordUndo(bv(), Undo::ATOMIC, getPar(from), getPar(to));
|
||||
|
||||
pos_type pos = from.pos();
|
||||
ParagraphList::iterator pit = from.par();
|
||||
int par = from.par();
|
||||
|
||||
while (pit != ownerParagraphs().end() &&
|
||||
(pos != to.pos() || pit != to.par())) {
|
||||
while (par != int(ownerParagraphs().size()) &&
|
||||
(pos != to.pos() || par != to.par())) {
|
||||
ParagraphList::iterator pit = getPar(par);
|
||||
if (pos == pit->size()) {
|
||||
++pit;
|
||||
++par;
|
||||
pos = 0;
|
||||
continue;
|
||||
}
|
||||
@ -1837,23 +1837,21 @@ void LyXText::Delete()
|
||||
// this is a very easy implementation
|
||||
|
||||
LyXCursor old_cursor = cursor;
|
||||
int const old_cur_par_id = old_cursor.par()->id();
|
||||
int const old_cur_par_id = cursorPar()->id();
|
||||
int const old_cur_par_prev_id =
|
||||
(old_cursor.par() != ownerParagraphs().begin() ?
|
||||
boost::prior(old_cursor.par())->id() : -1);
|
||||
old_cursor.par() ? getPar(old_cursor.par() - 1)->id() : -1;
|
||||
|
||||
// just move to the right
|
||||
cursorRight(bv());
|
||||
|
||||
// CHECK Look at the comment here.
|
||||
// This check is not very good...
|
||||
// The cursorRightIntern calls DeleteEmptyParagrapgMechanism
|
||||
// The cursorRightIntern calls DeleteEmptyParagraphMechanism
|
||||
// and that can very well delete the par or par->previous in
|
||||
// old_cursor. Will a solution where we compare paragraph id's
|
||||
//work better?
|
||||
if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
|
||||
== old_cur_par_prev_id
|
||||
&& cursor.par()->id() != old_cur_par_id) {
|
||||
int iid = cursor.par() ? getPar(cursor.par() - 1)->id() : -1;
|
||||
if (iid == old_cur_par_prev_id && cursorPar()->id() != old_cur_par_id) {
|
||||
// delete-empty-paragraph-mechanism has done it
|
||||
return;
|
||||
}
|
||||
@ -1863,7 +1861,7 @@ void LyXText::Delete()
|
||||
LyXCursor tmpcursor = cursor;
|
||||
// to make sure undo gets the right cursor position
|
||||
cursor = old_cursor;
|
||||
recordUndo(bv(), Undo::DELETE, cursor.par());
|
||||
recordUndo(bv(), Undo::DELETE, cursorPar());
|
||||
cursor = tmpcursor;
|
||||
backspace();
|
||||
}
|
||||
@ -1873,36 +1871,36 @@ void LyXText::Delete()
|
||||
void LyXText::backspace()
|
||||
{
|
||||
// Get the font that is used to calculate the baselineskip
|
||||
pos_type lastpos = cursor.par()->size();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type lastpos = pit->size();
|
||||
|
||||
if (cursor.pos() == 0) {
|
||||
// The cursor is at the beginning of a paragraph,
|
||||
// so the the backspace will collapse two paragraphs into one.
|
||||
|
||||
// but it's not allowed unless it's new
|
||||
if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
|
||||
if (pit->isChangeEdited(0, pit->size()))
|
||||
return;
|
||||
|
||||
// we may paste some paragraphs
|
||||
|
||||
// is it an empty paragraph?
|
||||
|
||||
if (lastpos == 0
|
||||
|| (lastpos == 1 && cursor.par()->isSeparator(0))) {
|
||||
if (lastpos == 0 || (lastpos == 1 && pit->isSeparator(0))) {
|
||||
// This is an empty paragraph and we delete it just
|
||||
// by moving the cursor one step
|
||||
// left and let the DeleteEmptyParagraphMechanism
|
||||
// handle the actual deletion of the paragraph.
|
||||
|
||||
if (cursor.par() != ownerParagraphs().begin()) {
|
||||
ParagraphList::iterator tmppit = boost::prior(cursor.par());
|
||||
if (cursor.par()->layout() == tmppit->layout()
|
||||
&& cursor.par()->getAlign() == tmppit->getAlign()) {
|
||||
if (cursor.par()) {
|
||||
ParagraphList::iterator tmppit = getPar(cursor.par() - 1);
|
||||
if (cursorPar()->layout() == tmppit->layout()
|
||||
&& cursorPar()->getAlign() == tmppit->getAlign()) {
|
||||
// Inherit bottom DTD from the paragraph below.
|
||||
// (the one we are deleting)
|
||||
tmppit->params().lineBottom(cursor.par()->params().lineBottom());
|
||||
tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
|
||||
tmppit->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
|
||||
tmppit->params().lineBottom(cursorPar()->params().lineBottom());
|
||||
tmppit->params().spaceBottom(cursorPar()->params().spaceBottom());
|
||||
tmppit->params().pagebreakBottom(cursorPar()->params().pagebreakBottom());
|
||||
}
|
||||
|
||||
cursorLeft(bv());
|
||||
@ -1913,21 +1911,21 @@ void LyXText::backspace()
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor.par() != ownerParagraphs().begin()) {
|
||||
if (cursorPar() != ownerParagraphs().begin()) {
|
||||
recordUndo(bv(), Undo::DELETE,
|
||||
boost::prior(cursor.par()),
|
||||
cursor.par());
|
||||
boost::prior(cursorPar()),
|
||||
cursorPar());
|
||||
}
|
||||
|
||||
ParagraphList::iterator tmppit = cursor.par();
|
||||
ParagraphList::iterator tmppit = cursorPar();
|
||||
// We used to do cursorLeftIntern() here, but it is
|
||||
// not a good idea since it triggers the auto-delete
|
||||
// mechanism. So we do a cursorLeftIntern()-lite,
|
||||
// without the dreaded mechanism. (JMarc)
|
||||
if (cursor.par() != ownerParagraphs().begin()) {
|
||||
if (cursor.par() != 0) {
|
||||
// steps into the above paragraph.
|
||||
setCursorIntern(boost::prior(cursor.par()),
|
||||
boost::prior(cursor.par())->size(),
|
||||
setCursorIntern(cursor.par() - 1,
|
||||
getPar(cursor.par() - 1)->size(),
|
||||
false);
|
||||
}
|
||||
|
||||
@ -1939,14 +1937,14 @@ void LyXText::backspace()
|
||||
BufferParams const & bufparams = buf.params();
|
||||
LyXTextClass const & tclass = bufparams.getLyXTextClass();
|
||||
|
||||
if (cursor.par() != tmppit
|
||||
&& (cursor.par()->layout() == tmppit->layout()
|
||||
if (cursorPar() != tmppit
|
||||
&& (cursorPar()->layout() == tmppit->layout()
|
||||
|| tmppit->layout() == tclass.defaultLayout())
|
||||
&& cursor.par()->getAlign() == tmppit->getAlign()) {
|
||||
&& cursorPar()->getAlign() == tmppit->getAlign()) {
|
||||
mergeParagraph(bufparams,
|
||||
buf.paragraphs(), cursor.par());
|
||||
buf.paragraphs(), cursorPar());
|
||||
|
||||
if (cursor.pos() && cursor.par()->isSeparator(cursor.pos() - 1))
|
||||
if (cursor.pos() && cursorPar()->isSeparator(cursor.pos() - 1))
|
||||
cursor.pos(cursor.pos() - 1);
|
||||
|
||||
// the row may have changed, block, hfills etc.
|
||||
@ -1956,17 +1954,17 @@ void LyXText::backspace()
|
||||
} else {
|
||||
// this is the code for a normal backspace, not pasting
|
||||
// any paragraphs
|
||||
recordUndo(bv(), Undo::DELETE, cursor.par());
|
||||
recordUndo(bv(), Undo::DELETE, cursorPar());
|
||||
// We used to do cursorLeftIntern() here, but it is
|
||||
// not a good idea since it triggers the auto-delete
|
||||
// mechanism. So we do a cursorLeftIntern()-lite,
|
||||
// without the dreaded mechanism. (JMarc)
|
||||
setCursorIntern(cursor.par(), cursor.pos() - 1,
|
||||
false, cursor.boundary());
|
||||
cursor.par()->erase(cursor.pos());
|
||||
cursorPar()->erase(cursor.pos());
|
||||
}
|
||||
|
||||
lastpos = cursor.par()->size();
|
||||
lastpos = cursorPar()->size();
|
||||
if (cursor.pos() == lastpos)
|
||||
setCurrentFont();
|
||||
|
||||
@ -1975,15 +1973,36 @@ void LyXText::backspace()
|
||||
}
|
||||
|
||||
|
||||
ParagraphList::iterator LyXText::cursorPar() const
|
||||
{
|
||||
return getPar(cursor.par());
|
||||
}
|
||||
|
||||
|
||||
ParagraphList::iterator LyXText::getPar(LyXCursor const & cur) const
|
||||
{
|
||||
return getPar(cur.par());
|
||||
}
|
||||
|
||||
|
||||
ParagraphList::iterator LyXText::getPar(int par) const
|
||||
{
|
||||
ParagraphList::iterator pit = ownerParagraphs().begin();
|
||||
std::advance(pit, par);
|
||||
return pit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RowList::iterator LyXText::cursorRow() const
|
||||
{
|
||||
return getRow(cursor.par(), cursor.pos());
|
||||
return getRow(cursorPar(), cursor.pos());
|
||||
}
|
||||
|
||||
|
||||
RowList::iterator LyXText::getRow(LyXCursor const & cur) const
|
||||
{
|
||||
return getRow(cur.par(), cur.pos());
|
||||
return getRow(getPar(cur), cur.pos());
|
||||
}
|
||||
|
||||
|
||||
@ -2003,7 +2022,7 @@ LyXText::getRow(ParagraphList::iterator pit, pos_type pos) const
|
||||
// returns pointer to some fancy row 'below' specified row
|
||||
RowList::iterator LyXText::cursorIRow() const
|
||||
{
|
||||
return getRow(cursor.par(), cursor.pos());
|
||||
return getRow(cursorPar(), cursor.pos());
|
||||
}
|
||||
|
||||
|
||||
@ -2026,7 +2045,7 @@ RowList::iterator LyXText::getRowNearY(int y,
|
||||
|
||||
int LyXText::getDepth() const
|
||||
{
|
||||
return cursor.par()->getDepth();
|
||||
return cursorPar()->getDepth();
|
||||
}
|
||||
|
||||
|
||||
@ -2073,3 +2092,39 @@ void LyXText::previousRow(ParagraphList::iterator & pit,
|
||||
rit = boost::prior(pit->rows.end());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string LyXText::selectionAsString(Buffer const & buffer, bool label) const
|
||||
{
|
||||
if (!selection.set())
|
||||
return string();
|
||||
|
||||
// should be const ...
|
||||
ParagraphList::iterator startpit = getPar(selection.start);
|
||||
ParagraphList::iterator endpit = getPar(selection.end);
|
||||
size_t const startpos = selection.start.pos();
|
||||
size_t const endpos = selection.end.pos();
|
||||
|
||||
if (startpit == endpit)
|
||||
return startpit->asString(buffer, startpos, endpos, label);
|
||||
|
||||
// First paragraph in selection
|
||||
string result =
|
||||
startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
|
||||
|
||||
// The paragraphs in between (if any)
|
||||
ParagraphList::iterator pit = startpit;
|
||||
for (++pit; pit != endpit; ++pit)
|
||||
result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
|
||||
|
||||
// Last paragraph in selection
|
||||
result += endpit->asString(buffer, 0, endpos, label);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int LyXText::parOffset(ParagraphList::iterator pit) const
|
||||
{
|
||||
return std::distance(ownerParagraphs().begin(), pit);
|
||||
}
|
||||
|
208
src/text2.C
208
src/text2.C
@ -61,6 +61,7 @@
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
using lyx::pos_type;
|
||||
using lyx::paroffset_type;
|
||||
using lyx::support::bformat;
|
||||
|
||||
using std::endl;
|
||||
@ -94,7 +95,7 @@ void LyXText::init(BufferView * bview)
|
||||
current_font = getFont(beg, 0);
|
||||
|
||||
redoParagraphs(beg, end);
|
||||
setCursorIntern(beg, 0);
|
||||
setCursorIntern(0, 0);
|
||||
selection.cursor = cursor;
|
||||
|
||||
updateCounters();
|
||||
@ -247,7 +248,7 @@ void LyXText::setCharFont(
|
||||
|
||||
InsetOld * LyXText::getInset() const
|
||||
{
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type const pos = cursor.pos();
|
||||
|
||||
if (pos < pit->size() && pit->isInset(pos)) {
|
||||
@ -313,7 +314,7 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
|
||||
LyXCursor & send_cur,
|
||||
string const & layout)
|
||||
{
|
||||
ParagraphList::iterator endpit = boost::next(send_cur.par());
|
||||
ParagraphList::iterator endpit = boost::next(getPar(send_cur));
|
||||
ParagraphList::iterator undoendpit = endpit;
|
||||
ParagraphList::iterator pars_end = ownerParagraphs().end();
|
||||
|
||||
@ -327,13 +328,13 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
|
||||
++endpit;
|
||||
}
|
||||
|
||||
recordUndo(bv(), Undo::ATOMIC, sstart_cur.par(), boost::prior(undoendpit));
|
||||
recordUndo(bv(), Undo::ATOMIC, getPar(sstart_cur), boost::prior(undoendpit));
|
||||
|
||||
// ok we have a selection. This is always between sstart_cur
|
||||
// and sel_end cursor
|
||||
cur = sstart_cur;
|
||||
ParagraphList::iterator pit = sstart_cur.par();
|
||||
ParagraphList::iterator epit = boost::next(send_cur.par());
|
||||
ParagraphList::iterator pit = getPar(sstart_cur);
|
||||
ParagraphList::iterator epit = boost::next(getPar(send_cur));
|
||||
|
||||
BufferParams const & bufparams = bv()->buffer()->params();
|
||||
LyXLayout_ptr const & lyxlayout =
|
||||
@ -350,7 +351,7 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
|
||||
: VSpace(VSpace::NONE));
|
||||
if (lyxlayout->margintype == MARGIN_MANUAL)
|
||||
pit->setLabelWidthString(lyxlayout->labelstring());
|
||||
cur.par(pit);
|
||||
cur.par(std::distance(ownerParagraphs().begin(), pit));
|
||||
++pit;
|
||||
} while (pit != epit);
|
||||
|
||||
@ -391,7 +392,7 @@ void LyXText::setLayout(string const & layout)
|
||||
|
||||
ParagraphList::iterator endpit = setLayout(cursor, selection.start,
|
||||
selection.end, layout);
|
||||
redoParagraphs(selection.start.par(), endpit);
|
||||
redoParagraphs(getPar(selection.start), endpit);
|
||||
|
||||
// we have to reset the selection, because the
|
||||
// geometry could have changed
|
||||
@ -407,13 +408,13 @@ void LyXText::setLayout(string const & layout)
|
||||
|
||||
bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
|
||||
{
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator end = cursor.par();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
ParagraphList::iterator end = cursorPar();
|
||||
ParagraphList::iterator start = pit;
|
||||
|
||||
if (selection.set()) {
|
||||
pit = selection.start.par();
|
||||
end = selection.end.par();
|
||||
pit = getPar(selection.start);
|
||||
end = getPar(selection.end);
|
||||
start = pit;
|
||||
}
|
||||
|
||||
@ -489,10 +490,10 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
|
||||
if (!selection.set()) {
|
||||
// Determine basis font
|
||||
LyXFont layoutfont;
|
||||
if (cursor.pos() < cursor.par()->beginningOfBody()) {
|
||||
layoutfont = getLabelFont(cursor.par());
|
||||
if (cursor.pos() < cursorPar()->beginningOfBody()) {
|
||||
layoutfont = getLabelFont(cursorPar());
|
||||
} else {
|
||||
layoutfont = getLayoutFont(cursor.par());
|
||||
layoutfont = getLayoutFont(cursorPar());
|
||||
}
|
||||
// Update current font
|
||||
real_current_font.update(font,
|
||||
@ -513,25 +514,24 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
|
||||
// ok we have a selection. This is always between sel_start_cursor
|
||||
// and sel_end cursor
|
||||
|
||||
recordUndo(bv(), Undo::ATOMIC, selection.start.par(), selection.end.par());
|
||||
recordUndo(bv(), Undo::ATOMIC, getPar(selection.start), getPar(selection.end));
|
||||
freezeUndo();
|
||||
cursor = selection.start;
|
||||
while (cursor.par() != selection.end.par() ||
|
||||
cursor.pos() < selection.end.pos())
|
||||
{
|
||||
if (cursor.pos() < cursor.par()->size()) {
|
||||
if (cursor.pos() < cursorPar()->size()) {
|
||||
// an open footnote should behave like a closed one
|
||||
setCharFont(cursor.par(), cursor.pos(),
|
||||
font, toggleall);
|
||||
setCharFont(cursorPar(), cursor.pos(), font, toggleall);
|
||||
cursor.pos(cursor.pos() + 1);
|
||||
} else {
|
||||
cursor.pos(0);
|
||||
cursor.par(boost::next(cursor.par()));
|
||||
cursor.par(cursor.par() + 1);
|
||||
}
|
||||
}
|
||||
unFreezeUndo();
|
||||
|
||||
redoParagraph(selection.start.par());
|
||||
redoParagraph(getPar(selection.start));
|
||||
|
||||
// we have to reset the selection, because the
|
||||
// geometry could have changed, but we keep
|
||||
@ -666,13 +666,13 @@ void LyXText::clearSelection()
|
||||
|
||||
void LyXText::cursorHome()
|
||||
{
|
||||
setCursor(cursor.par(), cursorRow()->pos());
|
||||
setCursor(cursorPar(), cursorRow()->pos());
|
||||
}
|
||||
|
||||
|
||||
void LyXText::cursorEnd()
|
||||
{
|
||||
setCursor(cursor.par(), cursorRow()->end() - 1);
|
||||
setCursor(cursorPar(), cursorRow()->end() - 1);
|
||||
}
|
||||
|
||||
|
||||
@ -715,7 +715,7 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
|
||||
if (implicitSelection) {
|
||||
clearSelection();
|
||||
cursor = resetCursor;
|
||||
setCursor(cursor.par(), cursor.pos());
|
||||
setCursor(cursorPar(), cursor.pos());
|
||||
selection.cursor = cursor;
|
||||
}
|
||||
}
|
||||
@ -740,7 +740,7 @@ string LyXText::getStringToIndex()
|
||||
|
||||
// Reset cursors to their original position.
|
||||
cursor = reset_cursor;
|
||||
setCursor(cursor.par(), cursor.pos());
|
||||
setCursor(cursorPar(), cursor.pos());
|
||||
selection.cursor = cursor;
|
||||
|
||||
// Clear the implicit selection.
|
||||
@ -773,7 +773,7 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
|
||||
}
|
||||
|
||||
// make sure that the depth behind the selection are restored, too
|
||||
ParagraphList::iterator endpit = boost::next(selection.end.par());
|
||||
ParagraphList::iterator endpit = boost::next(getPar(selection.end));
|
||||
ParagraphList::iterator undoendpit = endpit;
|
||||
ParagraphList::iterator pars_end = ownerParagraphs().end();
|
||||
|
||||
@ -787,16 +787,16 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
|
||||
++endpit;
|
||||
}
|
||||
|
||||
recordUndo(bv(), Undo::ATOMIC, selection.start.par(),
|
||||
recordUndo(bv(), Undo::ATOMIC, getPar(selection.start),
|
||||
boost::prior(undoendpit));
|
||||
|
||||
|
||||
ParagraphList::iterator tmppit = selection.end.par();
|
||||
int tmppit = selection.end.par();
|
||||
|
||||
while (tmppit != boost::prior(selection.start.par())) {
|
||||
while (tmppit != selection.start.par() - 1) {
|
||||
setCursor(tmppit, 0);
|
||||
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator const pit = cursorPar();
|
||||
ParagraphParameters & params = pit->params();
|
||||
|
||||
params.lineTop(line_top);
|
||||
@ -819,10 +819,10 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
|
||||
}
|
||||
pit->setLabelWidthString(labelwidthstring);
|
||||
params.noindent(noindent);
|
||||
tmppit = boost::prior(pit);
|
||||
--tmppit;
|
||||
}
|
||||
|
||||
redoParagraphs(selection.start.par(), endpit);
|
||||
redoParagraphs(getPar(selection.start), endpit);
|
||||
|
||||
clearSelection();
|
||||
setCursor(selection.start.par(), selection.start.pos());
|
||||
@ -1123,11 +1123,11 @@ void LyXText::updateCounters()
|
||||
|
||||
void LyXText::insertInset(InsetOld * inset)
|
||||
{
|
||||
if (!cursor.par()->insetAllowed(inset->lyxCode()))
|
||||
if (!cursorPar()->insetAllowed(inset->lyxCode()))
|
||||
return;
|
||||
recordUndo(bv(), Undo::ATOMIC, cursor.par());
|
||||
recordUndo(bv(), Undo::ATOMIC, cursorPar());
|
||||
freezeUndo();
|
||||
cursor.par()->insertInset(cursor.pos(), inset);
|
||||
cursorPar()->insertInset(cursor.pos(), inset);
|
||||
// Just to rebreak and refresh correctly.
|
||||
// The character will not be inserted a second time
|
||||
insertChar(Paragraph::META_INSET);
|
||||
@ -1161,7 +1161,7 @@ void LyXText::cutSelection(bool doclear, bool realcut)
|
||||
// and selection.end
|
||||
|
||||
// make sure that the depth behind the selection are restored, too
|
||||
ParagraphList::iterator endpit = boost::next(selection.end.par());
|
||||
ParagraphList::iterator endpit = getPar(selection.end.par() + 1);
|
||||
ParagraphList::iterator undoendpit = endpit;
|
||||
ParagraphList::iterator pars_end = ownerParagraphs().end();
|
||||
|
||||
@ -1175,40 +1175,40 @@ void LyXText::cutSelection(bool doclear, bool realcut)
|
||||
++endpit;
|
||||
}
|
||||
|
||||
recordUndo(bv(), Undo::DELETE, selection.start.par(),
|
||||
recordUndo(bv(), Undo::DELETE, getPar(selection.start),
|
||||
boost::prior(undoendpit));
|
||||
|
||||
endpit = selection.end.par();
|
||||
endpit = getPar(selection.end.par());
|
||||
int endpos = selection.end.pos();
|
||||
|
||||
BufferParams const & bufparams = bv()->buffer()->params();
|
||||
boost::tie(endpit, endpos) = realcut ?
|
||||
CutAndPaste::cutSelection(bufparams,
|
||||
ownerParagraphs(),
|
||||
selection.start.par(), endpit,
|
||||
getPar(selection.start.par()), endpit,
|
||||
selection.start.pos(), endpos,
|
||||
bufparams.textclass,
|
||||
doclear)
|
||||
: CutAndPaste::eraseSelection(bufparams,
|
||||
ownerParagraphs(),
|
||||
selection.start.par(), endpit,
|
||||
getPar(selection.start.par()), endpit,
|
||||
selection.start.pos(), endpos,
|
||||
doclear);
|
||||
// sometimes necessary
|
||||
if (doclear)
|
||||
selection.start.par()->stripLeadingSpaces();
|
||||
getPar(selection.start.par())->stripLeadingSpaces();
|
||||
|
||||
redoParagraphs(selection.start.par(), boost::next(endpit));
|
||||
redoParagraphs(getPar(selection.start.par()), boost::next(endpit));
|
||||
// cutSelection can invalidate the cursor so we need to set
|
||||
// it anew. (Lgb)
|
||||
// we prefer the end for when tracking changes
|
||||
cursor.pos(endpos);
|
||||
cursor.par(endpit);
|
||||
cursor.par(parOffset(endpit));
|
||||
|
||||
// need a valid cursor. (Lgb)
|
||||
clearSelection();
|
||||
|
||||
setCursor(cursor.par(), cursor.pos());
|
||||
setCursor(cursorPar(), cursor.pos());
|
||||
selection.cursor = cursor;
|
||||
updateCounters();
|
||||
}
|
||||
@ -1227,14 +1227,14 @@ void LyXText::copySelection()
|
||||
// and sel_end cursor
|
||||
|
||||
// copy behind a space if there is one
|
||||
while (selection.start.par()->size() > selection.start.pos()
|
||||
&& selection.start.par()->isLineSeparator(selection.start.pos())
|
||||
while (getPar(selection.start)->size() > selection.start.pos()
|
||||
&& getPar(selection.start)->isLineSeparator(selection.start.pos())
|
||||
&& (selection.start.par() != selection.end.par()
|
||||
|| selection.start.pos() < selection.end.pos()))
|
||||
selection.start.pos(selection.start.pos() + 1);
|
||||
|
||||
CutAndPaste::copySelection(selection.start.par(),
|
||||
selection.end.par(),
|
||||
CutAndPaste::copySelection(getPar(selection.start.par()),
|
||||
getPar(selection.end.par()),
|
||||
selection.start.pos(), selection.end.pos(),
|
||||
bv()->buffer()->params().textclass);
|
||||
}
|
||||
@ -1246,7 +1246,7 @@ void LyXText::pasteSelection(size_t sel_index)
|
||||
if (!CutAndPaste::checkPastePossible())
|
||||
return;
|
||||
|
||||
recordUndo(bv(), Undo::INSERT, cursor.par());
|
||||
recordUndo(bv(), Undo::INSERT, cursorPar());
|
||||
|
||||
ParagraphList::iterator endpit;
|
||||
PitPosPair ppp;
|
||||
@ -1256,13 +1256,13 @@ void LyXText::pasteSelection(size_t sel_index)
|
||||
boost::tie(ppp, endpit) =
|
||||
CutAndPaste::pasteSelection(*bv()->buffer(),
|
||||
ownerParagraphs(),
|
||||
cursor.par(), cursor.pos(),
|
||||
cursorPar(), cursor.pos(),
|
||||
bv()->buffer()->params().textclass,
|
||||
sel_index, el);
|
||||
bufferErrors(*bv()->buffer(), el);
|
||||
bv()->showErrorList(_("Paste"));
|
||||
|
||||
redoParagraphs(cursor.par(), endpit);
|
||||
redoParagraphs(cursorPar(), endpit);
|
||||
|
||||
setCursor(cursor.par(), cursor.pos());
|
||||
clearSelection();
|
||||
@ -1299,7 +1299,7 @@ void LyXText::replaceSelectionWithString(string const & str)
|
||||
|
||||
// Get font setting before we cut
|
||||
pos_type pos = selection.end.pos();
|
||||
LyXFont const font = selection.start.par()
|
||||
LyXFont const font = getPar(selection.start)
|
||||
->getFontSettings(bv()->buffer()->params(),
|
||||
selection.start.pos());
|
||||
|
||||
@ -1307,7 +1307,7 @@ void LyXText::replaceSelectionWithString(string const & str)
|
||||
string::const_iterator cit = str.begin();
|
||||
string::const_iterator end = str.end();
|
||||
for (; cit != end; ++cit) {
|
||||
selection.end.par()->insertChar(pos, (*cit), font);
|
||||
getPar(selection.end)->insertChar(pos, (*cit), font);
|
||||
++pos;
|
||||
}
|
||||
|
||||
@ -1321,9 +1321,9 @@ void LyXText::replaceSelectionWithString(string const & str)
|
||||
// needed to insert the selection
|
||||
void LyXText::insertStringAsLines(string const & str)
|
||||
{
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type pos = cursor.pos();
|
||||
ParagraphList::iterator endpit = boost::next(cursor.par());
|
||||
ParagraphList::iterator endpit = boost::next(cursorPar());
|
||||
|
||||
recordUndo(bv(), Undo::ATOMIC);
|
||||
|
||||
@ -1332,8 +1332,8 @@ void LyXText::insertStringAsLines(string const & str)
|
||||
|
||||
bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
|
||||
|
||||
redoParagraphs(cursor.par(), endpit);
|
||||
setCursor(cursor.par(), cursor.pos());
|
||||
redoParagraphs(cursorPar(), endpit);
|
||||
setCursor(cursorPar(), cursor.pos());
|
||||
selection.cursor = cursor;
|
||||
setCursor(pit, pos);
|
||||
setSelection();
|
||||
@ -1368,12 +1368,16 @@ void LyXText::insertStringAsParagraphs(string const & str)
|
||||
}
|
||||
|
||||
|
||||
bool LyXText::setCursor(ParagraphList::iterator pit,
|
||||
pos_type pos,
|
||||
bool setfont, bool boundary)
|
||||
void LyXText::setCursor(ParagraphList::iterator pit, pos_type pos)
|
||||
{
|
||||
setCursor(parOffset(pit), pos);
|
||||
}
|
||||
|
||||
|
||||
bool LyXText::setCursor(paroffset_type par, pos_type pos, bool setfont, bool boundary)
|
||||
{
|
||||
LyXCursor old_cursor = cursor;
|
||||
setCursorIntern(pit, pos, setfont, boundary);
|
||||
setCursorIntern(par, pos, setfont, boundary);
|
||||
return deleteEmptyParagraphMechanism(old_cursor);
|
||||
}
|
||||
|
||||
@ -1385,12 +1389,12 @@ void LyXText::redoCursor()
|
||||
}
|
||||
|
||||
|
||||
void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
|
||||
pos_type pos, bool boundary)
|
||||
void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
|
||||
pos_type pos, bool boundary)
|
||||
{
|
||||
BOOST_ASSERT(pit != ownerParagraphs().end());
|
||||
BOOST_ASSERT(par != int(ownerParagraphs().size()));
|
||||
|
||||
cur.par(pit);
|
||||
cur.par(par);
|
||||
cur.pos(pos);
|
||||
cur.boundary(boundary);
|
||||
|
||||
@ -1400,6 +1404,7 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
|
||||
|
||||
// get the cursor y position in text
|
||||
|
||||
ParagraphList::iterator pit = getPar(par);
|
||||
RowList::iterator row = getRow(pit, pos);
|
||||
int y = row->y();
|
||||
|
||||
@ -1489,10 +1494,10 @@ float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
|
||||
}
|
||||
|
||||
|
||||
void LyXText::setCursorIntern(ParagraphList::iterator pit,
|
||||
void LyXText::setCursorIntern(paroffset_type par,
|
||||
pos_type pos, bool setfont, bool boundary)
|
||||
{
|
||||
setCursor(cursor, pit, pos, boundary);
|
||||
setCursor(cursor, par, pos, boundary);
|
||||
if (setfont)
|
||||
setCurrentFont();
|
||||
}
|
||||
@ -1501,7 +1506,7 @@ void LyXText::setCursorIntern(ParagraphList::iterator pit,
|
||||
void LyXText::setCurrentFont()
|
||||
{
|
||||
pos_type pos = cursor.pos();
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
|
||||
if (cursor.boundary() && pos > 0)
|
||||
--pos;
|
||||
@ -1662,7 +1667,7 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
|
||||
|
||||
bool bound = false;
|
||||
pos_type const column = getColumnNearX(pit, rit, x, bound);
|
||||
cur.par(pit);
|
||||
cur.par(parOffset(pit));
|
||||
cur.pos(rit->pos() + column);
|
||||
cur.x(x);
|
||||
cur.y(y + rit->baseline());
|
||||
@ -1677,31 +1682,30 @@ void LyXText::cursorLeft(bool internal)
|
||||
bool boundary = cursor.boundary();
|
||||
setCursor(cursor.par(), cursor.pos() - 1, true, false);
|
||||
if (!internal && !boundary &&
|
||||
isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos() + 1))
|
||||
isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos() + 1))
|
||||
setCursor(cursor.par(), cursor.pos() + 1, true, true);
|
||||
} else if (cursor.par() != ownerParagraphs().begin()) {
|
||||
} else if (cursor.par() != 0) {
|
||||
// steps into the paragraph above
|
||||
ParagraphList::iterator pit = boost::prior(cursor.par());
|
||||
setCursor(pit, pit->size());
|
||||
setCursor(cursor.par() - 1, boost::prior(cursorPar())->size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LyXText::cursorRight(bool internal)
|
||||
{
|
||||
bool const at_end = (cursor.pos() == cursor.par()->size());
|
||||
bool const at_end = (cursor.pos() == cursorPar()->size());
|
||||
bool const at_newline = !at_end &&
|
||||
cursor.par()->isNewline(cursor.pos());
|
||||
cursorPar()->isNewline(cursor.pos());
|
||||
|
||||
if (!internal && cursor.boundary() && !at_newline)
|
||||
setCursor(cursor.par(), cursor.pos(), true, false);
|
||||
else if (!at_end) {
|
||||
setCursor(cursor.par(), cursor.pos() + 1, true, false);
|
||||
if (!internal &&
|
||||
isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos()))
|
||||
isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos()))
|
||||
setCursor(cursor.par(), cursor.pos(), true, true);
|
||||
} else if (boost::next(cursor.par()) != ownerParagraphs().end())
|
||||
setCursor(boost::next(cursor.par()), 0);
|
||||
} else if (cursor.par() + 1 != int(ownerParagraphs().size()))
|
||||
setCursor(cursor.par() + 1, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -1758,15 +1762,15 @@ void LyXText::cursorDown(bool selecting)
|
||||
void LyXText::cursorUpParagraph()
|
||||
{
|
||||
if (cursor.pos() > 0)
|
||||
setCursor(cursor.par(), 0);
|
||||
else if (cursor.par() != ownerParagraphs().begin())
|
||||
setCursor(boost::prior(cursor.par()), 0);
|
||||
setCursor(cursorPar(), 0);
|
||||
else if (cursorPar() != ownerParagraphs().begin())
|
||||
setCursor(boost::prior(cursorPar()), 0);
|
||||
}
|
||||
|
||||
|
||||
void LyXText::cursorDownParagraph()
|
||||
{
|
||||
ParagraphList::iterator par = cursor.par();
|
||||
ParagraphList::iterator par = cursorPar();
|
||||
ParagraphList::iterator next_par = boost::next(par);
|
||||
|
||||
if (next_par != ownerParagraphs().end())
|
||||
@ -1792,8 +1796,8 @@ void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
|
||||
|
||||
// check also if we don't want to set the cursor on a spot behind the
|
||||
// pagragraph because we erased the last character.
|
||||
if (cur.pos() > cur.par()->size())
|
||||
cur.pos(cur.par()->size());
|
||||
if (cur.pos() > getPar(cur)->size())
|
||||
cur.pos(getPar(cur)->size());
|
||||
|
||||
// recompute row et al. for this cursor
|
||||
setCursor(cur, cur.par(), cur.pos(), cur.boundary());
|
||||
@ -1807,7 +1811,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
|
||||
return false;
|
||||
|
||||
// We allow all kinds of "mumbo-jumbo" when freespacing.
|
||||
if (old_cursor.par()->isFreeSpacing())
|
||||
if (getPar(old_cursor)->isFreeSpacing())
|
||||
return false;
|
||||
|
||||
/* Ok I'll put some comments here about what is missing.
|
||||
@ -1834,16 +1838,17 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
|
||||
// MISSING
|
||||
|
||||
// If the pos around the old_cursor were spaces, delete one of them.
|
||||
ParagraphList::iterator const old_pit = getPar(old_cursor);
|
||||
if (old_cursor.par() != cursor.par()
|
||||
|| old_cursor.pos() != cursor.pos()) {
|
||||
|
||||
// Only if the cursor has really moved
|
||||
if (old_cursor.pos() > 0
|
||||
&& old_cursor.pos() < old_cursor.par()->size()
|
||||
&& old_cursor.par()->isLineSeparator(old_cursor.pos())
|
||||
&& old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
|
||||
bool erased = old_cursor.par()->erase(old_cursor.pos() - 1);
|
||||
redoParagraph(old_cursor.par());
|
||||
&& old_cursor.pos() < old_pit->size()
|
||||
&& old_pit->isLineSeparator(old_cursor.pos())
|
||||
&& old_pit->isLineSeparator(old_cursor.pos() - 1)) {
|
||||
bool erased = old_pit->erase(old_cursor.pos() - 1);
|
||||
redoParagraph(old_pit);
|
||||
|
||||
if (!erased)
|
||||
return false;
|
||||
@ -1867,7 +1872,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
|
||||
return false;
|
||||
|
||||
// Do not delete empty paragraphs with keepempty set.
|
||||
if (old_cursor.par()->allowEmpty())
|
||||
if (old_pit->allowEmpty())
|
||||
return false;
|
||||
|
||||
// only do our magic if we changed paragraph
|
||||
@ -1878,30 +1883,29 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
|
||||
// we can't possibly have deleted a paragraph before this point
|
||||
bool deleted = false;
|
||||
|
||||
if (old_cursor.par()->empty() ||
|
||||
(old_cursor.par()->size() == 1 &&
|
||||
old_cursor.par()->isLineSeparator(0))) {
|
||||
if (old_pit->empty() ||
|
||||
(old_pit->size() == 1 && old_pit->isLineSeparator(0))) {
|
||||
// ok, we will delete something
|
||||
LyXCursor tmpcursor;
|
||||
|
||||
deleted = true;
|
||||
|
||||
bool selection_position_was_oldcursor_position = (
|
||||
selection.cursor.par() == old_cursor.par()
|
||||
&& selection.cursor.pos() == old_cursor.pos());
|
||||
bool selection_position_was_oldcursor_position =
|
||||
selection.cursor.par() == old_cursor.par()
|
||||
&& selection.cursor.pos() == old_cursor.pos();
|
||||
|
||||
tmpcursor = cursor;
|
||||
cursor = old_cursor; // that undo can restore the right cursor position
|
||||
|
||||
ParagraphList::iterator endpit = boost::next(old_cursor.par());
|
||||
ParagraphList::iterator endpit = boost::next(old_pit);
|
||||
while (endpit != ownerParagraphs().end() && endpit->getDepth())
|
||||
++endpit;
|
||||
|
||||
recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
|
||||
recordUndo(bv(), Undo::DELETE, old_pit, boost::prior(endpit));
|
||||
cursor = tmpcursor;
|
||||
|
||||
// delete old par
|
||||
ownerParagraphs().erase(old_cursor.par());
|
||||
ownerParagraphs().erase(old_pit);
|
||||
redoParagraph();
|
||||
|
||||
// correct cursor y
|
||||
@ -1913,8 +1917,8 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
|
||||
}
|
||||
}
|
||||
if (!deleted) {
|
||||
if (old_cursor.par()->stripLeadingSpaces()) {
|
||||
redoParagraph(old_cursor.par());
|
||||
if (old_pit->stripLeadingSpaces()) {
|
||||
redoParagraph(old_pit);
|
||||
// correct cursor y
|
||||
setCursorIntern(cursor.par(), cursor.pos());
|
||||
selection.cursor = cursor;
|
||||
|
156
src/text3.C
156
src/text3.C
@ -100,11 +100,11 @@ namespace {
|
||||
// check if the given co-ordinates are inside an inset at the
|
||||
// given cursor, if one exists. If so, the inset is returned,
|
||||
// and the co-ordinates are made relative. Otherwise, 0 is returned.
|
||||
InsetOld * checkInset(BufferView * /*bv*/, LyXText & text,
|
||||
InsetOld * checkInset(LyXText & text,
|
||||
LyXCursor const & cur, int & x, int & y)
|
||||
{
|
||||
lyx::pos_type const pos = cur.pos();
|
||||
ParagraphList::iterator par = cur.par();
|
||||
ParagraphList::iterator par = text.getPar(cur);
|
||||
|
||||
if (pos >= par->size() || !par->isInset(pos))
|
||||
return 0;
|
||||
@ -137,7 +137,7 @@ namespace {
|
||||
return 0;
|
||||
}
|
||||
|
||||
text.setCursor(par, pos, true);
|
||||
text.setCursor(cur.par(), pos, true);
|
||||
|
||||
x -= b.x1;
|
||||
// The origin of an inset is on the baseline
|
||||
@ -156,7 +156,7 @@ InsetOld * LyXText::checkInsetHit(int & x, int & y)
|
||||
LyXCursor cur;
|
||||
setCursorFromCoordinates(cur, x, y_tmp);
|
||||
|
||||
InsetOld * inset = checkInset(bv(), *this, cur, x, y_tmp);
|
||||
InsetOld * inset = checkInset(*this, cur, x, y_tmp);
|
||||
if (inset) {
|
||||
y = y_tmp;
|
||||
return inset;
|
||||
@ -169,7 +169,7 @@ InsetOld * LyXText::checkInsetHit(int & x, int & y)
|
||||
// move back one
|
||||
setCursor(cur, cur.par(), cur.pos() - 1, true);
|
||||
|
||||
inset = checkInset(bv(), *this, cur, x, y_tmp);
|
||||
inset = checkInset(*this, cur, x, y_tmp);
|
||||
if (inset)
|
||||
y = y_tmp;
|
||||
return inset;
|
||||
@ -180,7 +180,7 @@ bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
|
||||
string const & contents)
|
||||
{
|
||||
ParagraphList::iterator end = ownerParagraphs().end();
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type pos = cursor.pos();
|
||||
|
||||
InsetOld * inset;
|
||||
@ -200,11 +200,11 @@ bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
|
||||
static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
|
||||
== contents)));
|
||||
|
||||
if (pit != end) {
|
||||
setCursor(pit, pos, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (pit == end)
|
||||
return false;
|
||||
|
||||
setCursor(parOffset(pit), pos, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -214,18 +214,18 @@ void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
|
||||
bv()->beforeChange(this);
|
||||
|
||||
string contents;
|
||||
if (same_content && cursor.pos() < cursor.par()->size()
|
||||
&& cursor.par()->isInset(cursor.pos())) {
|
||||
InsetOld const * inset = cursor.par()->getInset(cursor.pos());
|
||||
if (same_content && cursor.pos() < cursorPar()->size()
|
||||
&& cursorPar()->isInset(cursor.pos())) {
|
||||
InsetOld const * inset = cursorPar()->getInset(cursor.pos());
|
||||
if (find(codes.begin(), codes.end(), inset->lyxCode())
|
||||
!= codes.end())
|
||||
contents = static_cast<InsetCommand const *>(inset)->getContents();
|
||||
}
|
||||
|
||||
if (!gotoNextInset(codes, contents)) {
|
||||
if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
|
||||
if (cursor.pos() || cursorPar() != ownerParagraphs().begin()) {
|
||||
LyXCursor tmp = cursor;
|
||||
cursor.par(ownerParagraphs().begin());
|
||||
cursor.par(0);
|
||||
cursor.pos(0);
|
||||
if (!gotoNextInset(codes, contents)) {
|
||||
cursor = tmp;
|
||||
@ -284,9 +284,9 @@ void LyXText::cursorPrevious()
|
||||
}
|
||||
|
||||
LyXCursor cur;
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
previousRow(pit, rit);
|
||||
setCursor(cur, pit, rit->pos(), false);
|
||||
setCursor(cur, parOffset(pit), rit->pos(), false);
|
||||
if (cur.y() > bv_owner->top_y())
|
||||
cursorUp(true);
|
||||
bv()->updateScrollbar();
|
||||
@ -340,10 +340,10 @@ void LyXText::cursorNext()
|
||||
}
|
||||
}
|
||||
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
nextRow(pit, rit);
|
||||
LyXCursor cur;
|
||||
setCursor(cur, pit, rit->pos(), false);
|
||||
setCursor(cur, parOffset(pit), rit->pos(), false);
|
||||
if (cur.y() < bv_owner->top_y() + bv()->workHeight())
|
||||
cursorDown(true);
|
||||
bv()->updateScrollbar();
|
||||
@ -402,7 +402,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
switch (cmd.action) {
|
||||
|
||||
case LFUN_APPENDIX: {
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
bool start = !pit->params().startOfAppendix();
|
||||
|
||||
// ensure that we have only one start_of_appendix in this document
|
||||
@ -423,8 +423,8 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
|
||||
// we can set the refreshing parameters now
|
||||
updateCounters();
|
||||
redoParagraph(cursor.par());
|
||||
setCursor(cursor.par(), cursor.pos());
|
||||
redoParagraph(cursorPar());
|
||||
setCursor(cursorPar(), cursor.pos());
|
||||
bv->update();
|
||||
break;
|
||||
}
|
||||
@ -450,7 +450,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_WORDRIGHT:
|
||||
if (!selection.mark())
|
||||
bv->beforeChange(this);
|
||||
if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
|
||||
if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
|
||||
cursorLeftOneWord();
|
||||
else
|
||||
cursorRightOneWord();
|
||||
@ -460,7 +460,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_WORDLEFT:
|
||||
if (!selection.mark())
|
||||
bv->beforeChange(this);
|
||||
if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
|
||||
if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
|
||||
cursorRightOneWord();
|
||||
else
|
||||
cursorLeftOneWord();
|
||||
@ -484,7 +484,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_RIGHTSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
|
||||
if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
|
||||
cursorLeft(bv);
|
||||
else
|
||||
cursorRight(bv);
|
||||
@ -494,7 +494,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_LEFTSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
|
||||
if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
|
||||
cursorRight(bv);
|
||||
else
|
||||
cursorLeft(bv);
|
||||
@ -558,7 +558,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_WORDRIGHTSEL:
|
||||
if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
|
||||
if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
|
||||
cursorLeftOneWord();
|
||||
else
|
||||
cursorRightOneWord();
|
||||
@ -566,7 +566,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_WORDLEFTSEL:
|
||||
if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
|
||||
if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
|
||||
cursorRightOneWord();
|
||||
else
|
||||
cursorLeftOneWord();
|
||||
@ -576,7 +576,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_WORDSEL: {
|
||||
LyXCursor cur1 = cursor;
|
||||
LyXCursor cur2;
|
||||
::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
|
||||
::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
|
||||
setCursor(cur1.par(), cur1.pos());
|
||||
bv->beforeChange(this);
|
||||
setCursor(cur2.par(), cur2.pos());
|
||||
@ -585,15 +585,15 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
}
|
||||
|
||||
case LFUN_RIGHT: {
|
||||
bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params());
|
||||
bool is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
|
||||
if (!selection.mark())
|
||||
bv->beforeChange(this);
|
||||
if (is_rtl)
|
||||
cursorLeft(false);
|
||||
if (cursor.pos() < cursor.par()->size()
|
||||
&& cursor.par()->isInset(cursor.pos())
|
||||
&& isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
|
||||
InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
|
||||
if (cursor.pos() < cursorPar()->size()
|
||||
&& cursorPar()->isInset(cursor.pos())
|
||||
&& isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
|
||||
InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
|
||||
cmd.message(tmpinset->editMessage());
|
||||
FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
|
||||
tmpinset->localDispatch(cmd1);
|
||||
@ -608,17 +608,17 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_LEFT: {
|
||||
// This is soooo ugly. Isn`t it possible to make
|
||||
// it simpler? (Lgb)
|
||||
bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params());
|
||||
bool const is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
|
||||
if (!selection.mark())
|
||||
bv->beforeChange(this);
|
||||
LyXCursor const cur = cursor;
|
||||
if (!is_rtl)
|
||||
cursorLeft(false);
|
||||
if ((is_rtl || cur != cursor) && // only if really moved!
|
||||
cursor.pos() < cursor.par()->size() &&
|
||||
cursor.par()->isInset(cursor.pos()) &&
|
||||
isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
|
||||
InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
|
||||
cursor.pos() < cursorPar()->size() &&
|
||||
cursorPar()->isInset(cursor.pos()) &&
|
||||
isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
|
||||
InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
|
||||
cmd.message(tmpinset->editMessage());
|
||||
FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
|
||||
tmpinset->localDispatch(cmd1);
|
||||
@ -687,7 +687,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_BREAKLINE: {
|
||||
lyx::pos_type body = cursor.par()->beginningOfBody();
|
||||
lyx::pos_type body = cursorPar()->beginningOfBody();
|
||||
|
||||
// Not allowed by LaTeX (labels or empty par)
|
||||
if (cursor.pos() <= body)
|
||||
@ -695,7 +695,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
|
||||
replaceSelection(bv->getLyXText());
|
||||
insertInset(new InsetNewline);
|
||||
setCursor(cursor.par(), cursor.pos());
|
||||
setCursor(cursorPar(), cursor.pos());
|
||||
moveCursorUpdate(bv, false);
|
||||
break;
|
||||
}
|
||||
@ -717,22 +717,22 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
|
||||
if (!selection.set()) {
|
||||
LyXCursor cur = cursor;
|
||||
if (cur.pos() == cur.par()->size()) {
|
||||
if (cur.pos() == getPar(cur)->size()) {
|
||||
cursorRight(bv);
|
||||
cur = cursor;
|
||||
if (cur.pos() == 0
|
||||
&& !(cur.par()->params().spaceTop()
|
||||
&& !(getPar(cur)->params().spaceTop()
|
||||
== VSpace (VSpace::NONE))) {
|
||||
setParagraph(
|
||||
cur.par()->params().lineTop(),
|
||||
cur.par()->params().lineBottom(),
|
||||
cur.par()->params().pagebreakTop(),
|
||||
cur.par()->params().pagebreakBottom(),
|
||||
getPar(cur)->params().lineTop(),
|
||||
getPar(cur)->params().lineBottom(),
|
||||
getPar(cur)->params().pagebreakTop(),
|
||||
getPar(cur)->params().pagebreakBottom(),
|
||||
VSpace(VSpace::NONE),
|
||||
cur.par()->params().spaceBottom(),
|
||||
cur.par()->params().spacing(),
|
||||
cur.par()->params().align(),
|
||||
cur.par()->params().labelWidthString(), 0);
|
||||
getPar(cur)->params().spaceBottom(),
|
||||
getPar(cur)->params().spacing(),
|
||||
getPar(cur)->params().align(),
|
||||
getPar(cur)->params().labelWidthString(), 0);
|
||||
cursorLeft(bv);
|
||||
} else {
|
||||
cursorLeft(bv);
|
||||
@ -771,17 +771,17 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
if (!selection.set()) {
|
||||
LyXCursor cur = cursor;
|
||||
if (cur.pos() == 0
|
||||
&& !(cur.par()->params().spaceTop() == VSpace(VSpace::NONE))) {
|
||||
&& !(getPar(cur)->params().spaceTop() == VSpace(VSpace::NONE))) {
|
||||
setParagraph(
|
||||
cur.par()->params().lineTop(),
|
||||
cur.par()->params().lineBottom(),
|
||||
cur.par()->params().pagebreakTop(),
|
||||
cur.par()->params().pagebreakBottom(),
|
||||
getPar(cur)->params().lineTop(),
|
||||
getPar(cur)->params().lineBottom(),
|
||||
getPar(cur)->params().pagebreakTop(),
|
||||
getPar(cur)->params().pagebreakBottom(),
|
||||
VSpace(VSpace::NONE),
|
||||
cur.par()->params().spaceBottom(),
|
||||
cur.par()->params().spacing(),
|
||||
cur.par()->params().align(),
|
||||
cur.par()->params().labelWidthString(), 0);
|
||||
getPar(cur)->params().spaceBottom(),
|
||||
getPar(cur)->params().spacing(),
|
||||
getPar(cur)->params().align(),
|
||||
getPar(cur)->params().labelWidthString(), 0);
|
||||
} else {
|
||||
backspace();
|
||||
selection.cursor = cur;
|
||||
@ -817,16 +817,16 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
LyXCursor cur = cursor;
|
||||
replaceSelection(bv->getLyXText());
|
||||
if (cur.pos() == 0) {
|
||||
if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
|
||||
if (getPar(cur)->params().spaceTop() == VSpace(VSpace::NONE)) {
|
||||
setParagraph(
|
||||
cur.par()->params().lineTop(),
|
||||
cur.par()->params().lineBottom(),
|
||||
cur.par()->params().pagebreakTop(),
|
||||
cur.par()->params().pagebreakBottom(),
|
||||
VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
|
||||
cur.par()->params().spacing(),
|
||||
cur.par()->params().align(),
|
||||
cur.par()->params().labelWidthString(), 1);
|
||||
getPar(cur)->params().lineTop(),
|
||||
getPar(cur)->params().lineBottom(),
|
||||
getPar(cur)->params().pagebreakTop(),
|
||||
getPar(cur)->params().pagebreakBottom(),
|
||||
VSpace(VSpace::DEFSKIP), getPar(cur)->params().spaceBottom(),
|
||||
getPar(cur)->params().spacing(),
|
||||
getPar(cur)->params().align(),
|
||||
getPar(cur)->params().labelWidthString(), 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -840,7 +840,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
}
|
||||
|
||||
case LFUN_PARAGRAPH_SPACING: {
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
Spacing::Space cur_spacing = pit->params().spacing().getSpace();
|
||||
float cur_value = 1.0;
|
||||
if (cur_spacing == Spacing::Other)
|
||||
@ -894,7 +894,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_SPACE_INSERT:
|
||||
if (cursor.par()->layout()->free_spacing)
|
||||
if (cursorPar()->layout()->free_spacing)
|
||||
insertChar(' ');
|
||||
else
|
||||
doInsertInset(this, cmd, false, false);
|
||||
@ -964,7 +964,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_TRANSPOSE_CHARS:
|
||||
recordUndo(bv, Undo::ATOMIC, cursor.par());
|
||||
recordUndo(bv, Undo::ATOMIC, cursorPar());
|
||||
redoParagraph();
|
||||
bv->update();
|
||||
break;
|
||||
@ -1038,7 +1038,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_GETLAYOUT:
|
||||
cmd.message(tostr(cursor.par()->layout()));
|
||||
cmd.message(tostr(cursorPar()->layout()));
|
||||
break;
|
||||
|
||||
case LFUN_LAYOUT: {
|
||||
@ -1079,8 +1079,8 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
if (!change_layout && selection.set() &&
|
||||
selection.start.par() != selection.end.par())
|
||||
{
|
||||
ParagraphList::iterator spit = selection.start.par();
|
||||
ParagraphList::iterator epit = boost::next(selection.end.par());
|
||||
ParagraphList::iterator spit = getPar(selection.start);
|
||||
ParagraphList::iterator epit = boost::next(getPar(selection.end));
|
||||
while (spit != epit) {
|
||||
if (spit->layout()->name() != current_layout) {
|
||||
change_layout = true;
|
||||
@ -1135,7 +1135,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
|
||||
case LFUN_QUOTE: {
|
||||
replaceSelection(bv->getLyXText());
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
lyx::pos_type pos = cursor.pos();
|
||||
char c;
|
||||
if (!pos)
|
||||
@ -1217,7 +1217,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
if (bv->theLockingInset()) {
|
||||
InsetOld * tli = bv->theLockingInset();
|
||||
LyXCursor cursor = bv->text->cursor;
|
||||
LyXFont font = bv->text->getFont(cursor.par(), cursor.pos());
|
||||
LyXFont font = bv->text->getFont(cursorPar(), cursor.pos());
|
||||
int width = tli->width();
|
||||
int inset_x = font.isVisibleRightToLeft()
|
||||
? cursor.x() - width : cursor.x();
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "text_funcs.h"
|
||||
#include "debug.h"
|
||||
#include "lyxcursor.h"
|
||||
#include "lyxtext.h"
|
||||
#include "paragraph.h"
|
||||
|
||||
#include <boost/next_prior.hpp>
|
||||
@ -27,9 +28,9 @@ using lyx::word_location;
|
||||
using std::endl;
|
||||
|
||||
|
||||
bool transposeChars(LyXCursor const & cursor)
|
||||
bool transposeChars(LyXText & text, LyXCursor const & cursor)
|
||||
{
|
||||
ParagraphList::iterator tmppit = cursor.par();
|
||||
ParagraphList::iterator tmppit = text.cursorPar();
|
||||
pos_type tmppos = cursor.pos();
|
||||
|
||||
// First decide if it is possible to transpose at all
|
||||
@ -58,11 +59,12 @@ bool transposeChars(LyXCursor const & cursor)
|
||||
}
|
||||
|
||||
|
||||
void cursorLeftOneWord(LyXCursor & cursor, ParagraphList const & pars)
|
||||
void cursorLeftOneWord(LyXText & text,
|
||||
LyXCursor & cursor, ParagraphList const & pars)
|
||||
{
|
||||
// treat HFills, floats and Insets as words
|
||||
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = text.cursorPar();
|
||||
size_t pos = cursor.pos();
|
||||
|
||||
while (pos &&
|
||||
@ -88,15 +90,16 @@ void cursorLeftOneWord(LyXCursor & cursor, ParagraphList const & pars)
|
||||
--pos;
|
||||
}
|
||||
|
||||
cursor.par(pit);
|
||||
cursor.par(text.parOffset(pit));
|
||||
cursor.pos(pos);
|
||||
}
|
||||
|
||||
|
||||
void cursorRightOneWord(LyXCursor & cursor, ParagraphList const & pars)
|
||||
void cursorRightOneWord(LyXText & text,
|
||||
LyXCursor & cursor, ParagraphList const & pars)
|
||||
{
|
||||
// treat floats, HFills and Insets as words
|
||||
ParagraphList::iterator pit = cursor.par();
|
||||
ParagraphList::iterator pit = text.cursorPar();
|
||||
pos_type pos = cursor.pos();
|
||||
|
||||
// CHECK See comment on top of text.C
|
||||
@ -117,25 +120,27 @@ void cursorRightOneWord(LyXCursor & cursor, ParagraphList const & pars)
|
||||
}
|
||||
}
|
||||
|
||||
cursor.par(pit);
|
||||
cursor.par(text.parOffset(pit));
|
||||
cursor.pos(pos);
|
||||
}
|
||||
|
||||
|
||||
// Select current word. This depends on behaviour of
|
||||
// CursorLeftOneWord(), so it is patched as well.
|
||||
void getWord(LyXCursor & from, LyXCursor & to, word_location const loc,
|
||||
ParagraphList const & pars)
|
||||
void getWord(LyXText & text, LyXCursor & from, LyXCursor & to,
|
||||
word_location const loc, ParagraphList const & pars)
|
||||
{
|
||||
ParagraphList::iterator from_par = text.getPar(from);
|
||||
ParagraphList::iterator to_par = text.getPar(to);
|
||||
switch (loc) {
|
||||
case lyx::WHOLE_WORD_STRICT:
|
||||
if (from.pos() == 0 || from.pos() == from.par()->size()
|
||||
|| from.par()->isSeparator(from.pos())
|
||||
|| from.par()->isKomma(from.pos())
|
||||
|| from.par()->isNewline(from.pos())
|
||||
|| from.par()->isSeparator(from.pos() - 1)
|
||||
|| from.par()->isKomma(from.pos() - 1)
|
||||
|| from.par()->isNewline(from.pos() - 1)) {
|
||||
if (from.pos() == 0 || from.pos() == from_par->size()
|
||||
|| from_par->isSeparator(from.pos())
|
||||
|| from_par->isKomma(from.pos())
|
||||
|| from_par->isNewline(from.pos())
|
||||
|| from_par->isSeparator(from.pos() - 1)
|
||||
|| from_par->isKomma(from.pos() - 1)
|
||||
|| from_par->isNewline(from.pos() - 1)) {
|
||||
to = from;
|
||||
return;
|
||||
}
|
||||
@ -143,14 +148,14 @@ void getWord(LyXCursor & from, LyXCursor & to, word_location const loc,
|
||||
|
||||
case lyx::WHOLE_WORD:
|
||||
// Move cursor to the beginning, when not already there.
|
||||
if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
|
||||
&& !(from.par()->isKomma(from.pos() - 1)
|
||||
|| from.par()->isNewline(from.pos() - 1)))
|
||||
cursorLeftOneWord(from, pars);
|
||||
if (from.pos() && !from_par->isSeparator(from.pos() - 1)
|
||||
&& !(from_par->isKomma(from.pos() - 1)
|
||||
|| from_par->isNewline(from.pos() - 1)))
|
||||
cursorLeftOneWord(text, from, pars);
|
||||
break;
|
||||
case lyx::PREVIOUS_WORD:
|
||||
// always move the cursor to the beginning of previous word
|
||||
cursorLeftOneWord(from, pars);
|
||||
cursorLeftOneWord(text, from, pars);
|
||||
break;
|
||||
case lyx::NEXT_WORD:
|
||||
lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
|
||||
@ -160,12 +165,12 @@ void getWord(LyXCursor & from, LyXCursor & to, word_location const loc,
|
||||
break;
|
||||
}
|
||||
to = from;
|
||||
while (to.pos() < to.par()->size()
|
||||
&& !to.par()->isSeparator(to.pos())
|
||||
&& !to.par()->isKomma(to.pos())
|
||||
&& !to.par()->isNewline(to.pos())
|
||||
&& !to.par()->isHfill(to.pos())
|
||||
&& !to.par()->isInset(to.pos()))
|
||||
while (to.pos() < to_par->size()
|
||||
&& !to_par->isSeparator(to.pos())
|
||||
&& !to_par->isKomma(to.pos())
|
||||
&& !to_par->isNewline(to.pos())
|
||||
&& !to_par->isHfill(to.pos())
|
||||
&& !to_par->isInset(to.pos()))
|
||||
{
|
||||
to.pos(to.pos() + 1);
|
||||
}
|
||||
|
@ -20,21 +20,22 @@
|
||||
#include "support/types.h"
|
||||
|
||||
class LyXCursor;
|
||||
class LyXText;
|
||||
|
||||
|
||||
// do no use LyXText or BufferView here
|
||||
|
||||
|
||||
///
|
||||
bool transposeChars(LyXCursor const & cursor);
|
||||
bool transposeChars(LyXText &, LyXCursor const & cursor);
|
||||
///
|
||||
void cursorLeftOneWord(LyXCursor &, ParagraphList const &);
|
||||
void cursorLeftOneWord(LyXText &, LyXCursor &, ParagraphList const &);
|
||||
///
|
||||
void cursorRightOneWord(LyXCursor &, ParagraphList const &);
|
||||
void cursorRightOneWord(LyXText &, LyXCursor &, ParagraphList const &);
|
||||
|
||||
// Select current word. This depends on behaviour of
|
||||
// CursorLeftOneWord(), so it is patched as well.
|
||||
void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const loc,
|
||||
void getWord(LyXText &, LyXCursor & from, LyXCursor & to, lyx::word_location const loc,
|
||||
ParagraphList const & pars);
|
||||
|
||||
#endif // TEXT_FUNCS_H
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "textcursor.h"
|
||||
#include "paragraph.h"
|
||||
#include "ParagraphList_fwd.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -65,33 +66,3 @@ void TextCursor::clearSelection()
|
||||
selection.cursor = cursor;
|
||||
}
|
||||
|
||||
|
||||
string const TextCursor::selectionAsString(Buffer const & buffer,
|
||||
bool label) const
|
||||
{
|
||||
if (!selection.set())
|
||||
return string();
|
||||
|
||||
// should be const ...
|
||||
ParagraphList::iterator startpit = selection.start.par();
|
||||
ParagraphList::iterator endpit = selection.end.par();
|
||||
size_t const startpos = selection.start.pos();
|
||||
size_t const endpos = selection.end.pos();
|
||||
|
||||
if (startpit == endpit)
|
||||
return startpit->asString(buffer, startpos, endpos, label);
|
||||
|
||||
// First paragraph in selection
|
||||
string result =
|
||||
startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
|
||||
|
||||
// The paragraphs in between (if any)
|
||||
ParagraphList::iterator pit = startpit;
|
||||
for (++pit; pit != endpit; ++pit)
|
||||
result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
|
||||
|
||||
// Last paragraph in selection
|
||||
result += endpit->asString(buffer, 0, endpos, label);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -17,10 +17,6 @@
|
||||
|
||||
#include "lyxcursor.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class Buffer;
|
||||
|
||||
// Do not even think of forward declaring LyXText/BufferView etc here!
|
||||
// If you need Paragraph proper, go to text_func.h
|
||||
|
||||
@ -69,8 +65,6 @@ struct TextCursor {
|
||||
void setSelection();
|
||||
///
|
||||
void clearSelection();
|
||||
///
|
||||
std::string const selectionAsString(Buffer const & buffer, bool label) const;
|
||||
|
||||
// actual cursor position
|
||||
LyXCursor cursor;
|
||||
|
@ -79,8 +79,7 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
|
||||
}
|
||||
|
||||
// Record the cursor position in a stable way.
|
||||
int const cursor_offset = std::distance
|
||||
(text->ownerParagraphs().begin(), text->cursor.par());
|
||||
int const cursor_offset = text->cursor.par();
|
||||
|
||||
// Make and push the Undo entry
|
||||
stack.push(Undo(kind, inset_id,
|
||||
@ -140,9 +139,7 @@ bool performUndoOrRedo(BufferView * bv, Undo & undo)
|
||||
buf->getInsetFromID(undo.inset_id));
|
||||
|
||||
LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
|
||||
ParagraphList::iterator cursor = text->ownerParagraphs().begin();
|
||||
advance(cursor, undo.cursor_par_offset);
|
||||
text->setCursorIntern(cursor, undo.cursor_pos);
|
||||
text->setCursorIntern(undo.cursor_par_offset, undo.cursor_pos);
|
||||
|
||||
if (inset) {
|
||||
// Magic needed to update inset internal state
|
||||
@ -151,7 +148,7 @@ bool performUndoOrRedo(BufferView * bv, Undo & undo)
|
||||
}
|
||||
|
||||
// set cursor again to force the position to be the right one
|
||||
text->setCursorIntern(cursor, undo.cursor_pos);
|
||||
text->setCursorIntern(undo.cursor_par_offset, undo.cursor_pos);
|
||||
|
||||
// Clear any selection and set the selection
|
||||
// cursor for any new selection.
|
||||
@ -268,6 +265,6 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
|
||||
|
||||
void recordUndo(BufferView * bv, Undo::undo_kind kind)
|
||||
{
|
||||
recordUndo(bv, kind, bv->text->cursor.par());
|
||||
recordUndo(bv, kind, bv->text->cursorPar());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user