]> git.lyx.org Git - features.git/commitdiff
* fix for http://bugzilla.lyx.org/show_bug.cgi?id=4566
authorStefan Schimanski <sts@lyx.org>
Wed, 12 Mar 2008 00:19:31 +0000 (00:19 +0000)
committerStefan Schimanski <sts@lyx.org>
Wed, 12 Mar 2008 00:19:31 +0000 (00:19 +0000)
  "Eqnarray multiple cells size change erases what they contain"

  We now loop over the selected cells and change the font in each of them.

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

src/CutAndPaste.cpp
src/CutAndPaste.h
src/mathed/InsetMathNest.cpp

index 98abfe1e98d2f0c5a2d8fee5b6ededcf991680c5..0b3e8f5ed89f8a4d8ba460ce2f842349f98b26b2 100644 (file)
@@ -82,22 +82,6 @@ CutStack selectionBuffer(1);
 bool dirty_tabular_stack_ = false;
 
 
-void region(CursorSlice const & i1, CursorSlice const & i2,
-       Inset::row_type & r1, Inset::row_type & r2,
-       Inset::col_type & c1, Inset::col_type & c2)
-{
-       Inset & p = i1.inset();
-       c1 = p.col(i1.idx());
-       c2 = p.col(i2.idx());
-       if (c1 > c2)
-               swap(c1, c2);
-       r1 = p.row(i1.idx());
-       r2 = p.row(i2.idx());
-       if (r1 > r2)
-               swap(r1, r2);
-}
-
-
 bool checkPastePossible(int index)
 {
        return size_t(index) < theCuts.size() && !theCuts[index].first.empty();
@@ -424,6 +408,22 @@ void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
 
 namespace cap {
 
+void region(CursorSlice const & i1, CursorSlice const & i2,
+           Inset::row_type & r1, Inset::row_type & r2,
+           Inset::col_type & c1, Inset::col_type & c2)
+{
+       Inset & p = i1.inset();
+       c1 = p.col(i1.idx());
+       c2 = p.col(i2.idx());
+       if (c1 > c2)
+               swap(c1, c2);
+       r1 = p.row(i1.idx());
+       r2 = p.row(i2.idx());
+       if (r1 > r2)
+               swap(r1, r2);
+}
+
+
 docstring grabAndEraseSelection(Cursor & cur)
 {
        if (!cur.selection())
index 337d9967ed19a746fb68c61df5bba2660eaeda58..39de6b903674c2c6b93d56d24986ebc73bfa1b60 100644 (file)
@@ -131,7 +131,10 @@ void selDel(Cursor & cur);
 /// Clear or delete the selection if one exists, depending on lyxrc setting.
 /// Does not handle undo. Does only work if the whole selection is in mathed.
 void selClearOrDel(Cursor & cur);
-
+/// Calculate rectangular region of cell between \c i1 and \c i2.
+void region(CursorSlice const & i1, CursorSlice const & i2,
+    Inset::row_type & r1, Inset::row_type & r2,
+    Inset::col_type & c1, Inset::col_type & c2);
 /** Tabular has its own paste stack for multiple cells
  *  but it needs to know whether there is a more recent
  *  ordinary paste. Therefore which one is newer.
index 6895f2eeb1f004f05665933dfc023c7a2a7315c2..2ee6ee786f8568d5235fc908e6aec1e96d0af664 100644 (file)
@@ -408,8 +408,7 @@ void InsetMathNest::handleFont
 }
 
 
-void InsetMathNest::handleFont
-       (Cursor & cur, docstring const & arg, docstring const & font)
+void InsetMathNest::handleFont(Cursor & cur, docstring const & arg, docstring const & font)
 {
        // this whole function is a hack and won't work for incremental font
        // changes...
@@ -418,9 +417,65 @@ void InsetMathNest::handleFont
                cur.recordUndoInset();
                cur.handleFont(to_utf8(font));
        } else {
-               cur.recordUndo();
-               cur.handleNest(createInsetMath(font));
-               cur.insert(arg);
+               CursorSlice i1 = cur.selBegin();
+               CursorSlice i2 = cur.selEnd();
+               if (!i1.inset().asInsetMath())
+                       return;
+               if (i1.idx() == i2.idx()) {
+                       // the easy case where only one cell is selected
+                       cur.recordUndo();
+                       cur.handleNest(createInsetMath(font));
+                       cur.insert(arg);
+                       return;
+               }
+               
+               // multiple selected cells in a simple non-grid inset
+               if (i1.asInsetMath()->nrows() == 0 || i1.asInsetMath()->ncols() == 0) {
+                       cur.recordUndoInset();
+                       for (idx_type i = i1.idx(); i <= i2.idx(); ++i) {
+                               // select cell
+                               cur.idx() = i;
+                               cur.pos() = 0;
+                               cur.resetAnchor();
+                               cur.pos() = cur.lastpos();
+                               cur.setSelection();
+                               
+                               // change font of cell
+                               cur.handleNest(createInsetMath(font));
+                               cur.insert(arg);
+                               
+                               // cur is in the font inset now. If the loop continues,
+                               // we need to get outside again for the next cell
+                               if (i + 1 <= i2.idx())
+                                       cur.pop_back();
+                       }
+                       return;
+               }
+
+               // the complicated case with multiple selected cells in a grid
+               cur.recordUndoInset();
+               Inset::row_type r1, r2;
+               Inset::col_type c1, c2;
+               cap::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) {
+                               // select cell
+                               cur.idx() = i1.asInsetMath()->index(row, col);
+                               cur.pos() = 0;
+                               cur.resetAnchor();
+                               cur.pos() = cur.lastpos();
+                               cur.setSelection();
+
+                               // change font of cell
+                               cur.handleNest(createInsetMath(font));
+                               cur.insert(arg);
+
+                               // cur is in the font inset now. If the loop continues,
+                               // we need to get outside again for the next cell
+                               if (col + 1 <= c2 || row + 1 <= r2)
+                                       cur.pop_back();
+                       }
+               }
        }
 }