]> git.lyx.org Git - lyx.git/commitdiff
Code cleanup of \bigl related stuff:
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 1 May 2006 08:05:22 +0000 (08:05 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 1 May 2006 08:05:22 +0000 (08:05 +0000)
* 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

src/cursor.C
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h

index 45ba966efdbb36772317905909488a4db3993830..4c7b6a9873585a819a65ecdc0659312d742d13b4 100644 (file)
@@ -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 d5d4305e99de85df71fa18b94166421bcd8ad8ba..69752b52172027480071014ebcc2e613fbe6819c 100644 (file)
@@ -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)
 {
index cbf0725b352111293115fc00c524585a39051e49..99728f34ef58aec88cbb3e9a20e5fb4188b72307 100644 (file)
@@ -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