From 616955adb284949c1a9c4a3cd51e5d0d0c488237 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 23 Oct 2001 13:48:52 +0000 Subject: [PATCH] fix crash due to invalid cursor position after deleting more than one cell git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2925 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formula.C | 49 +++++++++++++++++++++++++++++++++++++++- src/mathed/math_cursor.C | 16 +++++++++++++ src/mathed/math_cursor.h | 2 ++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 67f37cd7bd..492b3d355a 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -315,7 +315,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, return result; } - +#if 0 void InsetFormula::handleExtern(const string & arg) { // where are we? @@ -357,7 +357,54 @@ void InsetFormula::handleExtern(const string & arg) mathed_parse_cell(ar, is); mathcursor->end(); } +#endif + +void InsetFormula::handleExtern(const string & arg) +{ + // where are we? + if (!mathcursor) + return; + + MathArray ar; + if (mathcursor->selection()) + mathcursor->selGet(ar); + else + ar = mathcursor->cursor().cell(); + + // parse args + string lang; + string extra; + istringstream iss(arg.c_str()); + iss >> lang >> extra; + if (extra.empty()) + extra = "noextra"; + + // strip last '=' and everything behind + stripFromLastEqualSign(ar); + // create normalized expression + //string outfile = lyx::tempName("maple.out"); + string outfile = "/tmp/lyx2" + lang + ".out"; + ostringstream os; + os << "[" << extra << ' '; + ar.writeNormal(os); + os << "]"; + string code = os.str().c_str(); + + // run external sript + string script = "lyx2" + arg + " '" + code + "' " + outfile; + lyxerr << "calling: " << script << endl; + Systemcalls cmd(Systemcalls::System, script, 0); + + // append a '=' + //ar.push_back(MathAtom(new MathCharInset('='))); + + // append result + MathArray br; + ifstream is(outfile.c_str()); + mathed_parse_cell(br, is); + mathcursor->insert(br); +} bool InsetFormula::display() const { diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index c7fa2cf3e5..019e9fb140 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -557,6 +557,9 @@ void MathCursor::delLine() if (par()->nrows() > 1) par()->delRow(row()); + + if (pos() > size()) + pos() = size(); } @@ -699,6 +702,7 @@ void MathCursor::selDel() seldump("selDel"); if (selection_) { theSelection.erase(*this); + pos() = 0; selClear(); } } @@ -743,6 +747,18 @@ void MathCursor::selClear() } +void MathCursor::selGet(MathArray & ar) +{ + seldump("selGet"); + if (selection_) + return; + + theSelection.grab(*this); + ar = theSelection.glue(); +} + + + void MathCursor::drawSelection(Painter & pain) const { if (!selection_) diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 93b7fc0297..7332398c65 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -165,6 +165,8 @@ public: /// void selClear(); /// + void selGet(MathArray & ar); + /// void drawSelection(Painter & pain) const; /// void handleFont(MathTextCodes t); -- 2.39.5