]> git.lyx.org Git - features.git/commitdiff
Reimplement inset-select-all in a generic way
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 19 Oct 2014 18:43:17 +0000 (20:43 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 6 Jan 2015 10:05:49 +0000 (11:05 +0100)
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.

12 files changed:
RELEASE-NOTES
lib/bind/cua.bind
lib/bind/mac.bind
lib/bind/sciword.bind
lib/doc/LFUNs.lyx
src/BufferView.cpp
src/CursorSlice.cpp
src/CursorSlice.h
src/LyXAction.cpp
src/Text3.cpp
src/mathed/InsetMathNest.cpp
status.21x

index f680014257abe69eeea76304eda51afef3d41296..d9212d49007f5c1df0fa759959b2ac5c8873a4f8 100644 (file)
@@ -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).
 
index 58e18f282ea65d5db88c09f2acc03e5786176ad7..359e1d486d4436d92cc27706aa333ab3171acefc 100644 (file)
@@ -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"
index efee7b2e9002d1bed89144d17a86ba3ff55ca900..ecdd3ad06bbf516716f4a2ab6a08eb204b2c4f83 100644 (file)
@@ -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"
index 533d6b128d4c81f8b94f4fa05b1c1b864427cca4..b3814f4c55a393287ba59de0fd1e5aea801f71f4 100644 (file)
@@ -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.
index b0ac9f469f38f64ebe277e9eeaac2283add09253..a5c57a359929547a9e63582f3a2f5e427ba5178b 100644 (file)
@@ -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.
index 324c65dff4393e841ef64740dbf2fc6f550839d3..2bd7f7270b3ed41f81fc8354ebbbef3cff25e572 100644 (file)
@@ -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: {
index 0e46c0781fc760ac8e8783fcd099011db555151f..e7ef90e8f37c3040e32aead6e0e595344f7a1d84 100644 (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();
 }
 
 
index 01634bdacca3a1dabc2d507dbb614a9b2df9e40e..d703cb4b3479ac3198c26ea3ed2df0dfaeb82f32 100644 (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
index 5b355243ba5562684f59d3532ec4b1de5308d6b7..151f955f98b610b3eb52971ca3921e52ed6b9f68 100644 (file)
@@ -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
index 523139141167b9c99aa82388f0d2e37199d01390..508a604ad097828e6836c044cfc0e555d3709540 100644 (file)
@@ -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:
index 2e32bbb0ac3328a9ddbdb2b7577ae0d60f8aca24..32e68485b624355217cce31684f9717e3c08ae72 100644 (file)
@@ -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();
index 7f199e4251296ecad34ce58994551916817e8a41..05002a076d759f984bf88e6ddd0171930f5cb93d 100644 (file)
@@ -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.