}
// not quite sure if we want this...
- recordUndo(bv_, Undo::ATOMIC);
+ bv_->text->recUndo(bv_->text->cursor.par());
freezeUndo();
beforeChange(bv_->text);
+
+2003-10-13 André Pönitz <poenitz@gmx.net>
+
+ * BufferView_pimpl.C:
+ * lyxtext.h:
+ * text.C:
+ * text2.C:
+ * text3.C:
+ * undo_funcs.[Ch]: use paroffset_type instead of
+ ParagraphList::iterators to prevent multiple conversion
+ (and get a more robust interface)
+
2003-10-13 Lars Gullik Bjønnes <larsbj@gullik.net>
* lyxfunc.C (dispatch): RESULT -> dispatch_result
if (cmd.action == LFUN_INSET_EDIT) {
+ lyxerr << "InsetTabular::edit: " << this << " args: '"
+ << cmd.argument << "' first cell: "
+ << &tabular.cell_info[0][0].inset << endl;
+
if (!bv->lockInset(this)) {
- lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
+ lyxerr << "InsetTabular::Cannot lock inset" << endl;
return DISPATCHED;
}
if (cell != -1)
return tabular.getPWidth(cell).zero();
+ // this is a workaround for a crash (New, Insert->Tabular,
+ // Insert->FootNote)
+ if (!owner())
+ return false;
+
// well we didn't obviously find it so maybe our owner knows more
BOOST_ASSERT(owner());
return owner()->forceDefaultParagraphs(in);
if (text_.selection.set())
- recordUndo(bv, Undo::ATOMIC, text_.cursorPar());
+ text_.recUndo(text_.cursor.par());
if (selectall) {
text_.cursorTop();
lyx::pos_type pos,
LyXFont const & font) const;
+ ///
+ void recUndo(lyx::paroffset_type first, lyx::paroffset_type last) const;
+ ///
+ void recUndo(lyx::paroffset_type first) const;
///
void setCursorFromCoordinates(int x, int y);
///
&& layout->labeltype != LABEL_SENSITIVE)
return;
- recordUndo(bv(), Undo::ATOMIC, cursorPar());
+ recUndo(cursor.par());
// Always break behind a space
//
// same Paragraph one to the right and make a rebreak
void LyXText::insertChar(char c)
{
- recordUndo(bv(), Undo::INSERT, cursorPar());
+ recordUndo(bv(), Undo::INSERT, ownerParagraphs(), cursor.par(), cursor.par());
// When the free-spacing option is set for the current layout,
// disable the double-space checking
if (selection.start.par() == selection.end.par()) {
LyXCursor & startc = selection.start;
LyXCursor & endc = selection.end;
- recordUndo(bv(), Undo::INSERT, getPar(startc));
+ recordUndo(bv(), Undo::INSERT, ownerParagraphs(), startc.par());
getPar(startc)->acceptChange(startc.pos(), endc.pos());
finishUndo();
clearSelection();
if (selection.start.par() == selection.end.par()) {
LyXCursor & startc = selection.start;
LyXCursor & endc = selection.end;
- recordUndo(bv(), Undo::INSERT, getPar(startc));
+ recordUndo(bv(), Undo::INSERT, ownerParagraphs(), startc.par());
getPar(startc)->rejectChange(startc.pos(), endc.pos());
finishUndo();
clearSelection();
setCursor(to.par(), to.pos() + 1);
}
- recordUndo(bv(), Undo::ATOMIC, getPar(from), getPar(to));
+ recordUndo(bv(), Undo::ATOMIC, ownerParagraphs(), from.par(), to.par());
pos_type pos = from.pos();
int par = from.par();
// if you had success make a backspace
if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
- LyXCursor tmpcursor = cursor;
- // to make sure undo gets the right cursor position
- cursor = old_cursor;
- recordUndo(bv(), Undo::DELETE, cursorPar());
- cursor = tmpcursor;
+ recordUndo(bv(), Undo::DELETE, ownerParagraphs(), old_cursor.par());
backspace();
}
}
}
}
- if (cursorPar() != ownerParagraphs().begin()) {
- recordUndo(bv(), Undo::DELETE,
- boost::prior(cursorPar()),
- cursorPar());
- }
+ if (cursor.par() != 0)
+ recordUndo(bv(), Undo::DELETE, ownerParagraphs(),
+ cursor.par() - 1, cursor.par());
ParagraphList::iterator tmppit = cursorPar();
// We used to do cursorLeftIntern() here, but it is
} else {
// this is the code for a normal backspace, not pasting
// any paragraphs
- recordUndo(bv(), Undo::DELETE, cursorPar());
+ recordUndo(bv(), Undo::DELETE, ownerParagraphs(), cursor.par());
// 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,
ParagraphList::iterator LyXText::getPar(int par) const
{
BOOST_ASSERT(par >= 0);
- BOOST_ASSERT(par < ownerParagraphs().size());
+ BOOST_ASSERT(par < int(ownerParagraphs().size()));
ParagraphList::iterator pit = ownerParagraphs().begin();
std::advance(pit, par);
return pit;
// do we want to keep this?? (JMarc)
if (!isHighlyEditableInset(inset))
- recordUndo(bv(), Undo::ATOMIC);
+ recUndo(cursor.par());
if (inset->isOpen())
inset->close(bv());
++endpit;
}
- recordUndo(bv(), Undo::ATOMIC, getPar(sstart_cur), boost::prior(undoendpit));
+ recUndo(sstart_cur.par(), parOffset(undoendpit) - 1);
// ok we have a selection. This is always between sstart_cur
// and sel_end cursor
ParagraphList::iterator pastend = boost::next(end);
if (!test_only)
- recordUndo(bv(), Undo::ATOMIC, start, end);
+ recUndo(parOffset(start), parOffset(end));
bool changed = false;
// ok we have a selection. This is always between sel_start_cursor
// and sel_end cursor
- recordUndo(bv(), Undo::ATOMIC, getPar(selection.start), getPar(selection.end));
+ recUndo(selection.start.par(), selection.end.par());
freezeUndo();
cursor = selection.start;
while (cursor.par() != selection.end.par() ||
++endpit;
}
- recordUndo(bv(), Undo::ATOMIC, getPar(selection.start),
- boost::prior(undoendpit));
+ recUndo(selection.start.par(), parOffset(undoendpit) - 1);
int tmppit = selection.end.par();
{
if (!cursorPar()->insetAllowed(inset->lyxCode()))
return;
- recordUndo(bv(), Undo::ATOMIC, cursorPar());
+ recUndo(cursor.par());
freezeUndo();
cursorPar()->insertInset(cursor.pos(), inset);
// Just to rebreak and refresh correctly.
++endpit;
}
- recordUndo(bv(), Undo::DELETE, getPar(selection.start),
- boost::prior(undoendpit));
+ recUndo(selection.start.par(), parOffset(undoendpit) - 1);
endpit = getPar(selection.end.par());
int endpos = selection.end.pos();
if (!CutAndPaste::checkPastePossible())
return;
- recordUndo(bv(), Undo::INSERT, cursorPar());
+ recUndo(cursor.par());
ParagraphList::iterator endpit;
PitPosPair ppp;
// simple replacing. The font of the first selected character is used
void LyXText::replaceSelectionWithString(string const & str)
{
- recordUndo(bv(), Undo::ATOMIC);
+ recUndo(cursor.par());
freezeUndo();
if (!selection.set()) { // create a dummy selection
pos_type pos = cursor.pos();
ParagraphList::iterator endpit = boost::next(cursorPar());
- recordUndo(bv(), Undo::ATOMIC);
+ recUndo(cursor.par());
// only to be sure, should not be neccessary
clearSelection();
while (endpit != ownerParagraphs().end() && endpit->getDepth())
++endpit;
- recordUndo(bv(), Undo::DELETE, old_pit, boost::prior(endpit));
+ recUndo(parOffset(old_pit), parOffset(endpit) - 1);
cursor = tmpcursor;
// delete old par
}
+void LyXText::recUndo(paroffset_type first, paroffset_type last) const
+{
+ recordUndo(bv(), Undo::ATOMIC, ownerParagraphs(), first, last);
+}
+
+
+void LyXText::recUndo(lyx::paroffset_type par) const
+{
+ recordUndo(bv(), Undo::ATOMIC, ownerParagraphs(), par, par);
+}
+
+
bool LyXText::isInInset() const
{
// Sub-level has non-null bv owner and non-null inset owner.
for (; tmp != end; ++tmp) {
if (tmp->params().startOfAppendix()) {
- recordUndo(bv, Undo::ATOMIC, tmp);
+ recUndo(parOffset(tmp));
tmp->params().startOfAppendix(false);
redoParagraph(tmp);
break;
}
}
- recordUndo(bv, Undo::ATOMIC, pit);
+ recUndo(parOffset(pit));
pit->params().startOfAppendix(start);
// we can set the refreshing parameters now
break;
case LFUN_TRANSPOSE_CHARS:
- recordUndo(bv, Undo::ATOMIC, cursorPar());
+ recUndo(cursor.par());
redoParagraph();
bv->update();
break;
// ...or maybe the recordUndo()
// below isn't necessary at all anylonger?
if (inset_hit->lyxCode() == InsetOld::REF_CODE)
- recordUndo(bv, Undo::ATOMIC);
+ recUndo(cursor.par());
bv->owner()->message(inset_hit->editMessage());
#include "undo_funcs.h"
#include "buffer.h"
+#include "debug.h"
#include "BufferView.h"
#include "funcrequest.h"
#include "iterators.h"
#include "insets/updatableinset.h"
+#include <iostream>
-/// The flag used by FinishUndo().
+using std::endl;
+using lyx::paroffset_type;
+
+
+/// The flag used by finishUndo().
bool undo_finished;
/// Whether actions are not added to the undo stacks.
void recordUndo(BufferView * bv, Undo::undo_kind kind,
- ParagraphList::iterator first, ParagraphList::iterator last,
+ ParagraphList & plist, paroffset_type firstpar, paroffset_type lastpar,
limited_stack<Undo> & stack)
{
Buffer * buf = bv->buffer();
+ ParagraphList::iterator first = plist.begin();
+ advance(first, firstpar);
+ ParagraphList::iterator last = plist.begin();
+ advance(last, lastpar);
+
// First, record inset id, if cursor is in one
UpdatableInset * inset = first->inInset();
LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
int const inset_id = inset ? inset->id() : -1;
// We simply record the entire outer paragraphs
- ParagraphList & plist = buf->paragraphs();
ParIterator null = buf->par_iterator_end();
// First, identify the outer paragraphs
}
// And calculate a stable reference to them
- int const first_offset = std::distance(plist.begin(), first);
- int const last_offset = std::distance(last, plist.end());
+ int const first_offset = firstpar;
+ int const last_offset = plist.size() - lastpar;
// Undo::ATOMIC are always recorded (no overlapping there).
cursor_offset, text->cursor.pos(),
ParagraphList()));
+ lyxerr << "G" << endl;
// Record the relevant paragraphs
ParagraphList & undo_pars = stack.top().pars;
// Returns false if no undo possible.
-bool performUndoOrRedo(BufferView * bv, Undo & undo)
+bool performUndoOrRedo(BufferView * bv, Undo const & undo)
{
Buffer * buf = bv->buffer();
ParagraphList & plist = buf->paragraphs();
LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
text->setCursorIntern(undo.cursor_par_offset, undo.cursor_pos);
+ lyxerr << "undo, inset: " << inset << endl;
+
if (inset) {
+ lyxerr << "undo, inset owner: " << inset->owner() << endl;
+
// Magic needed to update inset internal state
FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
- inset->localDispatch(cmd);
+ if (inset->owner())
+ inset->owner()->localDispatch(cmd);
+ else
+ inset->localDispatch(cmd);
}
// set cursor again to force the position to be the right one
void recordUndo(BufferView * bv, Undo::undo_kind kind,
- ParagraphList::iterator first, ParagraphList::iterator last)
+ ParagraphList & plist, paroffset_type first, paroffset_type last)
{
if (!undo_frozen) {
- recordUndo(bv, kind, first, last, bv->buffer()->undostack());
+ recordUndo(bv, kind, plist, first, last, bv->buffer()->undostack());
bv->buffer()->redostack().clear();
}
}
void recordUndo(BufferView * bv, Undo::undo_kind kind,
- ParagraphList::iterator first)
+ ParagraphList & plist, paroffset_type par)
{
- recordUndo(bv, kind, first, first);
+ recordUndo(bv, kind, plist, par, par);
}
void recordUndo(BufferView * bv, Undo::undo_kind kind)
{
- recordUndo(bv, kind, bv->text->cursorPar());
+ recordUndo(bv, kind, bv->text->ownerParagraphs(), bv->text->cursor.par());
}
-
#include "undo.h"
#include "ParagraphList_fwd.h"
+#include "support/types.h"
class BufferView;
class Paragraph;
* will record the original information of the paragraphs in the undo stack.
*/
void recordUndo(BufferView *, Undo::undo_kind kind,
- ParagraphList::iterator first, ParagraphList::iterator last);
+ ParagraphList & plist, lyx::paroffset_type first, lyx::paroffset_type last);
+
/// Convienience: Prepare undo when change in a single paragraph.
void recordUndo(BufferView *, Undo::undo_kind kind,
- ParagraphList::iterator first);
+ ParagraphList & plist, lyx::paroffset_type par);
/// Convienience: Prepare undo for the paragraph that contains the cursor
void recordUndo(BufferView *, Undo::undo_kind kind);