]> git.lyx.org Git - features.git/commitdiff
* only use selection of current cell when starting a macro (fixes http://bugzilla...
authorStefan Schimanski <sts@lyx.org>
Wed, 12 Mar 2008 00:18:39 +0000 (00:18 +0000)
committerStefan Schimanski <sts@lyx.org>
Wed, 12 Mar 2008 00:18:39 +0000 (00:18 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23670 a592a061-630c-0410-9148-cb99ea01b6c8

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

index bd0b3baaa7cdddfa974b49b52897f687ba0dd97d..98abfe1e98d2f0c5a2d8fee5b6ededcf991680c5 100644 (file)
@@ -434,6 +434,28 @@ docstring grabAndEraseSelection(Cursor & cur)
 }
 
 
+bool reduceSelectionToOneCell(Cursor & cur)
+{
+       if (!cur.selection() || !cur.inMathed())
+               return false;
+
+       CursorSlice i1 = cur.selBegin();
+       CursorSlice i2 = cur.selEnd();
+       if (!i1.inset().asInsetMath())
+               return false;
+
+       // the easy case: do nothing if only one cell is selected
+       if (i1.idx() == i2.idx())
+               return true;
+       
+       cur.top().pos() = 0;
+       cur.resetAnchor();
+       cur.top().pos() = cur.top().lastpos();
+       
+       return true;
+}
+
+
 void switchBetweenClasses(DocumentClass const * const oldone, 
                DocumentClass const * const newone, InsetText & in, ErrorList & errorlist)
 {
@@ -932,8 +954,10 @@ docstring grabSelection(Cursor const & cur)
        if (!cur.selection())
                return docstring();
 
-       // FIXME: What is wrong with the following?
 #if 0
+       // grab selection by glueing multiple cells together. This is not what
+       // we want because selections spanning multiple cells will get "&" and "\\"
+       // seperators.
        ostringstream os;
        for (DocIterator dit = cur.selectionBegin();
             dit != cur.selectionEnd(); dit.forwardPos())
index 3796966f0969ef1d22e1ae0f748414ec7da5a847..e16d4377344585871819f46d6c7a679fab63cc1b 100644 (file)
@@ -116,6 +116,11 @@ docstring grabSelection(Cursor const & cur);
 /// Does not handle undo. Does only work if the whole selection is in mathed.
 /// Calls saveSelection.
 void eraseSelection(Cursor & cur);
+/// Reduce the selected text in mathed to only one cell. If it spans multiple
+/// cells, the cursor is moved the end of the current cell and the anchor to the
+/// start. If the selection is inside only one cell, nothing is done. Return
+/// true if the selection now does not span multiple cells anymore.
+bool reduceSelectionToOneCell(Cursor & cur);
 /// Erase the selection and return it as a string.
 /// Does not handle undo. Does only work if the whole selection is in mathed.
 docstring grabAndEraseSelection(Cursor & cur);
index 9d173aac878dcee94a02bd4a3624fffc98bbb68d..6895f2eeb1f004f05665933dfc023c7a2a7315c2 100644 (file)
@@ -1415,8 +1415,11 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
 
        if (c == '\\') {
                //lyxerr << "starting with macro" << endl;
-               docstring const safe = cap::grabAndEraseSelection(cur);
-               cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
+               bool reduced = cap::reduceSelectionToOneCell(cur);
+               if (reduced || !cur.selection()) {
+                       docstring const safe = cap::grabAndEraseSelection(cur);
+                       cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
+               }
                return true;
        }