]> git.lyx.org Git - features.git/commitdiff
Make inset-select-all select all cells only in tables
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 14 Mar 2016 10:46:28 +0000 (11:46 +0100)
committerRichard Heck <rgheck@lyx.org>
Sat, 28 May 2016 21:43:01 +0000 (17:43 -0400)
inset-select-all has 3 levels
1. select current cell
2. select all cells
3. select inset from outside.

The second level makes sense for tables (text and math), but not for things like a math fraction.

Introduce a new method Inset::isTable() that allows to detect this case properly and skip level 2.

src/BufferView.cpp
src/insets/Inset.h
src/insets/InsetTabular.h
src/mathed/InsetMathGrid.h

index 56ecd94e29694099a67855963092d3db506cbf6a..414dbf216da329fe483473445328ecbfee065836 100644 (file)
@@ -1777,21 +1777,25 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        }
 
 
-       case LFUN_INSET_SELECT_ALL:
-               if (cur.depth() > 1
+       case LFUN_INSET_SELECT_ALL: {
+               // true if all cells are selected
+               bool const all_selected = cur.depth() > 1
                    && cur.selBegin().at_begin()
-                   && cur.selEnd().at_end()) {
-                       // All the contents of the inset if selected.
+                   && cur.selEnd().at_end();
+               // true if some cells are selected
+               bool const cells_selected = cur.depth() > 1
+                   && cur.selBegin().at_cell_begin()
+                       && cur.selEnd().at_cell_end();
+               if (all_selected || (cells_selected && !cur.inset().isTable())) {
+                       // All the contents of the inset if selected, or only at
+                       // least one cell but inset is not a table.
                        // 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.
+               } else if (cells_selected) {
+                       // At least one complete cell is selected and inset is a table.
                        // Select all cells
                        cur.idx() = 0;
                        cur.pos() = 0;
@@ -1811,6 +1815,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                cur.setCurrentFont();
                dr.screenUpdate(Update::Force);
                break;
+       }
 
 
        // This would be in Buffer class if only Cursor did not
index c413f9b4cc2cd47934635ca2b5c56e12b2a003c9..cbcaf518a2fca8838e40136e097e61dfbbcf6e7e 100644 (file)
@@ -347,6 +347,8 @@ public:
        virtual bool clickable(BufferView const &, int, int) const { return false; }
        /// Move one cell backwards
        virtual bool allowsCaptionVariation(std::string const &) const { return false; }
+       // true for insets that have a table structure (InsetMathGrid, InsetTabular)
+       virtual bool isTable() const { return false; }
 
        /// does this contain text that can be change track marked in DVI?
        virtual bool canTrackChanges() const { return false; }
index 6b60e44acb7c2866dd2720df3602e5fee1fd1376..5b5f836cbc46d140a229563d70ab09a32c6b186b 100644 (file)
@@ -881,6 +881,8 @@ public:
        bool inheritFont() const { return false; }
        ///
        bool allowsCaptionVariation(std::string const &) const;
+       //
+       bool isTable() const { return true; }
        ///
        DisplayType display() const;
        ///
index 7faf938818cb8227a02428b970c57e3c8d7f17db..e9ea396930f3aa466536dd1135f3062393764ca4 100644 (file)
@@ -154,6 +154,8 @@ public:
        InsetMathGrid * asGridInset() { return this; }
        /// identifies GridInset
        InsetMathGrid const * asGridInset() const { return this; }
+       //
+       bool isTable() const { return true; }
        ///
        col_type ncols() const;
        ///