Dear list This has been annoying me for a while. OK to push?
Sincerely Guillaume
>From 4a13412d56ff1c528e7a0bf39b64910f5042e058 Mon Sep 17 00:00:00 2001 From: Guillaume Munch <g...@lyx.org> Date: Sun, 13 Dec 2015 03:32:32 +0000 Subject: [PATCH] Display the correct horizontal alignment in AMS environments --- src/mathed/InsetMath.h | 10 ++++++---- src/mathed/InsetMathGrid.cpp | 23 +++++++++++++++++++++++ src/mathed/InsetMathGrid.h | 5 +++-- src/mathed/InsetMathHull.cpp | 28 ++++++++++++++++------------ src/mathed/InsetMathSplit.cpp | 36 ++++++++++++++++++++++++++++++------ src/mathed/InsetMathSplit.h | 2 ++ 6 files changed, 80 insertions(+), 24 deletions(-) diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h index bd72863..6e152f1 100644 --- a/src/mathed/InsetMath.h +++ b/src/mathed/InsetMath.h @@ -27,14 +27,16 @@ enum HullType { hullSimple, hullEquation, hullEqnArray, + hullMultline, + hullGather, + hullRegexp, + // FIXME: InsetMathHull tests for ">= hullAlign". So currently, aligns + // should remain last. Anything to add must go above. hullAlign, hullAlignAt, hullXAlignAt, hullXXAlignAt, - hullFlAlign, - hullMultline, - hullGather, - hullRegexp + hullFlAlign }; HullType hullType(docstring const & name); diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 8ea3940..5c346ee 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -1837,4 +1837,27 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd, } +// static +char InsetMathGrid::colAlign(HullType type, col_type col) +{ + switch (type) { + case hullMultline: + case hullGather: + return 'c'; + case hullEqnArray: + return "rcl"[col]; + case hullAlign: + case hullAlignAt: + case hullXAlignAt: + case hullXXAlignAt: + case hullFlAlign: + return "rl"[col & 1]; + default: + break; + } + return 'c'; +} + + + } // namespace lyx diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index bd3066d..709f492 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -258,10 +258,11 @@ protected: virtual docstring eocString(col_type col, col_type lastcol) const; /// splits cells and shifts right part to the next cell void splitCell(Cursor & cur); - /// Column aligmment for display of cell \p idx. + /// Column alignment for display of cell \p idx. /// Must not be written to file! virtual char displayColAlign(idx_type idx) const; - + /// The value of a fixed col align for a certain hull type + static char colAlign(HullType type, col_type col); /// row info. /// rowinfo_[nrows()] is a dummy row used only for hlines. diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 097a344..dcc6a17 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -351,26 +351,31 @@ bool InsetMathHull::idxLast(Cursor & cur) const char InsetMathHull::defaultColAlign(col_type col) { - if (type_ == hullEqnArray) - return "rcl"[col]; - if (type_ == hullMultline) - return 'c'; - if (type_ == hullGather) - return 'c'; - if (type_ >= hullAlign) - return "rl"[col & 1]; - return 'c'; + colAlign(type_, col); } char InsetMathHull::displayColAlign(idx_type idx) const { - if (type_ == hullMultline) { + switch (type_) { + case hullMultline: { row_type const r = row(idx); if (r == 0) return 'l'; if (r == nrows() - 1) return 'r'; + return 'c'; + } + case hullEqnArray: + case hullGather: + case hullAlign: + case hullAlignAt: + case hullXAlignAt: + case hullXXAlignAt: + case hullFlAlign: + return colAlign(type_, col(idx)); + default: + break; } return InsetMathGrid::displayColAlign(idx); } @@ -1870,10 +1875,9 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd, } default: - return InsetMathGrid::getStatus(cur, cmd, status); + break; } - // This cannot really happen, but inserted to shut-up gcc return InsetMathGrid::getStatus(cur, cmd, status); } diff --git a/src/mathed/InsetMathSplit.cpp b/src/mathed/InsetMathSplit.cpp index 5c425fb..3ffe757 100644 --- a/src/mathed/InsetMathSplit.cpp +++ b/src/mathed/InsetMathSplit.cpp @@ -50,18 +50,38 @@ Inset * InsetMathSplit::clone() const char InsetMathSplit::defaultColAlign(col_type col) { - if (name_ == "split") - return 'l'; if (name_ == "gathered") return 'c'; - if (name_ == "aligned" || name_ == "align") - return (col & 1) ? 'l' : 'r'; - if (name_ == "alignedat") - return (col & 1) ? 'l' : 'r'; + if (name_ == "lgathered") + return 'l'; + if (name_ == "rgathered") + return 'r'; + if (name_ == "split" + || name_ == "aligned" + || name_ == "align" + || name_ == "alignat") + return colAlign(hullAlign, col); return 'l'; } +char InsetMathSplit::displayColAlign(idx_type idx) const +{ + if (name_ == "gathered") + return 'c'; + if (name_ == "lgathered") + return 'l'; + if (name_ == "rgathered") + return 'r'; + if (name_ == "split" + || name_ == "aligned" + || name_ == "align" + || name_ == "alignat") + return colAlign(hullAlign, col(idx)); + return InsetMathGrid::displayColAlign(idx); +} + + void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const { InsetMathGrid::draw(pi, x, y); @@ -86,6 +106,10 @@ bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd, flag.setEnabled(false); return true; } + if (s == "align-left" || s == "align-center" || s == "align-right") { + flag.setEnabled(false); + return true; + } break; } default: diff --git a/src/mathed/InsetMathSplit.h b/src/mathed/InsetMathSplit.h index b0ff437..1b2aa23 100644 --- a/src/mathed/InsetMathSplit.h +++ b/src/mathed/InsetMathSplit.h @@ -43,6 +43,8 @@ public: /// char defaultColAlign(col_type); /// + char displayColAlign(idx_type idx) const; + /// InsetCode lyxCode() const { return MATH_SPLIT_CODE; } private: -- 2.1.4