Rename Cursor::setSelection(bool) to selection(bool)

The old name would be confusing wrt setSelection(), which does additional checks.
This one is a pure acessor, and the more complete methods are
* setSelection(), which avoids empty selections
* clearSelection(), which resets anchor, and sets word selection and mark more to false.

Most of the code should use these two instead of selection(bool), but this is for later.
This commit is contained in:
Jean-Marc Lasgouttes 2016-02-28 17:36:29 +01:00 committed by Richard Heck
parent 9fbee19a7f
commit 83d8e12cc1
11 changed files with 47 additions and 47 deletions

View File

@ -1587,7 +1587,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break; break;
case LFUN_MARK_TOGGLE: case LFUN_MARK_TOGGLE:
cur.setSelection(false); cur.selection(false);
if (cur.mark()) { if (cur.mark()) {
cur.setMark(false); cur.setMark(false);
dr.setMessage(from_utf8(N_("Mark removed"))); dr.setMessage(from_utf8(N_("Mark removed")));
@ -1786,7 +1786,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
// Select the inset from outside. // Select the inset from outside.
cur.pop(); cur.pop();
cur.resetAnchor(); cur.resetAnchor();
cur.setSelection(true); cur.selection(true);
cur.posForward(); cur.posForward();
} else if (cells_selected) { } else if (cells_selected) {
// At least one complete cell is selected and inset is a table. // At least one complete cell is selected and inset is a table.
@ -1794,7 +1794,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
cur.idx() = 0; cur.idx() = 0;
cur.pos() = 0; cur.pos() = 0;
cur.resetAnchor(); cur.resetAnchor();
cur.setSelection(true); cur.selection(true);
cur.idx() = cur.lastidx(); cur.idx() = cur.lastidx();
cur.pos() = cur.lastpos(); cur.pos() = cur.lastpos();
} else { } else {
@ -1802,7 +1802,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
cur.pit() = 0; cur.pit() = 0;
cur.pos() = 0; cur.pos() = 0;
cur.resetAnchor(); cur.resetAnchor();
cur.setSelection(true); cur.selection(true);
cur.pit() = cur.lastpit(); cur.pit() = cur.lastpit();
cur.pos() = cur.lastpos(); cur.pos() = cur.lastpos();
} }
@ -2187,7 +2187,7 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
Cursor old = cursor(); Cursor old = cursor();
Cursor cur(*this); Cursor cur(*this);
cur.push(buffer_.inset()); cur.push(buffer_.inset());
cur.setSelection(d->cursor_.selection()); cur.selection(d->cursor_.selection());
// Either the inset under the cursor or the // Either the inset under the cursor or the
// surrounding Text will handle this event. // surrounding Text will handle this event.
@ -2374,7 +2374,7 @@ void BufferView::setCursorFromRow(int row, TexRow const & texrow)
} }
d->cursor_.reset(); d->cursor_.reset();
buffer_.text().setCursor(d->cursor_, newpit, newpos); buffer_.text().setCursor(d->cursor_, newpit, newpos);
d->cursor_.setSelection(false); d->cursor_.selection(false);
d->cursor_.resetAnchor(); d->cursor_.resetAnchor();
recenter(); recenter();
} }
@ -2460,7 +2460,7 @@ void BufferView::setCursor(DocIterator const & dit)
dit[i].inset().edit(d->cursor_, true); dit[i].inset().edit(d->cursor_, true);
d->cursor_.setCursor(dit); d->cursor_.setCursor(dit);
d->cursor_.setSelection(false); d->cursor_.selection(false);
d->cursor_.setCurrentFont(); d->cursor_.setCurrentFont();
// FIXME // FIXME
// It seems on general grounds as if this is probably needed, but // It seems on general grounds as if this is probably needed, but
@ -2589,7 +2589,7 @@ bool BufferView::selectIfEmpty(DocIterator & cur)
d->cursor_.setCursor(cur); d->cursor_.setCursor(cur);
d->cursor_.pit() = beg_pit; d->cursor_.pit() = beg_pit;
d->cursor_.pos() = 0; d->cursor_.pos() = 0;
d->cursor_.setSelection(false); d->cursor_.selection(false);
d->cursor_.resetAnchor(); d->cursor_.resetAnchor();
d->cursor_.pit() = end_pit; d->cursor_.pit() = end_pit;
d->cursor_.pos() = end_pos; d->cursor_.pos() = end_pos;

View File

@ -997,18 +997,18 @@ DocIterator Cursor::selectionEnd() const
void Cursor::setSelection() void Cursor::setSelection()
{ {
setSelection(true); selection(true);
if (idx() == normalAnchor().idx() && if (idx() == normalAnchor().idx() &&
pit() == normalAnchor().pit() && pit() == normalAnchor().pit() &&
pos() == normalAnchor().pos()) pos() == normalAnchor().pos())
setSelection(false); selection(false);
} }
void Cursor::setSelection(DocIterator const & where, int n) void Cursor::setSelection(DocIterator const & where, int n)
{ {
setCursor(where); setCursor(where);
setSelection(true); selection(true);
anchor_ = where; anchor_ = where;
pos() += n; pos() += n;
} }
@ -1016,7 +1016,7 @@ void Cursor::setSelection(DocIterator const & where, int n)
void Cursor::clearSelection() void Cursor::clearSelection()
{ {
setSelection(false); selection(false);
setWordSelection(false); setWordSelection(false);
setMark(false); setMark(false);
resetAnchor(); resetAnchor();
@ -1079,7 +1079,7 @@ bool Cursor::selHandle(bool sel)
cap::saveSelection(*this); cap::saveSelection(*this);
resetAnchor(); resetAnchor();
setSelection(sel); selection(sel);
return true; return true;
} }
} // namespace lyx } // namespace lyx
@ -1319,7 +1319,7 @@ bool Cursor::backspace()
// let's require two backspaces for 'big stuff' and // let's require two backspaces for 'big stuff' and
// highlight on the first // highlight on the first
resetAnchor(); resetAnchor();
setSelection(true); selection(true);
--pos(); --pos();
} else { } else {
--pos(); --pos();
@ -1366,7 +1366,7 @@ bool Cursor::erase()
// 'clever' UI hack: only erase large items if previously slected // 'clever' UI hack: only erase large items if previously slected
if (pos() != lastpos() && nextAtom()->nargs() > 0) { if (pos() != lastpos() && nextAtom()->nargs() > 0) {
resetAnchor(); resetAnchor();
setSelection(true); selection(true);
++pos(); ++pos();
} else { } else {
plainErase(); plainErase();

View File

@ -161,8 +161,8 @@ public:
// //
/// selection active? /// selection active?
bool selection() const { return selection_; } bool selection() const { return selection_; }
/// set selection; /// set selection; this is lower level than (set|clear)Selection
void setSelection(bool sel) { selection_ = sel; } void selection(bool sel) { selection_ = sel; }
/// do we have a multicell selection? /// do we have a multicell selection?
bool selIsMultiCell() const bool selIsMultiCell() const
{ return selection_ && selBegin().idx() != selEnd().idx(); } { return selection_ && selBegin().idx() != selEnd().idx(); }

View File

@ -1325,7 +1325,7 @@ void selClearOrDel(Cursor & cur)
if (lyxrc.auto_region_delete) if (lyxrc.auto_region_delete)
selDel(cur); selDel(cur);
else else
cur.setSelection(false); cur.selection(false);
} }

View File

@ -1455,7 +1455,7 @@ void Text::deleteWordForward(Cursor & cur)
cursorForward(cur); cursorForward(cur);
else { else {
cur.resetAnchor(); cur.resetAnchor();
cur.setSelection(true); cur.selection(true);
cursorForwardOneWord(cur); cursorForwardOneWord(cur);
cur.setSelection(); cur.setSelection();
cutSelection(cur, true, false); cutSelection(cur, true, false);
@ -1471,7 +1471,7 @@ void Text::deleteWordBackward(Cursor & cur)
cursorBackward(cur); cursorBackward(cur);
else { else {
cur.resetAnchor(); cur.resetAnchor();
cur.setSelection(true); cur.selection(true);
cursorBackwardOneWord(cur); cursorBackwardOneWord(cur);
cur.setSelection(); cur.setSelection();
cutSelection(cur, true, false); cutSelection(cur, true, false);

View File

@ -178,7 +178,7 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd)
LASSERT(cur.inMathed(), return); LASSERT(cur.inMathed(), return);
cur.pos() = 0; cur.pos() = 0;
cur.resetAnchor(); cur.resetAnchor();
cur.setSelection(true); cur.selection(true);
cur.pos() = cur.lastpos(); cur.pos() = cur.lastpos();
if (cmd.action() != LFUN_MATH_MODE) if (cmd.action() != LFUN_MATH_MODE)
// LFUN_MATH_MODE has a different meaning in math mode // LFUN_MATH_MODE has a different meaning in math mode
@ -1678,7 +1678,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
// We continue with our existing selection or start a new one, so don't // We continue with our existing selection or start a new one, so don't
// reset the anchor. // reset the anchor.
bvcur.setCursor(cur); bvcur.setCursor(cur);
bvcur.setSelection(true); bvcur.selection(true);
if (cur.top() == old) { if (cur.top() == old) {
// We didn't move one iota, so no need to update the screen. // We didn't move one iota, so no need to update the screen.
cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor); cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
@ -2060,7 +2060,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cur.push(*inset); cur.push(*inset);
cur.top().pos() = cur.top().lastpos(); cur.top().pos() = cur.top().lastpos();
cur.resetAnchor(); cur.resetAnchor();
cur.setSelection(true); cur.selection(true);
cur.top().pos() = 0; cur.top().pos() = 0;
} }
break; break;
@ -2436,7 +2436,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_ESCAPE: case LFUN_ESCAPE:
if (cur.selection()) { if (cur.selection()) {
cur.setSelection(false); cur.selection(false);
} else { } else {
cur.undispatched(); cur.undispatched();
// This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more

View File

@ -1622,7 +1622,7 @@ void TextMetrics::deleteLineForward(Cursor & cur)
text_->cursorForward(cur); text_->cursorForward(cur);
} else { } else {
cur.resetAnchor(); cur.resetAnchor();
cur.setSelection(true); // to avoid deletion cur.selection(true); // to avoid deletion
cursorEnd(cur); cursorEnd(cur);
cur.setSelection(); cur.setSelection();
// What is this test for ??? (JMarc) // What is this test for ??? (JMarc)

View File

@ -337,9 +337,9 @@ void SpellcheckerWidget::Private::setSelection(
Cursor & bvcur = bv->cursor(); Cursor & bvcur = bv->cursor();
bvcur.setCursor(from); bvcur.setCursor(from);
bvcur.clearSelection(); bvcur.clearSelection();
bvcur.setSelection(true); bvcur.selection(true);
bvcur.setCursor(end); bvcur.setCursor(end);
bvcur.setSelection(true); bvcur.selection(true);
} else { } else {
// FIXME LFUN // FIXME LFUN
// If we used a LFUN, dispatch would do all of this for us // If we used a LFUN, dispatch would do all of this for us

View File

@ -3997,7 +3997,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.idx() = tabular.getLastCellInRow(r); cur.idx() = tabular.getLastCellInRow(r);
cur.pit() = cur.lastpit(); cur.pit() = cur.lastpit();
cur.pos() = cur.lastpos(); cur.pos() = cur.lastpos();
cur.setSelection(true); cur.selection(true);
bvcur = cur; bvcur = cur;
rowselect_ = true; rowselect_ = true;
break; break;
@ -4012,7 +4012,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.idx() = tabular.cellIndex(tabular.nrows() - 1, c); cur.idx() = tabular.cellIndex(tabular.nrows() - 1, c);
cur.pit() = cur.lastpit(); cur.pit() = cur.lastpit();
cur.pos() = cur.lastpos(); cur.pos() = cur.lastpos();
cur.setSelection(true); cur.selection(true);
bvcur = cur; bvcur = cur;
colselect_ = true; colselect_ = true;
break; break;
@ -4045,7 +4045,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.pit() = 0; cur.pit() = 0;
cur.pos() = 0; cur.pos() = 0;
bvcur.setCursor(cur); bvcur.setCursor(cur);
bvcur.setSelection(true); bvcur.selection(true);
break; break;
} }
// select (additional) column // select (additional) column
@ -4057,7 +4057,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.pit() = 0; cur.pit() = 0;
cur.pos() = 0; cur.pos() = 0;
bvcur.setCursor(cur); bvcur.setCursor(cur);
bvcur.setSelection(true); bvcur.selection(true);
break; break;
} }
// only update if selection changes // only update if selection changes
@ -4066,7 +4066,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.noScreenUpdate(); cur.noScreenUpdate();
setCursorFromCoordinates(cur, cmd.x(), cmd.y()); setCursorFromCoordinates(cur, cmd.x(), cmd.y());
bvcur.setCursor(cur); bvcur.setCursor(cur);
bvcur.setSelection(true); bvcur.selection(true);
// if this is a multicell selection, we just set the cursor to // if this is a multicell selection, we just set the cursor to
// the beginning of the cell's text. // the beginning of the cell's text.
if (bvcur.selIsMultiCell()) { if (bvcur.selIsMultiCell()) {
@ -4083,12 +4083,12 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_CELL_BACKWARD: case LFUN_CELL_BACKWARD:
movePrevCell(cur); movePrevCell(cur);
cur.setSelection(false); cur.selection(false);
break; break;
case LFUN_CELL_FORWARD: case LFUN_CELL_FORWARD:
moveNextCell(cur); moveNextCell(cur);
cur.setSelection(false); cur.selection(false);
break; break;
case LFUN_CHAR_FORWARD_SELECT: case LFUN_CHAR_FORWARD_SELECT:
@ -5186,7 +5186,7 @@ int InsetTabular::dist(BufferView & bv, idx_type const cell, int x, int y) const
Inset * InsetTabular::editXY(Cursor & cur, int x, int y) Inset * InsetTabular::editXY(Cursor & cur, int x, int y)
{ {
//lyxerr << "InsetTabular::editXY: " << this << endl; //lyxerr << "InsetTabular::editXY: " << this << endl;
cur.setSelection(false); cur.selection(false);
cur.push(*this); cur.push(*this);
cur.idx() = getNearestCell(cur.bv(), x, y); cur.idx() = getNearestCell(cur.bv(), x, y);
return cur.bv().textMetrics(&cell(cur.idx())->text()).editXY(cur, x, y); return cur.bv().textMetrics(&cell(cur.idx())->text()).editXY(cur, x, y);
@ -5545,7 +5545,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.cellIndex(sel_row_start, column); cur.idx() = tabular.cellIndex(sel_row_start, column);
cur.pit() = 0; cur.pit() = 0;
cur.pos() = 0; cur.pos() = 0;
cur.setSelection(false); cur.selection(false);
break; break;
case Tabular::DELETE_COLUMN: case Tabular::DELETE_COLUMN:
@ -5568,7 +5568,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.cellIndex(row, sel_col_start); cur.idx() = tabular.cellIndex(row, sel_col_start);
cur.pit() = 0; cur.pit() = 0;
cur.pos() = 0; cur.pos() = 0;
cur.setSelection(false); cur.selection(false);
break; break;
case Tabular::COPY_ROW: case Tabular::COPY_ROW:
@ -5684,7 +5684,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
tabular.rightLine(cur.selEnd().idx())); tabular.rightLine(cur.selEnd().idx()));
cur.pit() = 0; cur.pit() = 0;
cur.pos() = 0; cur.pos() = 0;
cur.setSelection(false); cur.selection(false);
break; break;
} }
@ -5741,7 +5741,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
tabular.getAlignment(cur.selEnd().idx())); tabular.getAlignment(cur.selEnd().idx()));
cur.pit() = 0; cur.pit() = 0;
cur.pos() = 0; cur.pos() = 0;
cur.setSelection(false); cur.selection(false);
break; break;
} }
@ -5946,7 +5946,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.setLTCaption(row, true); cur.idx() = tabular.setLTCaption(row, true);
cur.pit() = 0; cur.pit() = 0;
cur.pos() = 0; cur.pos() = 0;
cur.setSelection(false); cur.selection(false);
// If a row is set as caption, then also insert // If a row is set as caption, then also insert
// a caption. Otherwise the LaTeX output is broken. // a caption. Otherwise the LaTeX output is broken.
// Select cell if it is non-empty // Select cell if it is non-empty
@ -5962,7 +5962,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.setLTCaption(row, false); cur.idx() = tabular.setLTCaption(row, false);
cur.pit() = 0; cur.pit() = 0;
cur.pos() = 0; cur.pos() = 0;
cur.setSelection(false); cur.selection(false);
FuncRequest fr(LFUN_INSET_DISSOLVE, "caption"); FuncRequest fr(LFUN_INSET_DISSOLVE, "caption");
if (lyx::getStatus(fr).enabled()) if (lyx::getStatus(fr).enabled())
lyx::dispatch(fr); lyx::dispatch(fr);

View File

@ -1416,7 +1416,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_CELL_BACKWARD: case LFUN_CELL_BACKWARD:
// See below. // See below.
cur.setSelection(false); cur.selection(false);
if (!idxPrev(cur)) { if (!idxPrev(cur)) {
cmd = FuncRequest(LFUN_FINISHED_BACKWARD); cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
cur.undispatched(); cur.undispatched();
@ -1426,7 +1426,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_CELL_FORWARD: case LFUN_CELL_FORWARD:
// Can't handle selection by additional 'shift' as this is // Can't handle selection by additional 'shift' as this is
// hard bound to LFUN_CELL_BACKWARD // hard bound to LFUN_CELL_BACKWARD
cur.setSelection(false); cur.selection(false);
if (!idxNext(cur)) { if (!idxNext(cur)) {
cmd = FuncRequest(LFUN_FINISHED_FORWARD); cmd = FuncRequest(LFUN_FINISHED_FORWARD);
cur.undispatched(); cur.undispatched();

View File

@ -740,7 +740,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_WORD_SELECT: case LFUN_WORD_SELECT:
cur.pos() = 0; cur.pos() = 0;
cur.resetAnchor(); cur.resetAnchor();
cur.setSelection(true); cur.selection(true);
cur.pos() = cur.lastpos(); cur.pos() = cur.lastpos();
cur.bv().cursor() = cur; cur.bv().cursor() = cur;
break; break;
@ -749,7 +749,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.idx() = 0; cur.idx() = 0;
cur.pos() = 0; cur.pos() = 0;
cur.resetAnchor(); cur.resetAnchor();
cur.setSelection(true); cur.selection(true);
cur.idx() = cur.lastidx(); cur.idx() = cur.lastidx();
cur.pos() = cur.lastpos(); cur.pos() = cur.lastpos();
cur.bv().cursor() = cur; cur.bv().cursor() = cur;
@ -1621,7 +1621,7 @@ void InsetMathNest::lfunMouseRelease(Cursor & cur, FuncRequest & cmd)
cur.noScreenUpdate(); cur.noScreenUpdate();
else { else {
Cursor & bvcur = cur.bv().cursor(); Cursor & bvcur = cur.bv().cursor();
bvcur.setSelection(true); bvcur.selection(true);
} }
return; return;
} }
@ -1762,7 +1762,7 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
// just clear selection on pressing the space bar // just clear selection on pressing the space bar
if (cur.selection() && c == ' ') { if (cur.selection() && c == ' ') {
cur.setSelection(false); cur.selection(false);
return true; return true;
} }