try to position cusor correctly after undo

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7107 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-06-04 16:14:36 +00:00
parent c2933d528f
commit 4b14c1d9be
3 changed files with 56 additions and 52 deletions

View File

@ -359,6 +359,8 @@ string const currentState(BufferView * bv)
} }
#ifdef DEVEL_VERSION #ifdef DEVEL_VERSION
state << _(", Paragraph: ") << text->cursor.par()->id(); state << _(", Paragraph: ") << text->cursor.par()->id();
state << " Inset: " <<
(text->cursor.par()->inInset() ? text->cursor.par()->inInset()->id() : -1);
#endif #endif
return STRCONV(state.str()); return STRCONV(state.str());
} }

View File

@ -1363,9 +1363,11 @@ void Paragraph::id(int i)
LyXLayout_ptr const & Paragraph::layout() const LyXLayout_ptr const & Paragraph::layout() const
{ {
/*
Inset * inset = inInset(); Inset * inset = inInset();
if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE) if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE)
return static_cast<InsetEnvironment*>(inset)->layout(); return static_cast<InsetEnvironment*>(inset)->layout();
*/
return layout_; return layout_;
} }

View File

@ -60,11 +60,9 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
*/ */
// Set the right(new) inset-owner of the paragraph if there is any. // Set the right(new) inset-owner of the paragraph if there is any.
UpdatableInset * inset = 0; UpdatableInset * inset =
if (undo.inset_id >= 0) { static_cast<UpdatableInset *>(buf->getInsetFromID(undo.inset_id));
Inset * in = bv->buffer()->getInsetFromID(undo.inset_id);
inset = static_cast<UpdatableInset *>(in);
}
ParagraphList::iterator pit = undo.pars.begin(); ParagraphList::iterator pit = undo.pars.begin();
ParagraphList::iterator end = undo.pars.end(); ParagraphList::iterator end = undo.pars.end();
for ( ; pit != end; ++pit) for ( ; pit != end; ++pit)
@ -72,8 +70,10 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
lyxerr << "\nhandle: inset_id: " << undo.inset_id << "\n"; lyxerr << "\nhandle: inset_id: " << undo.inset_id << "\n";
lyxerr << "handle: inset: " << inset << "\n"; lyxerr << "handle: inset: " << inset << "\n";
lyxerr << "handle: plist_id: " << undo.plist_id << "\n"; //lyxerr << "handle: plist_id: " << undo.plist_id << "\n";
lyxerr << "handle: undo.pars.size(): " << undo.pars.size() << "\n"; lyxerr << "handle: undo.pars.size(): " << undo.pars.size() << "\n";
lyxerr << "handle: first_offset: " << undo.first_par_offset << "\n";
lyxerr << "handle: last_offset: " << undo.last_par_offset << "\n";
// remove stuff between first and behind // remove stuff between first and behind
{ {
@ -83,16 +83,19 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
advance(last, plist->size() - undo.last_par_offset); advance(last, plist->size() - undo.last_par_offset);
lyxerr << "handle: first_id: " << first->id() << "\n"; lyxerr << "handle: first_id: " << first->id() << "\n";
lyxerr << "handle: last_id: " << last->id() << "\n"; lyxerr << "handle: last_id: " << last->id() << "\n";
lyxerr << "handle: remove: " << distance(first, last) + 1 << " pars\n";
plist->erase(first, ++last); plist->erase(first, ++last);
lyxerr << "after remove\n"; lyxerr << "handle: after remove\n";
} }
// re-insert old stuff // re-insert old stuff
{ {
ParagraphList::iterator first = plist->begin(); ParagraphList::iterator first = plist->begin();
advance(first, undo.first_par_offset); advance(first, undo.first_par_offset);
lyxerr << "handle: plist->size: " << plist->size() << "\n";
lyxerr << "handle: offset: " << undo.first_par_offset << "\n";
plist->insert(first, undo.pars.begin(), undo.pars.end()); plist->insert(first, undo.pars.begin(), undo.pars.end());
lyxerr << "after insert\n"; lyxerr << "handle: after insert\n";
} }
/* /*
@ -107,36 +110,26 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
*/ */
// redo Paragraphs (should be handled outside undo...) // redo Paragraphs (should be handled outside undo...)
LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
{ {
lyxerr << "text: " << text << "\n"; //LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
LyXText * text = bv->text;
lyxerr << "handle: text: " << text << "\n";
if (undo.first_par_offset) { if (undo.first_par_offset) {
ParagraphList::iterator redo = plist->begin(); ParagraphList::iterator redo = plist->begin();
lyxerr << "handle: 1\n";
advance(redo, undo.first_par_offset); advance(redo, undo.first_par_offset);
lyxerr << "handle: 2\n";
text->setCursorIntern(plist->begin(), 0); text->setCursorIntern(plist->begin(), 0);
} }
lyxerr << "handle: 3\n";
text->redoParagraphs(text->cursor, plist->end()); text->redoParagraphs(text->cursor, plist->end());
lyxerr << "after redo\n"; lyxerr << "handle: after redo\n";
}
/* if (inset) {
Inset * = bv->buffer()->getInsetFromID(inset_id); FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
lyxerr << "tmppar: " << tmppar->id() << "\n"; inset->localDispatch(cmd);
LyXText * t; }
if (it) {
FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
it->localDispatch(cmd);
t = it->getLyXText(bv);
} else {
t = bv->text;
} }
t->setCursorIntern(*tmppar, undo.cursor_pos);
// Clear any selection and set the selection
// cursor for an evt. new selection.
t->clearSelection();
t->selection.cursor = t->cursor;
t->updateCounters();
*/
if (inset) { if (inset) {
lyxerr << "fit cursor...\n"; lyxerr << "fit cursor...\n";
@ -146,9 +139,15 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
// set cursor // set cursor
{ {
ParagraphList::iterator cursor = plist->begin(); LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
ParagraphList::iterator cursor = text->ownerParagraphs().begin();
advance(cursor, undo.cursor_par_offset); advance(cursor, undo.cursor_par_offset);
bv->text->setCursorIntern(cursor, undo.cursor_pos); text->setCursorIntern(cursor, undo.cursor_pos);
// Clear any selection and set the selection
// cursor for an evt. new selection.
text->clearSelection();
text->selection.cursor = text->cursor;
text->updateCounters();
lyxerr << "after setCursor\n"; lyxerr << "after setCursor\n";
} }
@ -172,6 +171,10 @@ void createUndo(BufferView * bv, Undo::undo_kind kind,
lyxerr << "\n"; lyxerr << "\n";
UpdatableInset * inset = first->inInset();
LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
int const inset_id = inset ? inset->id() : -1;
#if 0 #if 0
// this is what we'd like to have in the end for small grained undo // this is what we'd like to have in the end for small grained undo
for (ParIterator it = buf->par_iterator_begin(); it != null; ++it) { for (ParIterator it = buf->par_iterator_begin(); it != null; ++it) {
@ -198,23 +201,13 @@ void createUndo(BufferView * bv, Undo::undo_kind kind,
#endif #endif
int const inset_id = first->inInset() ? first->inInset()->id() : -1;
int const first_offset = std::distance(plist->begin(), first); int const first_offset = std::distance(plist->begin(), first);
int const last_offset = std::distance(last, plist->end()); int const last_offset = std::distance(last, plist->end());
if (last == plist->end()) { if (last == plist->end()) {
lyxerr << "*** createUndo: last == end schould not happen\n"; lyxerr << "*** createUndo: last == end should not happen\n";
} }
//lyxerr << "create: plist_id: " << plist->id() << "\n";
lyxerr << "create: first_id: " << first->id() << "\n";
lyxerr << "create: last_id: " << last->id() << "\n";
lyxerr << "create: first_offset: " << first_offset << "\n";
lyxerr << "create: last_offset: " << last_offset << "\n";
lyxerr << "create: inset_id: " << inset_id << "\n";
lyxerr << "create: kind: " << kind << "\n";
// Undo::EDIT and Undo::FINISH are // Undo::EDIT and Undo::FINISH are
// always finished. (no overlapping there) // always finished. (no overlapping there)
@ -235,17 +228,24 @@ void createUndo(BufferView * bv, Undo::undo_kind kind,
} }
// Create a new Undo. // Create a new Undo.
/* int const cursor_offset = std::distance
// this should be re-activated once we are back at fine-grained undo (text->ownerParagraphs().begin(), text->cursor.par());
LyXCursor const & cur = bv->theLockingInset() ?
bv->theLockingInset()->cursor(bv) : bv->text->cursor; //lyxerr << "create: plist_id: " << plist->id() << "\n";
int const cursor_offset = std::distance(plist->begin(), cur.par()); lyxerr << "create: inset_id: " << inset_id << "\n";
lyxerr << "create: first_id: " << first->id() << "\n";
lyxerr << "create: last_id: " << last->id() << "\n";
lyxerr << "create: first_offset: " << first_offset << "\n";
lyxerr << "create: last_offset: " << last_offset << "\n";
lyxerr << "create: cursor_offset: " << cursor_offset << "\n";
lyxerr << "create: cursor_pos: " << text->cursor.pos() << "\n";
stack.push(Undo(kind, inset_id, plist->id(),
first_offset, last_offset, cursor_offset, cur.pos(), ParagraphList()));
*/
stack.push(Undo(kind, inset_id, 0, //plist->id(), stack.push(Undo(kind, inset_id, 0, //plist->id(),
first_offset, last_offset, first_offset, 0, ParagraphList())); first_offset, last_offset,
cursor_offset, text->cursor.pos(),
ParagraphList()));
//stack.push(Undo(kind, inset_id, 0,
// first_offset, last_offset, first_offset, 0, ParagraphList()));
ParagraphList & undo_pars = stack.top().pars; ParagraphList & undo_pars = stack.top().pars;