Le 16/04/2012 22:18, Georg Baum a écrit :
Jean-Marc Lasgouttes wrote:
Here is what I would do after reverting 1fa39e1f953434. Does that seem
to work for you? THe idea is to only record undo (inset) once before the
insertion of the unknown inset.
It works, but not for pasting. I understand the idea, however the problem is
that you do not know before pasting whether to call recordUndoSelection() or
recordUndoInset(). Since my version does not work for pasting either your
patch is obviously better. Unfortunately I don't see how either of them can
be extended to work for pasting \hline.
OK, a new version (first the reversion, and then the actual patch). I do
not see why we could not always use recordUndoInset, except that it may
use more memory.
JMarc
>From 481ced1df1aa8fc7fff3af9ba34a83c42941236a Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Fri, 13 Apr 2012 13:03:59 +0200
Subject: [PATCH 1/2] Revert "Fix undo of entering \hline"
This reverts commit 1fa39e1f953434700f1af4fb2eb9b193dd1709df.
---
src/Cursor.cpp | 9 ++-------
src/mathed/InsetMathGrid.cpp | 1 -
src/mathed/InsetMathNest.cpp | 13 ++-----------
src/mathed/MathData.cpp | 2 ++
4 files changed, 6 insertions(+), 19 deletions(-)
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index be04294..7a13e1c 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -1599,11 +1599,8 @@ bool Cursor::macroModeClose()
docstring const name = s.substr(1);
InsetMathNest * const in = inset().asInsetMath()->asNestInset();
- if (in && in->interpretString(*this, s)) {
- // end undo group that was opened before in was created
- endUndoGroup();
+ if (in && in->interpretString(*this, s))
return true;
- }
MathAtom atom = buffer()->getMacro(name, *this, false) ?
MathAtom(new MathMacro(buffer(), name)) : createInsetMath(name, buffer());
@@ -1636,9 +1633,7 @@ bool Cursor::macroModeClose()
else
insert(selection);
}
-
- // end undo group that was opened before in was created
- endUndoGroup();
+
return true;
}
diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index 87f7d4b..ed77f71 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -184,7 +184,6 @@ bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
FuncStatus status;
if (getStatus(cur, fr, status)) {
if (status.enabled()) {
- cur.recordUndoInset();
rowinfo_[cur.row()].lines_++;
return true;
}
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 860d265..c2f4fc1 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -848,14 +848,10 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_SELF_INSERT:
if (cmd.argument().size() != 1) {
- // use a group because interpretString() might
- // record an extra undo step
- cur.beginUndoGroup();
cur.recordUndoSelection();
docstring const arg = cmd.argument();
if (!interpretString(cur, arg))
cur.insert(arg);
- cur.endUndoGroup();
break;
}
// Don't record undo steps if we are in macro mode and thus
@@ -1667,8 +1663,6 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
cur.cell().erase(cur.pos());
cur.plainInsert(MathAtom(
new InsetMathBig(name.substr(1), delim)));
- // end undo group that was opened before p was created
- cur.endUndoGroup();
return true;
}
}
@@ -1712,12 +1706,9 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
bool reduced = cap::reduceSelectionToOneCell(cur);
if (reduced || !cur.selection()) {
docstring const safe = cap::grabAndEraseSelection(cur);
- if (!cur.inRegexped()) {
- // open a group because interpretString() might
- // record an extra undo step when finalizing
- cur.beginUndoGroup();
+ if (!cur.inRegexped())
cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
- } else
+ else
cur.niceInsert(createInsetMath("backslash", buf));
}
return true;
diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp
index a4a11bb..8fcf746 100644
--- a/src/mathed/MathData.cpp
+++ b/src/mathed/MathData.cpp
@@ -28,6 +28,8 @@
#include "CoordCache.h"
#include "Cursor.h"
+#include "mathed/InsetMathUnknown.h"
+
#include "support/debug.h"
#include "support/docstream.h"
--
1.7.0.4
>From d459de3f2d6bcaf05ddcb286c73ea06b617b185a Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Tue, 17 Apr 2012 10:55:59 +0200
Subject: [PATCH 2/2] Simpler fix for undo support when entering \hline in an equation
* Avoid undo step when using backspace in macro mode
* Use recordUndoInset when entering macro mode (if one enters something like \hline, the outer inset itself will be modified)
* Use recordUndoInset when pasting in an INsetMathGrid (same reason as above)
---
src/mathed/InsetMathGrid.cpp | 2 +-
src/mathed/InsetMathNest.cpp | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index ed77f71..ac8cd49 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -1356,7 +1356,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
hline_enabled = status.enabled();
if (grid.nargs() == 1) {
// single cell/part of cell
- cur.recordUndo();
+ cur.recordUndoInset();
cur.cell().insert(cur.pos(), grid.cell(0));
cur.pos() += grid.cell(0).size();
if (hline_enabled)
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index c2f4fc1..5d35d77 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -806,7 +806,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
if (cur.pos() == 0)
// May affect external cell:
cur.recordUndoInset();
- else
+ else if (!cur.inMacroMode())
cur.recordUndoSelection();
// if the inset can not be removed from within, delete it
if (!cur.backspace()) {
@@ -1705,6 +1705,7 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
//lyxerr << "starting with macro" << endl;
bool reduced = cap::reduceSelectionToOneCell(cur);
if (reduced || !cur.selection()) {
+ cur.recordUndoInset();
docstring const safe = cap::grabAndEraseSelection(cur);
if (!cur.inRegexped())
cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
--
1.7.0.4