Cursor::Cursor(BufferView & bv)
: DocIterator(&bv.buffer()), bv_(&bv), anchor_(),
x_target_(-1), textTargetOffset_(0),
- selection_(false), mark_(false), logicalpos_(false),
- current_font(inherit_font)
+ selection_(false), mark_(false), word_selection_(false),
+ logicalpos_(false), current_font(inherit_font)
{}
LYXERR(Debug::DEBUG, "Cursor::dispatch: (AtPoint) cmd: "
<< cmd0 << endl << *this);
nextInset()->dispatch(*this, tmpcmd);
- if (result().dispatched())
+ if (result().dispatched()) {
+ buffer()->undo().endUndoGroup();
return;
+ }
}
// store some values to be used inside of the handlers
void Cursor::setCursorToAnchor()
{
- if (selection())
- setCursor(anchor_);
+ if (selection()) {
+ DocIterator normal = anchor_;
+ while (depth() < normal.depth())
+ normal.pop_back();
+ if (depth() < anchor_.depth() && top() <= anchor_[depth() - 1])
+ ++normal.pos();
+ setCursor(normal);
+ }
}
void Cursor::clearSelection()
{
setSelection(false);
+ setWordSelection(false);
setMark(false);
resetAnchor();
}
{
MathData ar(buffer());
asArray(t, ar, f);
- if (ar.size() == 1 && (selection() || enter))
+ if (ar.size() == 1 && (enter || selection()))
niceInsert(ar[0]);
else
insert(ar);
cap::eraseSelection(*this);
cell().insert(pos(), ar);
pos() += ar.size();
+ // FIXME audit setBuffer/updateLabels calls
+ inset().setBuffer(bv_->buffer());
}
bool Cursor::fixIfBroken()
{
- if (DocIterator::fixIfBroken()) {
- clearSelection();
- return true;
+ bool const broken_cursor = DocIterator::fixIfBroken();
+ bool const broken_anchor = anchor_.fixIfBroken();
+
+ if (broken_cursor || broken_anchor) {
+ clearSelection();
+ return true;
}
return false;
}