mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Code cleanup of \bigl related stuff:
* src/cursor.C (LCursor::plainInsert): Move special \bigl stuff from here to MathNestInset::interpret (LCursor::macroModeClose): try to intepret the current macro before it is simply inserted * src/mathed/math_nestinset.C (MathNestInset::doDispatch): try to intepret the argument of LFUN_SELFINSERT also if it is longer than one character * src/mathed/math_nestinset.[Ch] (MathNestInset::interpret): new, moved from LCursor::plainInsert git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13786 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4c7d66bfda
commit
143e14045f
20
src/cursor.C
20
src/cursor.C
@ -35,7 +35,6 @@
|
||||
#include "insets/insettabular.h"
|
||||
#include "insets/insettext.h"
|
||||
|
||||
#include "mathed/math_biginset.h"
|
||||
#include "mathed/math_data.h"
|
||||
#include "mathed/math_inset.h"
|
||||
#include "mathed/math_scriptinset.h"
|
||||
@ -652,22 +651,6 @@ void LCursor::markErase()
|
||||
|
||||
void LCursor::plainInsert(MathAtom const & t)
|
||||
{
|
||||
// Create a MathBigInset from cell()[pos() - 1] and t if possible
|
||||
if (!empty() && pos() > 0 && cell()[pos() - 1]->asUnknownInset()) {
|
||||
string const name = asString(t);
|
||||
if (MathBigInset::isBigInsetDelim(name)) {
|
||||
string prev = asString(cell()[pos() - 1]);
|
||||
if (prev[0] == '\\') {
|
||||
prev = prev.substr(1);
|
||||
latexkeys const * l = in_word_set(prev);
|
||||
if (l && l->inset == "big") {
|
||||
cell()[pos() - 1] =
|
||||
MathAtom(new MathBigInset(prev, name));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cell().insert(pos(), t);
|
||||
++pos();
|
||||
}
|
||||
@ -877,6 +860,9 @@ bool LCursor::macroModeClose()
|
||||
if (macro && macro->getInsetName() == name)
|
||||
lyxerr << "can't enter recursive macro" << endl;
|
||||
|
||||
MathNestInset * const in = inset().asMathInset()->asNestInset();
|
||||
if (in && in->interpret(*this, s))
|
||||
return true;
|
||||
plainInsert(createMathInset(name));
|
||||
return true;
|
||||
}
|
||||
|
@ -664,7 +664,8 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
case LFUN_SELFINSERT:
|
||||
if (cmd.argument.size() != 1) {
|
||||
recordUndo(cur);
|
||||
cur.insert(cmd.argument);
|
||||
if (!interpret(cur, cmd.argument))
|
||||
cur.insert(cmd.argument);
|
||||
break;
|
||||
}
|
||||
// Don't record undo steps if we are in macro mode and
|
||||
@ -1146,7 +1147,7 @@ bool MathNestInset::interpret(LCursor & cur, char c)
|
||||
}
|
||||
|
||||
// One character big delimiters. The others are handled in
|
||||
// LCursor::plainInsert.
|
||||
// the other interpret() method.
|
||||
latexkeys const * l = in_word_set(name.substr(1));
|
||||
if (name[0] == '\\' && l && l->inset == "big") {
|
||||
string delim;
|
||||
@ -1251,8 +1252,8 @@ bool MathNestInset::interpret(LCursor & cur, char c)
|
||||
}
|
||||
}
|
||||
|
||||
if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == '%'
|
||||
|| c == '_' || c == '^') {
|
||||
if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' ||
|
||||
c == '%' || c == '_' || c == '^') {
|
||||
cur.niceInsert(createMathInset(string(1, c)));
|
||||
return true;
|
||||
}
|
||||
@ -1269,6 +1270,29 @@ bool MathNestInset::interpret(LCursor & cur, char c)
|
||||
}
|
||||
|
||||
|
||||
bool MathNestInset::interpret(LCursor & cur, string const & str)
|
||||
{
|
||||
// Create a MathBigInset from cur.cell()[cur.pos() - 1] and t if
|
||||
// possible
|
||||
if (!cur.empty() && cur.pos() > 0 &&
|
||||
cur.cell()[cur.pos() - 1]->asUnknownInset()) {
|
||||
if (MathBigInset::isBigInsetDelim(str)) {
|
||||
string prev = asString(cur.cell()[cur.pos() - 1]);
|
||||
if (prev[0] == '\\') {
|
||||
prev = prev.substr(1);
|
||||
latexkeys const * l = in_word_set(prev);
|
||||
if (l && l->inset == "big") {
|
||||
cur.cell()[cur.pos() - 1] =
|
||||
MathAtom(new MathBigInset(prev, str));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool MathNestInset::script(LCursor & cur, bool up, string const &
|
||||
save_selection)
|
||||
{
|
||||
|
@ -107,12 +107,18 @@ protected:
|
||||
///
|
||||
void handleFont2(LCursor & cur, std::string const & arg);
|
||||
|
||||
///
|
||||
/// interpret \p c and insert the result at the current position of
|
||||
/// of \p cur. Return whether the cursor should stay in the formula.
|
||||
bool interpret(LCursor & cur, char c);
|
||||
///
|
||||
bool script(LCursor & cur, bool,
|
||||
std::string const & save_selection = std::string());
|
||||
|
||||
public:
|
||||
/// interpret \p str and insert the result at the current position of
|
||||
/// \p cur if it is something known. Return whether \p cur was
|
||||
/// inserted.
|
||||
bool interpret(LCursor & cur, std::string const & str);
|
||||
|
||||
private:
|
||||
/// lfun handler
|
||||
|
Loading…
Reference in New Issue
Block a user