mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 10:18:50 +00:00
* store the selection in the InsetMathUnknown and insert it into the
first argument after finalizing the macro. This also works with real math macros. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23449 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
501763cafa
commit
03a1c9192e
@ -43,6 +43,7 @@
|
|||||||
#include "insets/InsetText.h"
|
#include "insets/InsetText.h"
|
||||||
|
|
||||||
#include "mathed/InsetMath.h"
|
#include "mathed/InsetMath.h"
|
||||||
|
#include "mathed/InsetMathBrace.h"
|
||||||
#include "mathed/InsetMathScript.h"
|
#include "mathed/InsetMathScript.h"
|
||||||
#include "mathed/MacroTable.h"
|
#include "mathed/MacroTable.h"
|
||||||
#include "mathed/MathData.h"
|
#include "mathed/MathData.h"
|
||||||
@ -1208,6 +1209,8 @@ bool Cursor::macroModeClose()
|
|||||||
return false;
|
return false;
|
||||||
InsetMathUnknown * p = activeMacro();
|
InsetMathUnknown * p = activeMacro();
|
||||||
p->finalize();
|
p->finalize();
|
||||||
|
MathData selection;
|
||||||
|
asArray(p->selection(), selection);
|
||||||
docstring const s = p->name();
|
docstring const s = p->name();
|
||||||
--pos();
|
--pos();
|
||||||
cell().erase(pos());
|
cell().erase(pos());
|
||||||
@ -1225,12 +1228,37 @@ bool Cursor::macroModeClose()
|
|||||||
if (in && in->interpretString(*this, s))
|
if (in && in->interpretString(*this, s))
|
||||||
return true;
|
return true;
|
||||||
MathAtom atom = createInsetMath(name);
|
MathAtom atom = createInsetMath(name);
|
||||||
|
|
||||||
|
// try to put argument into macro, if we just inserted a macro
|
||||||
|
bool macroArg = false;
|
||||||
MathMacro * atomAsMacro = atom.nucleus()->asMacro();
|
MathMacro * atomAsMacro = atom.nucleus()->asMacro();
|
||||||
if (atomAsMacro) {
|
if (atomAsMacro) {
|
||||||
// make non-greedy, i.e. don't eat parameters from the right
|
// macros here are still unfolded (in init mode in fact). So
|
||||||
atomAsMacro->setDisplayMode(MathMacro::DISPLAY_INTERACTIVE_INIT);
|
// we have to resolve the macro here manually and check its arity
|
||||||
|
// to put the selection behind it if arity > 0.
|
||||||
|
MacroData const * data = buffer().getMacro(atomAsMacro->name());
|
||||||
|
if (selection.size() > 0 && data && data->numargs() - data->optionals() > 0) {
|
||||||
|
macroArg = true;
|
||||||
|
atomAsMacro->setDisplayMode(MathMacro::DISPLAY_INTERACTIVE_INIT, 1);
|
||||||
|
} else
|
||||||
|
// non-greedy case. Do not touch the arguments behind
|
||||||
|
atomAsMacro->setDisplayMode(MathMacro::DISPLAY_INTERACTIVE_INIT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// insert remembered selection into first argument of a non-macro
|
||||||
|
else if (atom.nucleus()->nargs() > 0)
|
||||||
|
atom.nucleus()->cell(0).append(selection);
|
||||||
|
|
||||||
plainInsert(atom);
|
plainInsert(atom);
|
||||||
|
|
||||||
|
// finally put the macro argument behind, if needed
|
||||||
|
if (macroArg) {
|
||||||
|
if (selection.size() > 1)
|
||||||
|
plainInsert(MathAtom(new InsetMathBrace(selection)));
|
||||||
|
else
|
||||||
|
insert(selection);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1423,14 +1423,15 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
selClearOrDel(cur);
|
|
||||||
|
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
//lyxerr << "starting with macro" << endl;
|
//lyxerr << "starting with macro" << endl;
|
||||||
cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), false)));
|
docstring const safe = cap::grabAndEraseSelection(cur);
|
||||||
|
cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selClearOrDel(cur);
|
||||||
|
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
if (currentMode() == InsetMath::TEXT_MODE)
|
if (currentMode() == InsetMath::TEXT_MODE)
|
||||||
cur.insert(c);
|
cur.insert(c);
|
||||||
|
@ -16,11 +16,14 @@
|
|||||||
#include "MathStream.h"
|
#include "MathStream.h"
|
||||||
#include "MathStream.h"
|
#include "MathStream.h"
|
||||||
|
|
||||||
|
#include "frontends/Painter.h"
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
InsetMathUnknown::InsetMathUnknown(docstring const & nm, bool final, bool black)
|
InsetMathUnknown::InsetMathUnknown(docstring const & nm,
|
||||||
: name_(nm), final_(final), black_(black)
|
docstring const & selection, bool final, bool black)
|
||||||
|
: name_(nm), final_(final), black_(black), selection_(selection)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +65,6 @@ void InsetMathUnknown::draw(PainterInfo & pi, int x, int y) const
|
|||||||
drawStrBlack(pi, x, y, name_);
|
drawStrBlack(pi, x, y, name_);
|
||||||
else
|
else
|
||||||
drawStrRed(pi, x, y, name_);
|
drawStrRed(pi, x, y, name_);
|
||||||
setPosCache(pi, x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ class InsetMathUnknown : public InsetMath {
|
|||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
explicit InsetMathUnknown(docstring const & name,
|
explicit InsetMathUnknown(docstring const & name,
|
||||||
|
docstring const & selection = docstring(),
|
||||||
bool final = true, bool black = false);
|
bool final = true, bool black = false);
|
||||||
///
|
///
|
||||||
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
||||||
@ -33,6 +34,9 @@ public:
|
|||||||
///
|
///
|
||||||
docstring name() const;
|
docstring name() const;
|
||||||
|
|
||||||
|
///
|
||||||
|
docstring const & selection() const { return selection_; }
|
||||||
|
|
||||||
/// identifies UnknownInsets
|
/// identifies UnknownInsets
|
||||||
InsetMathUnknown const * asUnknownInset() const { return this; }
|
InsetMathUnknown const * asUnknownInset() const { return this; }
|
||||||
/// identifies UnknownInsets
|
/// identifies UnknownInsets
|
||||||
@ -54,6 +58,7 @@ public:
|
|||||||
bool final() const;
|
bool final() const;
|
||||||
///
|
///
|
||||||
int kerning(BufferView const *) const { return kerning_; }
|
int kerning(BufferView const *) const { return kerning_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual Inset * clone() const;
|
virtual Inset * clone() const;
|
||||||
///
|
///
|
||||||
@ -64,6 +69,8 @@ private:
|
|||||||
bool black_;
|
bool black_;
|
||||||
///
|
///
|
||||||
mutable int kerning_;
|
mutable int kerning_;
|
||||||
|
/// the selection which was replaced by this
|
||||||
|
docstring selection_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user