Am Donnerstag, 27. April 2006 20:18 schrieb Andre Poenitz: > On Thu, Apr 27, 2006 at 09:24:42AM +0200, Georg Baum wrote: > > > In any case, all magic should go to interpret() & Co., not to > > > LCursor::plainInsert(). > > > > That works for one-character delimiters, but not for things like \Vert. It > > should be possible to introduce a second interpret method that is called > > from LCursor::macroModeClose() and LCursor::insert(). Would that be OK with > > you? > > Yes. > > > If you want I'll revert the changes to plainInsert, > > Please. > > > but I am not going to implement the cell based solution, since I don't > > like it UI-wise at all. > > Fine with me as long as no special case math stuff goes to LCursor.
Here is the patch that is going in soon. There is still a bit of math stuff in LCursor::macroModeClose(), but that is no surprise since the whole method is math-specific. Georg Log: 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
Index: src/cursor.C =================================================================== --- src/cursor.C (Revision 13784) +++ src/cursor.C (Arbeitskopie) @@ -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; } Index: src/mathed/math_nestinset.C =================================================================== --- src/mathed/math_nestinset.C (Revision 13784) +++ src/mathed/math_nestinset.C (Arbeitskopie) @@ -664,7 +664,8 @@ void MathNestInset::doDispatch(LCursor & 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 & } // 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 & } } - 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 & } +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) { Index: src/mathed/math_nestinset.h =================================================================== --- src/mathed/math_nestinset.h (Revision 13784) +++ src/mathed/math_nestinset.h (Arbeitskopie) @@ -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