]> git.lyx.org Git - features.git/blobdiff - src/Text3.cpp
* Lazy MathData to avoid unneeded interpretation of macro definitions
[features.git] / src / Text3.cpp
index 8490e4491743bf98aa9c053a92178b20426cd8b0..b90c6c84823d4b39b22b5df30ce604b48b3dee8e 100644 (file)
@@ -62,7 +62,6 @@
 #include "insets/InsetInfo.h"
 
 #include "support/lstrings.h"
-#include "support/lyxlib.h"
 #include "support/convert.h"
 #include "support/lyxtime.h"
 
@@ -191,7 +190,7 @@ static bool doInsertInset(Cursor & cur, Text * text,
 
        cur.recordUndo();
        if (cmd.action == LFUN_INDEX_INSERT) {
-               docstring ds = support::subst(text->getStringToIndex(cur), '\n', ' ');
+               docstring ds = subst(text->getStringToIndex(cur), '\n', ' ');
                text->insertInset(cur, inset);
                if (edit)
                        inset->edit(cur, true);
@@ -298,8 +297,8 @@ static void outline(OutlineOp mode, Cursor & cur)
                        // Not found; do nothing
                        if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
                                break;
-                       pit_type const newpit = std::distance(bgn, dest);
-                       pit_type const len = std::distance(start, finish);
+                       pit_type const newpit = distance(bgn, dest);
+                       pit_type const len = distance(start, finish);
                        pit_type const deletepit = pit + len;
                        buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
                        pars.insert(dest, start, finish);
@@ -331,8 +330,8 @@ static void outline(OutlineOp mode, Cursor & cur)
                                        break;
                        }
                        // One such was found:
-                       pit_type newpit = std::distance(bgn, dest);
-                       pit_type const len = std::distance(start, finish);
+                       pit_type newpit = distance(bgn, dest);
+                       pit_type const len = distance(start, finish);
                        buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
                        pars.insert(dest, start, finish);
                        start = boost::next(bgn, pit);
@@ -413,7 +412,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                pit_type const pit = cur.pit();
                recUndo(cur, pit, pit + 1);
                cur.finishUndo();
-               std::swap(pars_[pit], pars_[pit + 1]);
+               swap(pars_[pit], pars_[pit + 1]);
                updateLabels(cur.buffer());
                needsUpdate = true;
                ++cur.pit();
@@ -424,7 +423,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                pit_type const pit = cur.pit();
                recUndo(cur, pit - 1, pit);
                cur.finishUndo();
-               std::swap(pars_[pit], pars_[pit - 1]);
+               swap(pars_[pit], pars_[pit - 1]);
                updateLabels(cur.buffer());
                --cur.pit();
                needsUpdate = true;
@@ -487,6 +486,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                } else {
                        cur.undispatched();
                }
+               cur.updateFlags(Update::FitCursor);
                break;
 
        case LFUN_BUFFER_END:
@@ -497,6 +497,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                } else {
                        cur.undispatched();
                }
+               cur.updateFlags(Update::FitCursor);
                break;
 
        case LFUN_CHAR_FORWARD:
@@ -945,7 +946,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                is >> x >> y;
                if (!is)
                        lyxerr << "SETXY: Could not parse coordinates in '"
-                              << to_utf8(cmd.argument()) << std::endl;
+                              << to_utf8(cmd.argument()) << endl;
                else
                        tm.setCursorFromCoordinates(cur, x, y);
                break;
@@ -1028,8 +1029,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                if (cmd.argument().empty())
                        break;
                docstring hexstring = cmd.argument();
-               if (lyx::support::isHex(hexstring)) {
-                       char_type c = lyx::support::hexToInt(hexstring);
+               if (isHex(hexstring)) {
+                       char_type c = hexToInt(hexstring);
                        if (c >= 32 && c < 0x10ffff) {
                                lyxerr << "Inserting c: " << c << endl;
                                docstring s = docstring(1, c);
@@ -1155,7 +1156,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                CursorSlice old = bvcur.top();
 
                int const wh = bv->workHeight();
-               int const y = std::max(0, std::min(wh - 1, cmd.y));
+               int const y = max(0, min(wh - 1, cmd.y));
 
                tm.setCursorFromCoordinates(cur, cmd.x, y);
                cur.setTargetX(cmd.x);
@@ -1280,6 +1281,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        docstring ds = cur.selectionAsString(false);
                        cutSelection(cur, true, false);
                        static_cast<InsetInfo *>(inset)->setInfo(to_utf8(ds));
+                       static_cast<InsetInfo *>(inset)->updateInfo(cur.bv().buffer());
                }
                insertInset(cur, inset);
                cur.posForward();
@@ -1433,8 +1435,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        string const s1 = token(s, ' ', 1);
                        int const nargs = s1.empty() ? 0 : convert<int>(s1);
                        string const s2 = token(s, ' ', 2);
-                       string const type = s2.empty() ? "newcommand" : s2;
-                       cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, from_utf8(type)));
+                       MacroType type = MacroTypeNewcommand;
+                       if (s2 == "def")
+                               type = MacroTypeDef;
+                       cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type));
                        //cur.nextInset()->edit(cur, true);
                }
                break;
@@ -1451,12 +1455,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MATH_MATRIX:
        case LFUN_MATH_DELIM:
        case LFUN_MATH_BIGDELIM: {
-               if (cur.selection())
-                       cur.clearSelection();
-               // FIXME: instead of the above, this one
-               // should be used (but it asserts with Bidi enabled)
-               // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
-               // cap::replaceSelection(cur);
+               cap::replaceSelection(cur);
                cur.insert(new InsetMathHull(hullSimple));
                checkAndActivateInset(cur, true);
                BOOST_ASSERT(cur.inMathed());