]> git.lyx.org Git - features.git/commitdiff
* handle the multiple-selected-cells case also for color changes in mathed
authorStefan Schimanski <sts@lyx.org>
Wed, 12 Mar 2008 14:04:25 +0000 (14:04 +0000)
committerStefan Schimanski <sts@lyx.org>
Wed, 12 Mar 2008 14:04:25 +0000 (14:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23682 a592a061-630c-0410-9148-cb99ea01b6c8

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

index 572e70d88a43aced8c8a32cb60f5ecfebc9268b9..377724444d06c14b696b2b48c82e83edadb8bbd1 100644 (file)
@@ -416,65 +416,70 @@ void InsetMathNest::handleFont(Cursor & cur, docstring const & arg, docstring co
        if (cur.inset().asInsetMath()->name() == font) {
                cur.recordUndoInset();
                cur.handleFont(to_utf8(font));
-       } else {
-               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));
+       } else
+               handleNest(cur, createInsetMath(font), arg);
+}
+
+
+void InsetMathNest::handleNest(Cursor & cur, MathAtom const & nest, docstring const & 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(nest);
+               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(nest);
                        cur.insert(arg);
-                       return;
+                       
+                       // 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();
+                       
+                       // 
+                       cur.handleNest(nest);
+                       cur.insert(arg);
                
-               // 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();
-                       }
+                       // 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();
                }
        }
 }
@@ -486,10 +491,8 @@ void InsetMathNest::handleFont2(Cursor & cur, docstring const & arg)
        Font font;
        bool b;
        font.fromString(to_utf8(arg), b);
-       if (font.fontInfo().color() != Color_ignore) {
-               MathAtom at = MathAtom(new InsetMathColor(true, font.fontInfo().color()));
-               cur.handleNest(at, 0);
-       }
+       if (font.fontInfo().color() != Color_ignore)
+               handleNest(cur, MathAtom(new InsetMathColor(true, font.fontInfo().color())));
        
        // FIXME: support other font changes here as well?
 }
index 72d14e6c71a4ca7ff3caa1af1d049a82471b6823..7e2b7a40a869b89496707beb55c6206fd32c63f0 100644 (file)
@@ -169,6 +169,11 @@ protected:
                docstring const & arg, char const * const font);
        ///
        void handleFont2(Cursor & cur, docstring const & arg);
+       /// Grab and erase selection and insert the InsetMathNest atom in every
+       /// previously selected cell, insert the grabbed former data and \c arg
+       /// in the first cell of the inserted atom.
+       void handleNest(Cursor & cur, MathAtom const & nest,
+               docstring const & arg = docstring());
 
        /// interpret \p c and insert the result at the current position of
        /// of \p cur. Return whether the cursor should stay in the formula.