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)

C-a is now bound to inset-select-all

C-M-a is bound to the global "select all". The
reason for this change is that selecting an inset
is a more common operation that selecting an entire
document.

This patch is the result of discussion on #7727.
This commit is contained in:
Jean-Marc Lasgouttes 2014-10-19 20:43:17 +02:00
parent e0840f28b7
commit 1997e8b817
12 changed files with 84 additions and 31 deletions

View File

@ -175,6 +175,11 @@ The following LyX functions have been changed:
The following LyX key bindings have been changed: The following LyX key bindings have been changed:
- In LyX 2.1.3, the binding "C-a" was moved from selecting the whole
document to "inset-select-all". This function allows to select the
document in a incremental way. The old behavior is now bound to
"C-M-a".
- The binding "C-w" was moved from "buffer-close" to "view-close" - The binding "C-w" was moved from "buffer-close" to "view-close"
(only in cua.bind). (only in cua.bind).

View File

@ -87,8 +87,8 @@ Format 2
\bind "C-y" "redo" \bind "C-y" "redo"
\bind "C-S-Z" "redo" \bind "C-S-Z" "redo"
\bind "C-a" "command-sequence buffer-begin ; buffer-end-select" # select all \bind "C-M-a" "command-sequence buffer-begin ; buffer-end-select" # select all
\bind "C-M-a" "inset-select-all" \bind "C-a" "inset-select-all"
\bind "C-S-E" "changes-track" # it's what MS Word uses \bind "C-S-E" "changes-track" # it's what MS Word uses
\bind "~S-M-quotedbl" "quote-insert single" \bind "~S-M-quotedbl" "quote-insert single"

View File

@ -123,8 +123,8 @@ Format 2
# +: "Shift-Command-4" # Capture a selection to a file # +: "Shift-Command-4" # Capture a selection to a file
# +: "Shift-Control-Command-4" # Capture a selection to the Clipboard # +: "Shift-Control-Command-4" # Capture a selection to the Clipboard
# +: "Command-A" # Highlight every item in a document or window, or all characters in a text field # +: "Command-A" # Highlight every item in a document or window, or all characters in a text field
\bind "C-a" "command-sequence buffer-begin ; buffer-end-select" \bind "C-M-a" "command-sequence buffer-begin ; buffer-end-select"
\bind "C-M-a" "inset-select-all" \bind "C-a" "inset-select-all"
# +: "Command-B" # Boldface the selected text or toggle boldfaced text on and off # +: "Command-B" # Boldface the selected text or toggle boldfaced text on and off
\bind "C-M-b" "font-boldsymbol" \bind "C-M-b" "font-boldsymbol"
\bind "C-b" "font-bold" \bind "C-b" "font-bold"

View File

@ -113,7 +113,8 @@ Format 2
\bind "C-x" "cut" \bind "C-x" "cut"
\bind "C-z" "undo" \bind "C-z" "undo"
\bind "S-C-Z" "redo" \bind "S-C-Z" "redo"
\bind "C-a" "command-sequence buffer-begin ; buffer-end-select" # select all \bind "C-a" "inset-select-all"
\bind "C-M-a" "command-sequence buffer-begin ; buffer-end-select" # select all
# This combination makes an umlaut accent now. # This combination makes an umlaut accent now.

View File

@ -98,7 +98,7 @@ The LyX Team
\end_layout \end_layout
\begin_layout Date \begin_layout Date
2014-02-13 2014-11-20
\end_layout \end_layout
\begin_layout Section* \begin_layout Section*
@ -2171,13 +2171,16 @@ Sample inset-modify note Note Comment
inset-select-all inset-select-all
\end_layout \end_layout
\begin_layout Description \begin_layout Description
Action Selects all contents of an inset. Action Select all contents of an inset.
\end_layout
\begin_layout Description
Notion There are 3 successive levels: select current cell, select all cells of inset, select the inset from outside (in the enclosing inset).
\end_layout \end_layout
\begin_layout Description \begin_layout Description
Syntax inset-select-all Syntax inset-select-all
\end_layout \end_layout
\begin_layout Description \begin_layout Description
Origin vfr, 22 Aug 2009 Origin vfr, 22 Aug 2009; lasgouttes 1 Nov 2014
\end_layout \end_layout
\begin_layout Subsection* \begin_layout Subsection*
@ -3047,7 +3050,7 @@ Origin Abdel, Dec 27 2007
section-select section-select
\end_layout \end_layout
\begin_layout Description \begin_layout Description
Action Selects the whole section. Action Select the whole section.
\end_layout \end_layout
\begin_layout Description \begin_layout Description
Notion The cursor should be in a section heading before calling this lfun. Notion The cursor should be in a section heading before calling this lfun.

View File

@ -1089,6 +1089,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
case LFUN_KEYMAP_PRIMARY: case LFUN_KEYMAP_PRIMARY:
case LFUN_KEYMAP_SECONDARY: case LFUN_KEYMAP_SECONDARY:
case LFUN_KEYMAP_TOGGLE: case LFUN_KEYMAP_TOGGLE:
case LFUN_INSET_SELECT_ALL:
flag.setEnabled(true); flag.setEnabled(true);
break; break;
@ -1800,6 +1801,41 @@ 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.depth() > 1
&& cur.selBegin().at_cell_begin()
&& cur.selEnd().at_cell_end())) {
// At least one complete cell is selected.
// Select all cells
cur.idx() = 0;
cur.pos() = 0;
cur.resetAnchor();
cur.setSelection(true);
cur.idx() = cur.lastidx();
cur.pos() = cur.lastpos();
} else {
// select current cell
cur.pit() = 0;
cur.pos() = 0;
cur.resetAnchor();
cur.setSelection(true);
cur.pit() = cur.lastpit();
cur.pos() = cur.lastpos();
}
dr.screenUpdate(Update::Force);
break;
// This would be in Buffer class if only Cursor did not // This would be in Buffer class if only Cursor did not
// require a bufferview // require a bufferview
case LFUN_INSET_FORALL: { case LFUN_INSET_FORALL: {

View File

@ -158,15 +158,27 @@ void CursorSlice::backwardPos()
} }
bool CursorSlice::at_cell_end() const
{
return pit_ == lastpit() && pos_ == lastpos();
}
bool CursorSlice::at_cell_begin() const
{
return pit_ == 0 && pos_ == 0;
}
bool CursorSlice::at_end() const bool CursorSlice::at_end() const
{ {
return idx_ == lastidx() && pit_ == lastpit() && pos_ == lastpos(); return idx_ == lastidx() && at_cell_end();
} }
bool CursorSlice::at_begin() const 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(); void forwardIdx();
/// move to previous cell /// move to previous cell
void backwardIdx(); 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 /// are we at the end of this slice
bool at_end() const; bool at_end() const;
/// are we at the start of this slice /// are we at the start of this slice

View File

@ -1141,16 +1141,19 @@ void LyXAction::init()
/*! /*!
* \var lyx::FuncCode lyx::LFUN_INSET_SELECT_ALL * \var lyx::FuncCode lyx::LFUN_INSET_SELECT_ALL
* \li Action: Selects all contents of an inset. * \li Action: Select all contents of an inset.
* \li Notion: There are 3 successive levels: select current cell,
* select all cells of inset, select the inset from outside
* (in the enclosing inset).
* \li Syntax: inset-select-all * \li Syntax: inset-select-all
* \li Origin: vfr, 22 Aug 2009 * \li Origin: vfr, 22 Aug 2009; lasgouttes 1 Nov 2014
* \endvar * \endvar
*/ */
{ LFUN_INSET_SELECT_ALL, "inset-select-all", ReadOnly, Edit }, { LFUN_INSET_SELECT_ALL, "inset-select-all", ReadOnly, Edit },
/*! /*!
* \var lyx::FuncCode lyx::LFUN_SECTION_SELECT * \var lyx::FuncCode lyx::LFUN_SECTION_SELECT
* \li Action: Selects the whole section. * \li Action: Select the whole section.
* \li Notion: The cursor should be in a section heading * \li Notion: The cursor should be in a section heading
before calling this lfun. before calling this lfun.
* \li Syntax: section-select * \li Syntax: section-select

View File

@ -616,18 +616,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cur.screenUpdateFlags(Update::FitCursor); cur.screenUpdateFlags(Update::FitCursor);
break; 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:
case LFUN_CHAR_FORWARD_SELECT: case LFUN_CHAR_FORWARD_SELECT:
//LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur); //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
@ -3058,7 +3046,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_INSET_END: case LFUN_INSET_END:
case LFUN_INSET_BEGIN_SELECT: case LFUN_INSET_BEGIN_SELECT:
case LFUN_INSET_END_SELECT: case LFUN_INSET_END_SELECT:
case LFUN_INSET_SELECT_ALL:
case LFUN_PARAGRAPH_UP: case LFUN_PARAGRAPH_UP:
case LFUN_PARAGRAPH_DOWN: case LFUN_PARAGRAPH_DOWN:
case LFUN_LINE_BEGIN: case LFUN_LINE_BEGIN:

View File

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

View File

@ -58,14 +58,17 @@ What's new
* USER INTERFACE * USER INTERFACE
- Debug options in message pane are now sorted alphabetically.
- References no longer truncated in outliner (bug 9312). - References no longer truncated in outliner (bug 9312).
- Allow computing selected subformulas with computer algebra systems. - Allow computing selected subformulas with computer algebra systems.
- Number correctly footnotes in title layouts (part of bug 2666). - Number correctly footnotes in title layouts (part of bug 2666).
- Ctrl+A is now bound to inset-select-all, which does a local
selection (current inset) and grows at each new invokation. Try it!
- Debug options in message pane are now sorted alphabetically.
* DOCUMENTATION AND LOCALIZATION * DOCUMENTATION AND LOCALIZATION
- New example file "PDF-comment.lyx" describing the support for PDF annotations. - New example file "PDF-comment.lyx" describing the support for PDF annotations.