commit b16b1ddb58bab10f62837162bde5de3a50d4b71a
Author: Enrico Forestieri <for...@lyx.org>
Date:   Mon Nov 10 00:47:50 2014 +0100

    Fix CAS computation of a selected subformula.
    
    Invoking a computer algebra system program for computing a selected
    subformula has never worked (checked with all LyX versions back to 1.3)
    and, moreover, in the presence of a selection things go awry.
    This commit allows this computation by replacing the selected
    subformula with the result of the computation.

diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 9657475..20787e2 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -66,6 +66,7 @@ using namespace lyx::support;
 namespace lyx {
 
 using cap::grabAndEraseSelection;
+using cap::reduceSelectionToOneCell;
 
 namespace {
 
@@ -1316,14 +1317,14 @@ void InsetMathHull::doExtern(Cursor & cur, FuncRequest 
& func)
                extra = from_ascii("noextra");
        string const lang = to_ascii(dlang);
 
-       // FIXME: temporarily disabled
-       //if (cur.selection()) {
-       //      MathData ar;
-       //      selGet(cur.ar);
-       //      lyxerr << "use selection: " << ar << endl;
-       //      insert(pipeThroughExtern(lang, extra, ar));
-       //      return;
-       //}
+       // replace selection with result of computation
+       if (reduceSelectionToOneCell(cur)) {
+               MathData ar;
+               asArray(grabAndEraseSelection(cur), ar);
+               lyxerr << "use selection: " << ar << endl;
+               cur.insert(pipeThroughExtern(lang, extra, ar));
+               return;
+       }
 
        // only inline, display or eqnarray math is allowed
        if (getType() > hullEqnArray) {
@@ -1344,9 +1345,7 @@ void InsetMathHull::doExtern(Cursor & cur, FuncRequest & 
func)
        if (getType() == hullSimple) {
                size_type pos = cur.cell().find_last(eq);
                MathData ar;
-               if (cur.inMathed() && cur.selection()) {
-                       asArray(grabAndEraseSelection(cur), ar);
-               } else if (pos == cur.cell().size()) {
+               if (pos == cur.cell().size()) {
                        ar = cur.cell();
                        lyxerr << "use whole cell: " << ar << endl;
                } else {
diff --git a/status.21x b/status.21x
index 36f2469..16c763b 100644
--- a/status.21x
+++ b/status.21x
@@ -46,6 +46,8 @@ What's new
 
 - References no longer truncated in outliner (bug 9312).
 
+- Allow computing selected subformulas with computer algebra systems.
+
 
 * DOCUMENTATION AND LOCALIZATION
 

Reply via email to