commit cd499fdef427a79d3172071982f446caf0cf154f
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Thu Oct 16 16:16:15 2014 +0200

    Erase correctly math multi-cell selection
    
    What a selection spans several cells in mathed, and a deletion occurs 
though LFUN_CHAR_DELETE_FORWARD for example, only the case of a proper grid was 
handled. When no such grid exists, all cells between the first and the last 
index are cleared now.
    
    Fixes part of bug #9747.

diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 185cf79..92a804b 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -1274,31 +1274,43 @@ void eraseSelection(Cursor & cur)
        //lyxerr << "cap::eraseSelection begin: " << cur << endl;
        CursorSlice const & i1 = cur.selBegin();
        CursorSlice const & i2 = cur.selEnd();
-       if (i1.inset().asInsetMath()) {
-               saveSelection(cur);
-               cur.top() = i1;
-               if (i1.idx() == i2.idx()) {
-                       i1.cell().erase(i1.pos(), i2.pos());
-                       // We may have deleted i1.cell(cur.pos()).
-                       // Make sure that pos is valid.
-                       if (cur.pos() > cur.lastpos())
-                               cur.pos() = cur.lastpos();
-               } else {
-                       InsetMath * p = i1.asInsetMath();
-                       Inset::row_type r1, r2;
-                       Inset::col_type c1, c2;
-                       region(i1, i2, r1, r2, c1, c2);
-                       for (Inset::row_type row = r1; row <= r2; ++row)
-                               for (Inset::col_type col = c1; col <= c2; ++col)
-                                       p->cell(p->index(row, col)).clear();
-                       // We've deleted the whole cell. Only pos 0 is valid.
-                       cur.pos() = 0;
-               }
-               // need a valid cursor. (Lgb)
-               cur.clearSelection();
+       if (!i1.asInsetMath()) {
+               LYXERR0("Can't erase this selection");
+               return;
+       }
+
+       saveSelection(cur);
+       cur.top() = i1;
+       InsetMath * p = i1.asInsetMath();
+       if (i1.idx() == i2.idx()) {
+               i1.cell().erase(i1.pos(), i2.pos());
+               // We may have deleted i1.cell(cur.pos()).
+               // Make sure that pos is valid.
+               if (cur.pos() > cur.lastpos())
+                       cur.pos() = cur.lastpos();
+       } else if (p->nrows() > 0 && p->ncols() > 0) {
+               // This is a grid, delete a nice square region
+               Inset::row_type r1, r2;
+               Inset::col_type c1, c2;
+               region(i1, i2, r1, r2, c1, c2);
+               for (Inset::row_type row = r1; row <= r2; ++row)
+                       for (Inset::col_type col = c1; col <= c2; ++col)
+                               p->cell(p->index(row, col)).clear();
+               // We've deleted the whole cell. Only pos 0 is valid.
+               cur.pos() = 0;
        } else {
-               lyxerr << "can't erase this selection 1" << endl;
+               Inset::idx_type idx1 = i1.idx();
+               Inset::idx_type idx2 = i2.idx();
+               if (idx1 > idx2)
+                       swap(idx1, idx2);
+               for (Inset::idx_type idx = idx1 ; idx <= idx2; ++idx)
+                       p->cell(idx).clear();
+               // We've deleted the whole cell. Only pos 0 is valid.
+               cur.pos() = 0;
        }
+
+       // need a valid cursor. (Lgb)
+       cur.clearSelection();
        //lyxerr << "cap::eraseSelection end: " << cur << endl;
 }
 
diff --git a/status.21x b/status.21x
index aee0f3c..f8f2f53 100644
--- a/status.21x
+++ b/status.21x
@@ -43,7 +43,8 @@ What's new
 
 - The indentation of beamer frame contents has been decreased and unified.
 
-- In mathed, select only current cell on double-click
+- In mathed, select only current cell on double-click (bug 9747).
+
 
 * DOCUMENTATION AND LOCALIZATION
 
@@ -155,8 +156,9 @@ What's new
 
 - Fix initialization problem with default Inset Layout.
 
-- When a counter is stepped, reset recursively all subcounters (bug #10063).
+- When a counter is stepped, reset recursively all subcounters (bug 10063).
 
+- Erase correctly math multi-cell selections (bug 9747).
 
 * INTERNALS
 

Reply via email to