Reimplement inset-select-all in a generic way

There are 3 possible actions (in order)
* select current cell
* select all calls of inset
* select the inset from outside (in the containing inset)

This fixes completely #7727.
This commit is contained in:
Jean-Marc Lasgouttes 2014-10-19 20:43:17 +02:00
parent c559f85ccb
commit e52a385493
5 changed files with 52 additions and 17 deletions

View File

@ -1087,6 +1087,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
case LFUN_KEYMAP_PRIMARY:
case LFUN_KEYMAP_SECONDARY:
case LFUN_KEYMAP_TOGGLE:
case LFUN_INSET_SELECT_ALL:
flag.setEnabled(true);
break;
@ -1800,6 +1801,38 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
}
case LFUN_INSET_SELECT_ALL:
if (cur.depth() > 1
&& cur.selBegin().at_begin()
&& cur.selEnd().at_end()) {
// All the contents of the inset if selected.
// Select the inset from outside.
cur.pop();
cur.resetAnchor();
cur.setSelection(true);
cur.posForward();
} else if (cur.selBegin().idx() != cur.selEnd().idx()
|| (cur.selBegin().at_cell_begin()
&& cur.selEnd().at_cell_end())) {
// At least one complete cell is selected.
// Select all cells
cur.pos() = 0;
cur.idx() = 0;
cur.resetAnchor();
cur.setSelection(true);
cur.idx() = cur.lastidx();
cur.pos() = cur.lastpos();
} else {
// select current cell
cur.pos() = 0;
cur.resetAnchor();
cur.setSelection(true);
cur.pos() = cur.lastpos();
}
dr.screenUpdate(Update::Force);
break;
// This would be in Buffer class if only Cursor did not
// require a bufferview
case LFUN_INSET_FORALL: {

View File

@ -158,15 +158,27 @@ void CursorSlice::backwardPos()
}
bool CursorSlice::at_end() const
bool CursorSlice::at_cell_end() const
{
return idx_ == lastidx() && pit_ == lastpit() && pos_ == lastpos();
return pit_ == lastpit() && pos_ == lastpos();
}
bool CursorSlice::at_cell_begin() const
{
return pit_ == 0 && pos_ == 0;
}
bool CursorSlice::at_end() const
{
return idx_ == lastidx() && at_cell_end();
}
bool CursorSlice::at_begin() const
{
return idx_ == 0 && pit_ == 0 && pos_ == 0;
return idx_ == 0 && at_cell_begin();
}

View File

@ -132,6 +132,10 @@ public:
void forwardIdx();
/// move to previous cell
void backwardIdx();
/// are we at the end of the cell
bool at_cell_end() const;
/// are we at the start of the cell
bool at_cell_begin() const;
/// are we at the end of this slice
bool at_end() const;
/// are we at the start of this slice

View File

@ -599,18 +599,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cur.screenUpdateFlags(Update::FitCursor);
break;
case LFUN_INSET_SELECT_ALL:
if (cur.depth() == 1 || !cur.selection() || !cur.selBegin().at_begin()
|| !cur.selEnd().at_end()) {
needsUpdate |= cur.selHandle(false);
needsUpdate |= cursorTop(cur);
needsUpdate |= cur.selHandle(true);
needsUpdate |= cursorBottom(cur);
} else
cur.undispatched();
cur.screenUpdateFlags(Update::FitCursor);
break;
case LFUN_CHAR_FORWARD:
case LFUN_CHAR_FORWARD_SELECT:
//LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
@ -3118,7 +3106,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_INSET_END:
case LFUN_INSET_BEGIN_SELECT:
case LFUN_INSET_END_SELECT:
case LFUN_INSET_SELECT_ALL:
case LFUN_PARAGRAPH_UP:
case LFUN_PARAGRAPH_DOWN:
case LFUN_LINE_BEGIN:

View File

@ -731,7 +731,6 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_MOUSE_DOUBLE:
case LFUN_MOUSE_TRIPLE:
case LFUN_WORD_SELECT:
case LFUN_INSET_SELECT_ALL:
cur.pos() = 0;
cur.idx() = 0;
cur.resetAnchor();