From 1997e8b817c0a65aa82f97ef7cc887c7bb11caa1 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Sun, 19 Oct 2014 20:43:17 +0200 Subject: [PATCH] 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. --- RELEASE-NOTES | 5 +++++ lib/bind/cua.bind | 4 ++-- lib/bind/mac.bind | 4 ++-- lib/bind/sciword.bind | 3 ++- lib/doc/LFUNs.lyx | 11 +++++++---- src/BufferView.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/CursorSlice.cpp | 18 +++++++++++++++--- src/CursorSlice.h | 4 ++++ src/LyXAction.cpp | 9 ++++++--- src/Text3.cpp | 13 ------------- src/mathed/InsetMathNest.cpp | 1 - status.21x | 7 +++++-- 12 files changed, 84 insertions(+), 31 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f680014257..d9212d4900 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -175,6 +175,11 @@ The following LyX functions 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" (only in cua.bind). diff --git a/lib/bind/cua.bind b/lib/bind/cua.bind index 58e18f282e..359e1d486d 100644 --- a/lib/bind/cua.bind +++ b/lib/bind/cua.bind @@ -87,8 +87,8 @@ Format 2 \bind "C-y" "redo" \bind "C-S-Z" "redo" -\bind "C-a" "command-sequence buffer-begin ; buffer-end-select" # select all -\bind "C-M-a" "inset-select-all" +\bind "C-M-a" "command-sequence buffer-begin ; buffer-end-select" # select all +\bind "C-a" "inset-select-all" \bind "C-S-E" "changes-track" # it's what MS Word uses \bind "~S-M-quotedbl" "quote-insert single" diff --git a/lib/bind/mac.bind b/lib/bind/mac.bind index efee7b2e90..ecdd3ad06b 100644 --- a/lib/bind/mac.bind +++ b/lib/bind/mac.bind @@ -123,8 +123,8 @@ Format 2 # +: "Shift-Command-4" # Capture a selection to a file # +: "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 -\bind "C-a" "command-sequence buffer-begin ; buffer-end-select" -\bind "C-M-a" "inset-select-all" +\bind "C-M-a" "command-sequence buffer-begin ; buffer-end-select" +\bind "C-a" "inset-select-all" # +: "Command-B" # Boldface the selected text or toggle boldfaced text on and off \bind "C-M-b" "font-boldsymbol" \bind "C-b" "font-bold" diff --git a/lib/bind/sciword.bind b/lib/bind/sciword.bind index 533d6b128d..b3814f4c55 100644 --- a/lib/bind/sciword.bind +++ b/lib/bind/sciword.bind @@ -113,7 +113,8 @@ Format 2 \bind "C-x" "cut" \bind "C-z" "undo" \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. diff --git a/lib/doc/LFUNs.lyx b/lib/doc/LFUNs.lyx index b0ac9f469f..a5c57a3599 100644 --- a/lib/doc/LFUNs.lyx +++ b/lib/doc/LFUNs.lyx @@ -98,7 +98,7 @@ The LyX Team \end_layout \begin_layout Date -2014-02-13 +2014-11-20 \end_layout \begin_layout Section* @@ -2171,13 +2171,16 @@ Sample inset-modify note Note Comment inset-select-all \end_layout \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 \begin_layout Description Syntax inset-select-all \end_layout \begin_layout Description -Origin vfr, 22 Aug 2009 +Origin vfr, 22 Aug 2009; lasgouttes 1 Nov 2014 \end_layout \begin_layout Subsection* @@ -3047,7 +3050,7 @@ Origin Abdel, Dec 27 2007 section-select \end_layout \begin_layout Description -Action Selects the whole section. +Action Select the whole section. \end_layout \begin_layout Description Notion The cursor should be in a section heading before calling this lfun. diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 324c65dff4..2bd7f7270b 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1089,6 +1089,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,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 // require a bufferview case LFUN_INSET_FORALL: { diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp index 0e46c0781f..e7ef90e8f3 100644 --- a/src/CursorSlice.cpp +++ b/src/CursorSlice.cpp @@ -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(); } diff --git a/src/CursorSlice.h b/src/CursorSlice.h index 01634bdacc..d703cb4b34 100644 --- a/src/CursorSlice.h +++ b/src/CursorSlice.h @@ -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 diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 5b355243ba..151f955f98 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -1141,16 +1141,19 @@ void LyXAction::init() /*! * \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 Origin: vfr, 22 Aug 2009 + * \li Origin: vfr, 22 Aug 2009; lasgouttes 1 Nov 2014 * \endvar */ { LFUN_INSET_SELECT_ALL, "inset-select-all", ReadOnly, Edit }, /*! * \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 before calling this lfun. * \li Syntax: section-select diff --git a/src/Text3.cpp b/src/Text3.cpp index 5231391411..508a604ad0 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -616,18 +616,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); @@ -3058,7 +3046,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: diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 2e32bbb0ac..32e68485b6 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -729,7 +729,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(); diff --git a/status.21x b/status.21x index 7f199e4251..05002a076d 100644 --- a/status.21x +++ b/status.21x @@ -58,14 +58,17 @@ What's new * USER INTERFACE -- Debug options in message pane are now sorted alphabetically. - - References no longer truncated in outliner (bug 9312). - Allow computing selected subformulas with computer algebra systems. - 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 - New example file "PDF-comment.lyx" describing the support for PDF annotations. -- 2.39.5