namespace {
-bool positionable(DocIterator const & cursor, DocIterator const & anchor)
-{
- // avoid deeper nested insets when selecting
- if (cursor.depth() > anchor.depth())
- return false;
-
- // anchor might be deeper, should have same path then
- for (size_t i = 0; i < cursor.depth(); ++i)
- if (&cursor[i].inset() != &anchor[i].inset())
- return false;
-
- // position should be ok.
- return true;
-}
-
-
// Find position closest to (x, y) in cell given by iter.
// Used only in mathed
DocIterator bruteFind2(Cursor const & c, int x, int y)
CursorData::CursorData()
: DocIterator(), anchor_(),
selection_(false), mark_(false), word_selection_(false),
- logicalpos_(false), current_font(inherit_font)
+ logicalpos_(false), current_font(inherit_font),
+ autocorrect_(false), macromode_(false)
{}
CursorData::CursorData(Buffer * buffer)
: DocIterator(buffer), anchor_(),
selection_(false), mark_(false), word_selection_(false),
- logicalpos_(false), current_font(inherit_font)
+ logicalpos_(false), current_font(inherit_font),
+ autocorrect_(false), macromode_(false)
{}
CursorData::CursorData(DocIterator const & dit)
: DocIterator(dit), anchor_(),
selection_(false), mark_(false), word_selection_(false),
- logicalpos_(false), current_font(inherit_font)
+ logicalpos_(false), current_font(inherit_font),
+ autocorrect_(false), macromode_(false)
{}
+
+
+ostream & operator<<(ostream & os, CursorData const & cur)
+{
+ os << "\n cursor: | anchor:\n";
+ for (size_t i = 0, n = cur.depth(); i != n; ++i) {
+ os << " " << cur[i] << " | ";
+ if (i < cur.anchor_.depth())
+ os << cur.anchor_[i];
+ else
+ os << "-------------------------------";
+ os << "\n";
+ }
+ for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
+ os << "------------------------------- | " << cur.anchor_[i] << "\n";
+ }
+ os << " selection: " << cur.selection_
+// << " x_target: " << cur.x_target_
+ << " boundary: " << cur.boundary() << endl;
+ return os;
+}
+
+
+LyXErr & operator<<(LyXErr & os, CursorData const & cur)
+{
+ os.stream() << cur;
+ return os;
+}
+
+
// be careful: this is called from the bv's constructor, too, so
// bv functions are not yet available!
Cursor::Cursor(BufferView & bv)
: CursorData(&bv.buffer()), bv_(&bv),
- x_target_(-1), textTargetOffset_(0)
+ x_target_(-1), textTargetOffset_(0),
+ beforeDispatchPosX_(0), beforeDispatchPosY_(0)
{}
Cursor new_cur = *this; // where we will move to
pos_type left_pos; // position visually left of current cursor
pos_type right_pos; // position visually right of current cursor
- bool new_pos_is_RTL; // is new position we're moving to RTL?
getSurroundingPos(left_pos, right_pos);
// we're currently to the left of 'right_pos'). In
// order to move to the right, it depends whether or
// not the character at 'right_pos' is RTL.
- new_pos_is_RTL = paragraph().getFontSettings(
+ bool const new_pos_is_RTL = paragraph().getFontSettings(
buffer()->params(), right_pos).isVisibleRightToLeft();
// If the character at 'right_pos' *is* LTR, then in
// order to move to the right of it, we need to be
Cursor new_cur = *this; // where we will move to
pos_type left_pos; // position visually left of current cursor
pos_type right_pos; // position visually right of current cursor
- bool new_pos_is_RTL; // is new position we're moving to RTL?
getSurroundingPos(left_pos, right_pos);
// currently to the right of 'left_pos'). In order to
// move to the left, it depends whether or not the
// character at 'left_pos' is RTL.
- new_pos_is_RTL = paragraph().getFontSettings(
+ bool const new_pos_is_RTL = paragraph().getFontSettings(
buffer()->params(), left_pos).isVisibleRightToLeft();
// If the character at 'left_pos' *is* RTL, then in
// order to move to the left of it, we need to be
void Cursor::setSelection()
{
setSelection(true);
- // A selection with no contents is not a selection
- // FIXME: doesnt look ok
if (idx() == normalAnchor().idx() &&
pit() == normalAnchor().pit() &&
pos() == normalAnchor().pos())
setSelection(sel);
return true;
}
-
-
-ostream & operator<<(ostream & os, Cursor const & cur)
-{
- os << "\n cursor: | anchor:\n";
- for (size_t i = 0, n = cur.depth(); i != n; ++i) {
- os << " " << cur[i] << " | ";
- if (i < cur.anchor_.depth())
- os << cur.anchor_[i];
- else
- os << "-------------------------------";
- os << "\n";
- }
- for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
- os << "------------------------------- | " << cur.anchor_[i] << "\n";
- }
- os << " selection: " << cur.selection_
- << " x_target: " << cur.x_target_ << endl;
- return os;
-}
-
-
-LyXErr & operator<<(LyXErr & os, Cursor const & cur)
-{
- os.stream() << cur;
- return os;
-}
-
-
} // namespace lyx
next_row = 0;
}
}
- top().pos() = min(tm.x2pos(pit(), next_row, xo), top().lastpos());
- int const xpos = tm.x2pos(pit(), next_row, xo);
- bool const at_end_row = xpos == tm.x2pos(pit(), next_row, tm.width());
- bool const at_beg_row = xpos == tm.x2pos(pit(), next_row, 0);
-
- if (at_end_row && at_beg_row)
- // make sure the cursor ends up on this row
- boundary(false);
- else
- boundary(at_end_row);
+ Row const & real_next_row = tm.parMetrics(pit()).rows()[next_row];
+ bool bound = false;
+ top().pos() = tm.getPosNearX(real_next_row, xo, bound);
+ boundary(bound);
updateNeeded |= bv().checkDepm(*this, old);
}
{
setBuffer(&bv_->buffer());
DocIterator::sanitize();
- anchor_.sanitize();
+ if (selection())
+ anchor_.sanitize();
+ else
+ resetAnchor();
}
}
-void Cursor::recordUndo(UndoKind kind, pit_type from, pit_type to) const
+void Cursor::recordUndo(pit_type from, pit_type to) const
{
- buffer()->undo().recordUndo(*this, kind, from, to);
+ buffer()->undo().recordUndo(*this, from, to);
}
-void Cursor::recordUndo(UndoKind kind, pit_type from) const
+void Cursor::recordUndo(pit_type from) const
{
- buffer()->undo().recordUndo(*this, kind, from);
+ buffer()->undo().recordUndo(*this, from, pit());
}
}
-void Cursor::recordUndoInset(UndoKind kind, Inset const * inset) const
+void Cursor::recordUndoInset(Inset const * in) const
+{
+ if (!in || in == &inset()) {
+ CursorData c = *this;
+ c.pop_back();
+ buffer()->undo().recordUndo(c, c.pit(), c.pit());
+ } else if (in == nextInset())
+ recordUndo();
+ else
+ LYXERR0("Inset not found, no undo element added.");
+}
+
+
+void Cursor::recordUndoFullBuffer() const
{
- buffer()->undo().recordUndoInset(*this, kind, inset);
+ buffer()->undo().recordUndoFullBuffer(*this);
}
-void Cursor::recordUndoFullDocument() const
+void Cursor::recordUndoBufferParams() const
{
- buffer()->undo().recordUndoFullDocument(*this);
+ buffer()->undo().recordUndoBufferParams(*this);
}
else
recordUndo();
} else {
- buffer()->undo().recordUndo(*this, ATOMIC_UNDO,
+ buffer()->undo().recordUndo(*this,
selBegin().pit(), selEnd().pit());
}
}