* BufferView.cpp (setCursorFromInset): new method, useful to find
an inset that is known to be in the document.
* frontends/qt4/GuiView.cpp (dispatch): do a proper recordUndo
befire appplying changes to an inset. The insets are responsible
for recording additional undo steps that could be needed.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26428
a592a061-630c-0410-9148-
cb99ea01b6c8
}
+bool BufferView::setCursorFromInset(Inset const * inset)
+{
+ // are we already there?
+ if (cursor().nextInset() == inset)
+ return true;
+
+ // Inset is not at cursor position. Find it in the document.
+ Cursor cur(*this);
+ cur.reset(buffer().inset());
+ do
+ cur.forwardInset();
+ while (cur && cur.nextInset() != inset);
+
+ if (cur) {
+ setCursor(cur);
+ return true;
+ }
+ return false;
+}
+
+
void BufferView::gotoLabel(docstring const & label)
{
Toc & toc = buffer().tocBackend().toc("label");
/// set the cursor based on the given TeX source row.
void setCursorFromRow(int row);
+ /// set cursor to the given inset. Return true if found.
+ bool setCursorFromInset(Inset const *);
+
/// Ensure that the BufferView cursor is visible.
/// This method will automatically scroll and update the BufferView
/// if needed.
}
case LFUN_INSET_APPLY: {
- view()->cursor().recordUndoFullDocument();
string const name = cmd.getArg(0);
Inset * inset = getOpenInset(name);
if (inset) {
+ // put cursor in front of inset.
+ if (!view()->setCursorFromInset(inset))
+ LASSERT(false, /**/);
+
+ view()->cursor().recordUndo();
FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
inset->dispatch(view()->cursor(), fr);
} else {
+ view()->cursor().recordUndo();
FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
lyx::dispatch(fr);
}