From bee48063a04391c80b9dc0463f494dfe815eafc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Mon, 17 Mar 2008 11:49:12 +0000 Subject: [PATCH] backport rev. 23673 from sts, which partially fixes a major dataloss bug: URL: http://www.lyx.org/trac/changeset/23673 Log: * fix for http://bugzilla.lyx.org/show_bug.cgi?id=4566 "Eqnarray multiple cells size change erases what they contain" We now loop over the selected cells and change the font in each of them. Note that the bug still applies if a font change is done via the math panel. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_5_X@23789 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CutAndPaste.cpp | 32 +++++++++---------- src/CutAndPaste.h | 5 +++ src/mathed/InsetMathNest.cpp | 60 ++++++++++++++++++++++++++++++++++-- status.15x | 3 ++ 4 files changed, 81 insertions(+), 19 deletions(-) diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 913479f1ec..4aa991d8b7 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -83,22 +83,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) - std::swap(c1, c2); - r1 = p.row(i1.idx()); - r2 = p.row(i2.idx()); - if (r1 > r2) - std::swap(r1, r2); -} - - bool checkPastePossible(int index) { return size_t(index) < theCuts.size() && !theCuts[index].first.empty(); @@ -394,6 +378,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) + std::swap(c1, c2); + r1 = p.row(i1.idx()); + r2 = p.row(i2.idx()); + if (r1 > r2) + std::swap(r1, r2); +} + + docstring grabAndEraseSelection(Cursor & cur) { if (!cur.selection()) diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index ef26ce9f3b..ccc92461a9 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -15,6 +15,7 @@ #define CUTANDPASTE_H #include "support/docstring.h" +#include "insets/InsetTabular.h" #include @@ -101,6 +102,10 @@ void pasteParagraphList(Cursor & cur, ParagraphList const & parlist, void switchBetweenClasses(textclass_type c1, textclass_type c2, InsetText & in, ErrorList &); +/// 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); /// Get the current selection as a string. Does not change the selection. /// Does only work if the whole selection is in mathed. docstring grabSelection(Cursor const & cur); diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 9f6a997968..b041305c64 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -417,9 +417,63 @@ void InsetMathNest::handleFont recordUndoInset(cur, Undo::ATOMIC); cur.handleFont(to_utf8(font)); } else { - recordUndo(cur, Undo::ATOMIC); - 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 + recordUndo(cur, Undo::ATOMIC); + 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) { + recordUndoInset(cur); + 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 + recordUndoInset(cur); + 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(); + } + } } } diff --git a/status.15x b/status.15x index cc9e7f9f3a..45aa038d93 100644 --- a/status.15x +++ b/status.15x @@ -89,6 +89,9 @@ What's new * USER INTERFACE: +- Correctly apply font changes when several math matrix cells are selected + (part of bug 4566). + - Allow deleting a label in a formula as well as the numbering with the delete key (bug 2556).