break;
// no break here!
case LFUN_DELETE:
- setUndo(bv, Undo::DELETE, bv->text->cursor.par());
+ setUndo(bv, Undo::DELETE);
cutSelection(bv->buffer()->params);
updateLocal(bv, INIT);
break;
}
case LFUN_PASTE:
if (hasPasteBuffer()) {
- setUndo(bv, Undo::INSERT, bv->text->cursor.par());
+ setUndo(bv, Undo::INSERT);
pasteSelection(bv);
updateLocal(bv, INIT);
break;
setSelection(0, tabular.getNumberOfCells() - 1);
}
if (hasSelection()) {
- setUndo(bv, Undo::EDIT, bv->text->cursor.par());
+ setUndo(bv, Undo::EDIT);
bool const frozen = undo_frozen;
if (!frozen)
freezeUndo();
sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
}
- setUndo(bv, Undo::FINISH, bv->text->cursor.par());
+ setUndo(bv, Undo::FINISH);
int row = tabular.row_of_cell(actcell);
int column = tabular.column_of_cell(actcell);
break;
}
- if (it != end && t->cursor.pos() <= it->size()) {
- sstate.lpar = t->cursor.par();
- sstate.pos = t->cursor.pos();
- sstate.boundary = t->cursor.boundary();
- sstate.selstartpar = t->selection.start.par();
- sstate.selstartpos = t->selection.start.pos();
- sstate.selstartboundary = t->selection.start.boundary();
- sstate.selendpar = t->selection.end.par();
- sstate.selendpos = t->selection.end.pos();
- sstate.selendboundary = t->selection.end.boundary();
- sstate.selection = t->selection.set();
- sstate.mark_set = t->selection.mark();
- } else {
- sstate.lpar = const_cast<ParagraphList&>(paragraphs).end();
- }
+ if (it != end && t->cursor.pos() <= it->size())
+ sstate = *t; // slicing intended
+ else
+ sstate.cursor.par(end);
}
void InsetText::restoreLyXTextState(LyXText * t) const
{
- if (sstate.lpar == const_cast<ParagraphList&>(paragraphs).end())
+ if (sstate.cursor.par() == const_cast<ParagraphList&>(paragraphs).end())
return;
t->selection.set(true);
- /* at this point just to avoid the DEPM when setting the cursor */
- t->selection.mark(sstate.mark_set);
- if (sstate.selection) {
- t->setCursor(sstate.selstartpar, sstate.selstartpos,
- true, sstate.selstartboundary);
+ // at this point just to avoid the DEPM when setting the cursor
+ t->selection.mark(sstate.selection.mark());
+ if (sstate.selection.set()) {
+ t->setCursor(sstate.selection.start.par(),
+ sstate.selection.start.pos(),
+ true, sstate.selection.start.boundary());
t->selection.cursor = t->cursor;
- t->setCursor(sstate.selendpar, sstate.selendpos,
- true, sstate.selendboundary);
+ t->setCursor(sstate.selection.end.par(), sstate.selection.end.pos(),
+ true, sstate.selection.end.boundary());
t->setSelection();
- t->setCursor(sstate.lpar, sstate.pos);
+ t->setCursor(sstate.cursor.par(), sstate.cursor.pos());
} else {
- t->setCursor(sstate.lpar, sstate.pos, true, sstate.boundary);
+ t->setCursor(sstate.cursor.par(), sstate.cursor.pos(),
+ true, sstate.cursor.boundary());
t->selection.cursor = t->cursor;
t->selection.set(false);
}
old_par = paragraphs.end();
last_drawn_width = -1;
cached_bview = 0;
- sstate.lpar = paragraphs.end();
+ sstate.cursor.par(paragraphs.end());
in_insetAllowed = false;
}
if (locked) {
saveLyXTextState(it->second.text.get());
} else {
- sstate.lpar = const_cast<ParagraphList&>(paragraphs).end();
+ sstate.cursor.par(const_cast<ParagraphList&>(paragraphs).end());
}
}
//
#define INSETTEXT_H
#include "updatableinset.h"
+#include "textcursor.h"
#include "LString.h"
#include "LColor.h"
#include "ParagraphList.h"
mutable BufferView * cached_bview;
///
mutable boost::shared_ptr<LyXText> cached_text;
- ///
- struct save_state {
- ParagraphList::iterator lpar;
- ParagraphList::iterator selstartpar;
- ParagraphList::iterator selendpar;
- lyx::pos_type pos;
- lyx::pos_type selstartpos;
- lyx::pos_type selendpos;
- bool boundary;
- bool selstartboundary;
- bool selendboundary;
- bool selection;
- bool mark_set;
- };
- ///
- mutable save_state sstate;
+
+ /// some funny 'temporarily saved state'
+ mutable TextCursor sstate;
///
// this is needed globally so we know that we're using it actually and
#include "insets/inset.h"
#include "RowList.h"
#include "bufferview_funcs.h"
+#include "textcursor.h"
class Buffer;
class BufferParams;
/**
This class holds the mapping between buffer paragraphs and screen rows.
*/
-class LyXText {
+
+// The inheritance from TextCursor should go. It's just there to ease
+// transition...
+class LyXText : public TextCursor {
public:
/// what repainting is needed
enum refresh_status {
return rowlist_;
}
- /** The cursor.
- Later this variable has to be removed. There should be now internal
- cursor in a text (and thus not in a buffer). By keeping this it is
- (I think) impossible to have several views with the same buffer, but
- the cursor placed at different places.
- [later]
- Since the LyXText now has been moved from Buffer to BufferView
- it should not be absolutely needed to move the cursor...
- */
- LyXCursor cursor; // actual cursor position
-
- /** The structure that keeps track of the selections set. */
- struct Selection {
- Selection()
- : set_(false), mark_(false)
- {}
- bool set() const {
- return set_;
- }
- void set(bool s) {
- set_ = s;
- }
- bool mark() const {
- return mark_;
- }
- void mark(bool m) {
- mark_ = m;
- }
- LyXCursor cursor; // temporary cursor to hold a cursor position
- // until setSelection is called!
- LyXCursor start; // start of a REAL selection
- LyXCursor end; // end of a REAL selection
- private:
- bool set_; // former selection
- bool mark_; // former mark_set
-
- };
- Selection selection;
- // this is used to handle XSelection events in the right manner
- Selection xsel_cache;
-
- /// needed for the toggling (cursor position on last selection made)
- LyXCursor last_sel_cursor;
- /// needed for toggling the selection in screen.C
- LyXCursor toggle_cursor;
- /// needed for toggling the selection in screen.C
- LyXCursor toggle_end_cursor;
-
+
/// need the selection cursor:
void setSelection();
///
/// return true if this is owned by an inset.
bool isInInset() const;
+
+private:
+ /** Cursor related data.
+ Later this variable has to be removed. There should be now internal
+ cursor in a text */
+ ///
+ ///TextCursor cursor_;
};
/// return the default height of a row in pixels, considering font zoom
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file cursor.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author Lars Gullik Bjønnes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include "lyxcursor.h"
+
+#ifndef TEXTCURSOR_H
+#define TEXTCURSOR_H
+
+/** The cursor.
+ Later this variable has to be removed. There should be now internal
+ cursor in a text (and thus not in a buffer). By keeping this it is
+ (I think) impossible to have several views with the same buffer, but
+ the cursor placed at different places.
+ [later]
+ Since the LyXText now has been moved from Buffer to BufferView
+ it should not be absolutely needed to move the cursor...
+ [even later]
+ It should neverthe less to keep classes and intedependencies small
+ */
+
+// The structure that keeps track of the selections set.
+struct Selection {
+ Selection()
+ : set_(false), mark_(false)
+ {}
+ bool set() const {
+ return set_;
+ }
+ void set(bool s) {
+ set_ = s;
+ }
+ bool mark() const {
+ return mark_;
+ }
+ void mark(bool m) {
+ mark_ = m;
+ }
+ LyXCursor cursor; // temporary cursor to hold a cursor position
+ // until setSelection is called!
+ LyXCursor start; // start of a REAL selection
+ LyXCursor end; // end of a REAL selection
+private:
+ bool set_; // former selection
+ bool mark_; // former mark_set
+
+};
+
+struct TextCursor {
+ // actual cursor position
+ LyXCursor cursor;
+
+ Selection selection;
+ // this is used to handle XSelection events in the right manner
+ Selection xsel_cache;
+
+ /// needed for the toggling (cursor position on last selection made)
+ LyXCursor last_sel_cursor;
+ /// needed for toggling the selection in screen.C
+ LyXCursor toggle_cursor;
+ /// needed for toggling the selection in screen.C
+ LyXCursor toggle_end_cursor;
+};
+
+#endif
}
+void setUndo(BufferView * bv, Undo::undo_kind kind)
+{
+ setUndo(bv, kind, bv->text->cursor.par());
+}
+
+
void setUndo(BufferView * bv, Undo::undo_kind kind,
ParagraphList::iterator first)
{
ParagraphList::iterator first, ParagraphList::iterator last);
void setUndo(BufferView *, Undo::undo_kind kind,
ParagraphList::iterator first);
+// set undo for containing paragraph
+void setUndo(BufferView *, Undo::undo_kind kind);
/// FIXME
void setCursorParUndo(BufferView *);