mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
* only use selection of current cell when starting a macro (fixes http://bugzilla.lyx.org/show_bug.cgi?id=4566 for macros)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23670 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4461cc2fda
commit
b2e8d557cc
@ -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())
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user