Le 31/07/2015 17:05, Guillaume Munch a écrit :
\{ and \% now correctly use the selection as their argument instead of
erasing it. Solves <http://www.lyx.org/trac/ticket/6466>. Please criticise.



If there are no experts of math mode to review the patch, here's to help you check: 1) the change to InsetMathNest.cpp is inspired from existing code in Cursor.cpp:1542, 2) the new constructor in InsetMathComment is copied from InsetMathBrace (that's all).

While writing that I noticed that I forgot one line from Cursop.cpp (p->finalize()), here's the amended version.
>From d8ad5477f2032fcfd88c91aeaa487ae819bc89c4 Mon Sep 17 00:00:00 2001
From: gadmm <ga...@free.fr>
Date: Mon, 3 Aug 2015 14:21:03 +0100
Subject: [PATCH] \{ and \% now correctly use the selection as their argument
 instead of erasing it (bug #6466)

---
 src/mathed/InsetMathComment.cpp |  7 +++++++
 src/mathed/InsetMathComment.h   |  2 ++
 src/mathed/InsetMathNest.cpp    | 15 ++++++++++-----
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/mathed/InsetMathComment.cpp b/src/mathed/InsetMathComment.cpp
index 096cf38..ff91991 100644
--- a/src/mathed/InsetMathComment.cpp
+++ b/src/mathed/InsetMathComment.cpp
@@ -26,6 +26,13 @@ InsetMathComment::InsetMathComment(Buffer * buf)
 {}
 
 
+InsetMathComment::InsetMathComment(MathData const & ar)
+	: InsetMathNest(const_cast<Buffer *>(ar.buffer()), 1)
+{
+	cell(0) = ar;
+}
+
+
 InsetMathComment::InsetMathComment(Buffer * buf, docstring const & str)
 	: InsetMathNest(buf, 1)
 {
diff --git a/src/mathed/InsetMathComment.h b/src/mathed/InsetMathComment.h
index fa33c63..8cfe136 100644
--- a/src/mathed/InsetMathComment.h
+++ b/src/mathed/InsetMathComment.h
@@ -25,6 +25,8 @@ public:
 	///
 	InsetMathComment(Buffer * buf);
 	///
+	InsetMathComment(MathData const & ar);
+	///
 	explicit InsetMathComment(Buffer * buf, docstring const &);
 	///
 	void metrics(MetricsInfo & mi, Dimension & dim) const;
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 133c336..6f1a132 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -1657,12 +1657,17 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
 			} else if (c == '^' && currentMode() == InsetMath::MATH_MODE) {
 				cur.backspace();
 				cur.niceInsert(createInsetMath("mathcircumflex", buf));
-			} else if (c == '{') {
-				cur.backspace();
-				cur.niceInsert(MathAtom(new InsetMathBrace(buf)));
-			} else if (c == '%') {
+			} else if (c == '{' || c == '%') {
+				//using the saved selection as argument
+				InsetMathUnknown * p = cur.activeMacro();
+				p->finalize();
+				MathData sel(cur.buffer());
+				asArray(p->selection(), sel);
 				cur.backspace();
-				cur.niceInsert(MathAtom(new InsetMathComment(buf)));
+				if (c == '{')
+					cur.niceInsert(MathAtom(new InsetMathBrace(sel)));
+				else
+					cur.niceInsert(MathAtom(new InsetMathComment(sel)));
 			} else if (c == '#') {
 				LASSERT(cur.activeMacro(), return false);
 				cur.activeMacro()->setName(name + docstring(1, c));
-- 
2.1.4

Reply via email to