]> git.lyx.org Git - features.git/commitdiff
Fix bug 1802: http://bugzilla.lyx.org/show_bug.cgi?id=1802.
authorVincent van Ravesteijn <vfr@lyx.org>
Sat, 7 Feb 2009 15:24:47 +0000 (15:24 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Sat, 7 Feb 2009 15:24:47 +0000 (15:24 +0000)
* allows the selection of a whole cell with shift+key
* shift-movement between empty cells with a single keystroke

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28385 a592a061-630c-0410-9148-cb99ea01b6c8

src/Text.cpp
src/Text.h
src/insets/InsetTabular.cpp

index dde070405f0c585cbd511075369ff3279702c88b..91b8a5f02a456ad58c5df78fd1736cfc0c0e8030 100644 (file)
@@ -757,6 +757,25 @@ void Text::selectWord(Cursor & cur, word_location loc)
 }
 
 
+void Text::selectAll(Cursor & cur)
+{
+       LASSERT(this == cur.text(), /**/);
+       if (cur.lastpos() == 0 && cur.lastpit() == 0)
+               return;
+       // If the cursor is at the beginning, make sure the cursor ends there
+       if (cur.pit() == 0 && cur.pos() == 0) {
+               setCursor(cur, cur.lastpit(), getPar(cur.lastpit()).size());
+               cur.resetAnchor();
+               setCursor(cur, 0, 0);           
+       } else {
+               setCursor(cur, 0, 0);
+               cur.resetAnchor();
+               setCursor(cur, cur.lastpit(), getPar(cur.lastpit()).size());
+       }
+       cur.setSelection();
+}
+
+
 // Select the word currently under the cursor when no
 // selection is currently set
 bool Text::selectWordWhenUnderCursor(Cursor & cur, word_location loc)
index 3beda155a5b9616e104d4028e0af3d24ec090b55..df19ca7ae2dc71c20621bb692c9a4f4a9d274ae8 100644 (file)
@@ -149,6 +149,8 @@ public:
        void getWord(CursorSlice & from, CursorSlice & to, word_location const) const;
        /// just selects the word the cursor is in
        void selectWord(Cursor & cur, word_location loc);
+       /// select all text
+       void selectAll(Cursor & cur);
        /// convenience function get the previous word or an empty string
        docstring previousWord(CursorSlice const & sl) const;
        
index 6e871a6098094fd4a1cdb2c8145d73b82d4d7264..e518ce343049c5c5c9d05ccfaaf91ddfae1e1983 100644 (file)
@@ -3401,18 +3401,43 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                        finish_lfun = right ? LFUN_FINISHED_RIGHT : LFUN_FINISHED_LEFT;
                }
 
-               // if we don't have a multicell selection...
-               if (!cur.selIsMultiCell() ||
-                 // ...or we're not doing some LFUN_*_SELECT thing, anyway...
-                   (cmd.action != LFUN_CHAR_FORWARD_SELECT &&
-                    cmd.action != LFUN_CHAR_BACKWARD_SELECT &&
-                    cmd.action != LFUN_CHAR_RIGHT_SELECT &&
-                    cmd.action != LFUN_CHAR_LEFT_SELECT)) {
+               bool const select = cmd.action == LFUN_CHAR_FORWARD_SELECT ||
+                   cmd.action == LFUN_CHAR_BACKWARD_SELECT ||
+                   cmd.action == LFUN_CHAR_RIGHT_SELECT ||
+                   cmd.action == LFUN_CHAR_LEFT_SELECT;
+
+               // If we have a multicell selection or we're 
+               // not doing some LFUN_*_SELECT thing anyway...
+               if (!cur.selIsMultiCell() || !select) {
+                       col_type const c = tabular.cellColumn(cur.idx());
+                       row_type const r = tabular.cellRow(cur.idx());
+                       // Are we trying to select the whole cell and is the whole cell 
+                       // not yet selected?
+                       bool const select_whole = select && !isCellSelected(cur, r, c) &&
+                               ((next_cell && cur.pit() == cur.lastpit() 
+                               && cur.pos() == cur.lastpos())
+                               || (!next_cell && cur.pit() == 0 && cur.pos() == 0));
+
                        // ...try to dispatch to the cell's inset.
                        cell(cur.idx())->dispatch(cur, cmd);
-                       if (cur.result().dispatched()) 
+
+                       bool const empty_cell = cur.lastpos() == 0 && cur.lastpit() == 0;
+                       
+                       // When we already have a selection we want to select the whole cell
+                       // before going to the next cell.
+                       if (select_whole && !empty_cell){
+                               getText(cur.idx())->selectAll(cur);
+                               cur.dispatched();
+                               break;
+                       }
+
+                       // FIXME: When we support the selection of an empty cell, remove 
+                       // the !empty_cell from this condition. For now we jump to the next
+                       // cell if the current cell is empty.
+                       if (cur.result().dispatched() && !empty_cell)
                                break;
                }
+
                // move to next/prev cell, as appropriate
                // note that we will always do this if we're selecting and we have
                // a multicell selection