Fix textstyle-update handling in mathed

The code was expecting that all properties were specified
in the argument and not only some. Simply do not process
those properties not specified in the argument.
This commit is contained in:
Enrico Forestieri 2024-06-09 13:04:22 +02:00
parent 64aad586f4
commit afb70c905b

View File

@ -518,176 +518,187 @@ void InsetMathNest::handleFont2(Cursor & cur, docstring const & arg)
DocIterator sel_end = cur.selectionEnd(); DocIterator sel_end = cur.selectionEnd();
bool multiple_cells = sel_begin.idx() != sel_end.idx(); bool multiple_cells = sel_begin.idx() != sel_end.idx();
Font font; Font font;
bool b;
font.fromString(to_utf8(arg), b);
docstring im; docstring im;
InsetMathFont const * f = asFontInset(); InsetMathFont const * f = asFontInset();
bool b;
switch(font.fontInfo().family()) { // Return if nothing has been set
case ROMAN_FAMILY: if (!font.fromString(to_utf8(arg), b))
if (!f || (f->name() != "textrm" && f->name() != "mathrm")) return;
im = currentMode() != MATH_MODE ? from_ascii("textrm")
: from_ascii("mathrm");
break;
case SANS_FAMILY:
if (!f || (f->name() != "textsf" && f->name() != "mathsf"))
im = currentMode() != MATH_MODE ? from_ascii("textsf")
: from_ascii("mathsf");
break;
case TYPEWRITER_FAMILY:
if (!f || (f->name() != "texttt" && f->name() != "mathtt"))
im = currentMode() != MATH_MODE ? from_ascii("texttt")
: from_ascii("mathtt");
break;
case SYMBOL_FAMILY:
case CMR_FAMILY:
case CMSY_FAMILY:
case CMM_FAMILY:
case CMEX_FAMILY:
case MSA_FAMILY:
case MSB_FAMILY:
case DS_FAMILY:
case EUFRAK_FAMILY:
case RSFS_FAMILY:
case STMARY_FAMILY:
case WASY_FAMILY:
case ESINT_FAMILY:
case INHERIT_FAMILY:
case IGNORE_FAMILY:
break;
}
if (!im.empty()) {
handleNest(cur, createInsetMath(im, cur.buffer()));
im.clear();
include_previous_change = true;
}
switch(font.fontInfo().series()) { if (support::contains(arg, from_ascii("family"))) {
case MEDIUM_SERIES: switch(font.fontInfo().family()) {
if (!f || (f->name() != "textmd" && f->name() != "mathrm")) case ROMAN_FAMILY:
im = currentMode() != MATH_MODE ? from_ascii("textmd") if (!f || (f->name() != "textrm" && f->name() != "mathrm"))
: from_ascii("mathrm"); im = currentMode() != MATH_MODE ? from_ascii("textrm")
break; : from_ascii("mathrm");
case BOLD_SERIES: break;
if (!f || (f->name() != "textbf" && f->name() != "mathbf")) case SANS_FAMILY:
im = currentMode() != MATH_MODE ? from_ascii("textbf") if (!f || (f->name() != "textsf" && f->name() != "mathsf"))
: from_ascii("boldsymbol"); im = currentMode() != MATH_MODE ? from_ascii("textsf")
break; : from_ascii("mathsf");
case INHERIT_SERIES: break;
case IGNORE_SERIES: case TYPEWRITER_FAMILY:
break; if (!f || (f->name() != "texttt" && f->name() != "mathtt"))
} im = currentMode() != MATH_MODE ? from_ascii("texttt")
if (!im.empty()) { : from_ascii("mathtt");
if (multiple_cells) { break;
cur.setCursor(sel_begin); case SYMBOL_FAMILY:
cur.idx() = 0; case CMR_FAMILY:
cur.pos() = 0; case CMSY_FAMILY:
cur.resetAnchor(); case CMM_FAMILY:
cur.setCursor(sel_end); case CMEX_FAMILY:
cur.pos() = cur.lastpos(); case MSA_FAMILY:
cur.setSelection(); case MSB_FAMILY:
} else if (include_previous_change && selection) { case DS_FAMILY:
cur.setSelection(); case EUFRAK_FAMILY:
case RSFS_FAMILY:
case STMARY_FAMILY:
case WASY_FAMILY:
case ESINT_FAMILY:
case INHERIT_FAMILY:
case IGNORE_FAMILY:
break;
}
if (!im.empty()) {
handleNest(cur, createInsetMath(im, cur.buffer()));
im.clear();
include_previous_change = true;
} }
handleNest(cur, createInsetMath(im, cur.buffer()));
im.clear();
include_previous_change = true;
} }
switch(font.fontInfo().shape()) { if (support::contains(arg, from_ascii("series"))) {
case UP_SHAPE: switch(font.fontInfo().series()) {
if (!f || (f->name() != "textup" && f->name() != "mathrm")) case MEDIUM_SERIES:
im = currentMode() != MATH_MODE ? from_ascii("textup") if (!f || (f->name() != "textmd" && f->name() != "mathrm"))
: from_ascii("mathrm"); im = currentMode() != MATH_MODE ? from_ascii("textmd")
break; : from_ascii("mathrm");
case ITALIC_SHAPE: break;
if (!f || (f->name() != "textit" && f->name() != "mathit")) case BOLD_SERIES:
im = currentMode() != MATH_MODE ? from_ascii("textit") if (!f || (f->name() != "textbf" && f->name() != "mathbf"))
: from_ascii("mathit"); im = currentMode() != MATH_MODE ? from_ascii("textbf")
break; : from_ascii("boldsymbol");
case SLANTED_SHAPE: break;
if (!f || f->name() != "textsl") case INHERIT_SERIES:
im = currentMode() != MATH_MODE ? from_ascii("textsl") case IGNORE_SERIES:
: docstring(); break;
break; }
case SMALLCAPS_SHAPE: if (!im.empty()) {
if (!f || f->name() != "textsc") if (multiple_cells) {
im = currentMode() != MATH_MODE ? from_ascii("textsc") cur.setCursor(sel_begin);
: docstring(); cur.idx() = 0;
break; cur.pos() = 0;
case INHERIT_SHAPE: cur.resetAnchor();
case IGNORE_SHAPE: cur.setCursor(sel_end);
break; cur.pos() = cur.lastpos();
} cur.setSelection();
if (!im.empty()) { } else if (include_previous_change && selection) {
if (multiple_cells) { cur.setSelection();
cur.setCursor(sel_begin); }
cur.idx() = 0; handleNest(cur, createInsetMath(im, cur.buffer()));
cur.pos() = 0; im.clear();
cur.resetAnchor(); include_previous_change = true;
cur.setCursor(sel_end);
cur.pos() = cur.lastpos();
cur.setSelection();
} else if (include_previous_change && selection) {
cur.setSelection();
} }
handleNest(cur, createInsetMath(im, cur.buffer()));
im.clear();
include_previous_change = true;
} }
switch(font.fontInfo().size()) { if (support::contains(arg, from_ascii("shape"))) {
case TINY_SIZE: switch(font.fontInfo().shape()) {
im = from_ascii("tiny"); case UP_SHAPE:
break; if (!f || (f->name() != "textup" && f->name() != "mathrm"))
case SCRIPT_SIZE: im = currentMode() != MATH_MODE ? from_ascii("textup")
im = from_ascii("scriptsize"); : from_ascii("mathrm");
break; break;
case FOOTNOTE_SIZE: case ITALIC_SHAPE:
im = from_ascii("footnotesize"); if (!f || (f->name() != "textit" && f->name() != "mathit"))
break; im = currentMode() != MATH_MODE ? from_ascii("textit")
case SMALL_SIZE: : from_ascii("mathit");
im = from_ascii("small"); break;
break; case SLANTED_SHAPE:
case NORMAL_SIZE: if (!f || f->name() != "textsl")
im = from_ascii("normalsize"); im = currentMode() != MATH_MODE ? from_ascii("textsl")
break; : docstring();
case LARGE_SIZE: break;
im = from_ascii("large"); case SMALLCAPS_SHAPE:
break; if (!f || f->name() != "textsc")
case LARGER_SIZE: im = currentMode() != MATH_MODE ? from_ascii("textsc")
im = from_ascii("Large"); : docstring();
break; break;
case LARGEST_SIZE: case INHERIT_SHAPE:
im = from_ascii("LARGE"); case IGNORE_SHAPE:
break; break;
case HUGE_SIZE: }
im = from_ascii("huge"); if (!im.empty()) {
break; if (multiple_cells) {
case HUGER_SIZE: cur.setCursor(sel_begin);
im = from_ascii("Huge"); cur.idx() = 0;
break; cur.pos() = 0;
case INCREASE_SIZE: cur.resetAnchor();
case DECREASE_SIZE: cur.setCursor(sel_end);
case INHERIT_SIZE: cur.pos() = cur.lastpos();
case IGNORE_SIZE: cur.setSelection();
break; } else if (include_previous_change && selection) {
} cur.setSelection();
if (!im.empty()) { }
if (multiple_cells) { handleNest(cur, createInsetMath(im, cur.buffer()));
cur.setCursor(sel_begin); im.clear();
cur.idx() = 0; include_previous_change = true;
cur.pos() = 0; }
cur.resetAnchor(); }
cur.setCursor(sel_end);
cur.pos() = cur.lastpos(); if (support::contains(arg, from_ascii("size"))) {
cur.setSelection(); switch(font.fontInfo().size()) {
} else if (include_previous_change && selection) { case TINY_SIZE:
cur.setSelection(); im = from_ascii("tiny");
break;
case SCRIPT_SIZE:
im = from_ascii("scriptsize");
break;
case FOOTNOTE_SIZE:
im = from_ascii("footnotesize");
break;
case SMALL_SIZE:
im = from_ascii("small");
break;
case NORMAL_SIZE:
im = from_ascii("normalsize");
break;
case LARGE_SIZE:
im = from_ascii("large");
break;
case LARGER_SIZE:
im = from_ascii("Large");
break;
case LARGEST_SIZE:
im = from_ascii("LARGE");
break;
case HUGE_SIZE:
im = from_ascii("huge");
break;
case HUGER_SIZE:
im = from_ascii("Huge");
break;
case INCREASE_SIZE:
case DECREASE_SIZE:
case INHERIT_SIZE:
case IGNORE_SIZE:
break;
}
if (!im.empty()) {
if (multiple_cells) {
cur.setCursor(sel_begin);
cur.idx() = 0;
cur.pos() = 0;
cur.resetAnchor();
cur.setCursor(sel_end);
cur.pos() = cur.lastpos();
cur.setSelection();
} else if (include_previous_change && selection) {
cur.setSelection();
}
handleNest(cur, createInsetMath(im, cur.buffer()));
im.clear();
include_previous_change = true;
} }
handleNest(cur, createInsetMath(im, cur.buffer()));
im.clear();
include_previous_change = true;
} }
InsetMathDecoration const * d = multiple_cells InsetMathDecoration const * d = multiple_cells
@ -765,21 +776,23 @@ void InsetMathNest::handleFont2(Cursor & cur, docstring const & arg)
include_previous_change = true; include_previous_change = true;
} }
if (font.fontInfo().color() != Color_inherit && if (support::contains(arg, from_ascii("color"))) {
font.fontInfo().color() != Color_ignore) { if (font.fontInfo().color() != Color_inherit &&
if (multiple_cells) { font.fontInfo().color() != Color_ignore) {
cur.setCursor(sel_begin); if (multiple_cells) {
cur.idx() = 0; cur.setCursor(sel_begin);
cur.pos() = 0; cur.idx() = 0;
cur.resetAnchor(); cur.pos() = 0;
cur.setCursor(sel_end); cur.resetAnchor();
cur.pos() = cur.lastpos(); cur.setCursor(sel_end);
cur.setSelection(); cur.pos() = cur.lastpos();
} else if (include_previous_change && selection) { cur.setSelection();
cur.setSelection(); } else if (include_previous_change && selection) {
cur.setSelection();
}
handleNest(cur, MathAtom(new InsetMathColor(buffer_, true, font.fontInfo().color())));
include_previous_change = true;
} }
handleNest(cur, MathAtom(new InsetMathColor(buffer_, true, font.fontInfo().color())));
include_previous_change = true;
} }
if (selection) { if (selection) {