Skip to content

Commit

Permalink
arithmetic: Add space around mod and rem in rendering
Browse files Browse the repository at this point in the history
Add spaces around `mod` and `rem` during rendering.

Fixes: #906

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
  • Loading branch information
c3d committed Apr 16, 2024
1 parent f36718f commit b404edd
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
Binary file modified color-images/expression.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified color-images/reduced.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified color-images/two-levels.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/expression.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/reduced.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/two-levels.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 13 additions & 6 deletions src/expression.cc
Expand Up @@ -160,13 +160,19 @@ symbol_p expression::render(uint depth, int &precedence, bool editing)
break;
case 2:
{
int lprec = 0, rprec = 0;
symbol_g op = obj->as_symbol(editing);
int lprec = 0, rprec = 0;
symbol_g op = obj->as_symbol(editing);
symbol_g rtxt = render(depth, rprec, editing);
symbol_g ltxt = render(depth, lprec, editing);
int prec = obj->precedence();
int prec = obj->precedence();
if (prec != precedence::FUNCTION)
{
id oid = obj->type();
if (oid == ID_mod || oid == ID_rem)
{
op = symbol::make(' ') + op;
op = op + symbol::make(' ');
}
if (lprec < prec)
ltxt = parentheses(ltxt);
if (rprec <= prec)
Expand Down Expand Up @@ -1879,9 +1885,10 @@ grob_p expression::graph(grapher &g, uint depth, int &precedence)
{
if (lprec < prec)
lg = parentheses(g, lg);
if (rprec < prec ||
(rprec == prec && (oid == ID_sub || oid == ID_div)))
rg = parentheses(g, rg);
if (oid != ID_pow)
if (rprec < prec ||
(rprec == prec && (oid == ID_sub || oid == ID_div)))
rg = parentheses(g, rg);
}
precedence = prec;
switch (oid)
Expand Down
8 changes: 7 additions & 1 deletion src/tests.cc
Expand Up @@ -158,7 +158,7 @@ void tests::run(bool onlyCurrent)
if (onlyCurrent)
{
here().begin("Current");
sorting_functions();
regression_checks();
}
else
{
Expand Down Expand Up @@ -6930,6 +6930,12 @@ void tests::regression_checks()
.test("1968.1205", F6).expect("1 968 ²⁴¹/₂ ₀₀₀")
.test("1968.0512", F6).expect("1 968 ³²/₆₂₅")
.test(LSHIFT, N, RSHIFT, F4); // Reset modes

step("Bug 906: mod and rem should have spaces during editing")
.test(CLEAR, "X Y mod", ENTER).expect("'X mod Y'")
.test(NOSHIFT, DOWN, ENTER).expect("'X mod Y'")
.test(CLEAR, "X Y rem", ENTER).expect("'X rem Y'")
.test(NOSHIFT, DOWN, ENTER).expect("'X rem Y'");
}


Expand Down

0 comments on commit b404edd

Please sign in to comment.