Le 03/04/2025 à 23:26, Jean-Marc Lasgouttes a écrit :
commit 016bb5b23ccce06128d878139a625a75557afca5
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Thu Apr 3 23:16:21 2025 +0200

     Improve breaking of equation with C-Return
This does two different changes: 1/ when the equation is not of grid type, newline-insert will preserve
        cursor position when mutating the equation to align or eqnarray.
2/ when the equation is already of grid type, the cursor will be
        adjusted to go to the newly-created row.
Related to bug #11515, but does not fix it.

I would be interested to know whether breaking equations feels better with this change.

Something I did initially but did not keep is to only mutate to eqnarray/align on first C-Enter, and insert a new row only if the equation is already a grid.

Tell me if you would prefer that, or something else.

JMarc

---
  src/mathed/InsetMathGrid.cpp | 16 ++++++++--------
  src/mathed/InsetMathHull.cpp | 12 ++++++++++--
  2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index f3e4aff269..f48d1eeeb9 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -1425,23 +1425,23 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest 
& cmd)
case LFUN_NEWLINE_INSERT: {
                cur.recordUndoInset();
-               row_type const r = cur.row();
-               addRow(r);
+               row_type const oldr = cur.row();
+               col_type const oldc = cur.col();
+               addRow(oldr);
// split line
                for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
-                       swap(cell(index(r, c)), cell(index(r + 1, c)));
+                       swap(cell(index(oldr, c)), cell(index(oldr + 1, c)));
// split cell
                splitCell(cur);
                if (ncols() > 1)
                        swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
-               if (cur.idx() > 0)
-                       --cur.idx();
-               cur.pos() = cur.lastpos();
+
+               // move cursor to next line
+               cur.idx() = index(oldr + 1, oldc);
+               cur.pos() = 0;
                cur.forceBufferUpdate();
-               //mathcursor->normalize();
-               //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
                break;
        }
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 5b1d0e57c5..04d48151f8 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -1893,8 +1893,16 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest 
& cmd)
                        mutate(align ? hullAlign : hullEqnArray);
                        // mutate() may change labels and such.
                        cur.forceBufferUpdate();
-                       cur.idx() = nrows() * ncols() - 1;
-                       cur.pos() = cur.lastpos();
+                       size_t p = cur.pos();
+                       for (idx_type idx = 0 ; idx < nargs() ; ++idx) {
+                               if (cell(idx).size() < p)
+                                       p -= cell(idx).size();
+                               else {
+                                       cur.idx() = idx;
+                                       cur.pos() = p;
+                                       break;
+                               }
+                       }
                }
                InsetMathGrid::doDispatch(cur, cmd);
                break;

--
lyx-devel mailing list
lyx-devel@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to