From: Georg Baum Date: Mon, 1 May 2006 08:05:22 +0000 (+0000) Subject: Code cleanup of \bigl related stuff: X-Git-Tag: 1.6.10~13270 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=143e14045fb116d293ba8f50d1e7865c7827b1ba;p=features.git 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 --- diff --git a/src/cursor.C b/src/cursor.C index 45ba966efd..4c7b6a9873 100644 --- a/src/cursor.C +++ b/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; } diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index d5d4305e99..69752b5217 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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) { diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index cbf0725b35..99728f34ef 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -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