// translates LyXText pointer into offset count from document begin
-ParIterator text2pit(LyXText * text, int & tcount)
+ParIterator text2pit(BufferView * bv, LyXText * text, int & tcount)
{
tcount = 0;
Buffer * buf = text->bv()->buffer();
ParIterator pit = buf->par_iterator_begin();
ParIterator end = buf->par_iterator_end();
- // it.text() returns 0 for outermost text.
- if (text == text->bv()->text)
- return pit;
-
for ( ; pit != end; ++pit, ++tcount)
- if (pit.text() == text)
+ if (pit.text(bv) == text)
return pit;
lyxerr << "undo: should not happen" << std::endl;
return end;
}
-// translates offset from buffer begin to LyXText
-LyXText * pit2text(BufferView * bv, ParIterator const & pit)
-{
- LyXText * text = pit.text();
- return text ? text : bv->text;
-}
-
-
void recordUndo(Undo::undo_kind kind,
LyXText * text, paroffset_type first_par, paroffset_type last_par,
limited_stack<Undo> & stack)
// make and push the Undo entry
int textnum;
- ParIterator pit = text2pit(text, textnum);
+ ParIterator pit = text2pit(text->bv(), text, textnum);
stack.push(Undo(kind, textnum, pit.index(),
first_par, end_par, text->cursor.par(), text->cursor.pos()));
lyxerr << "undo record: " << stack.top() << std::endl;
{
lyxerr << "undo, performing: " << undo << std::endl;
ParIterator pit = num2pit(bv, undo.text);
- LyXText * text = pit2text(bv, pit);
+ LyXText * text = pit.text(bv);
ParagraphList & plist = text->ownerParagraphs();
// remove new stuff between first and last
advance(last, plist.size() - undo.end_par + 1);
otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last);
}
- LyXText * text = pit2text(bv, pit);
+ LyXText * text = pit.text(bv);
otherstack.top().cursor_pos = text->cursor.pos();
otherstack.top().cursor_par = text->cursor.par();
lyxerr << " undo other: " << otherstack.top() << std::endl;