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 15, 2024
1 parent f36718f commit 12430e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 9 additions & 3 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
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 12430e4

Please sign in to comment.