ui: Do not insert an extra space before parentheses in equation

When hitting F F, we expect `'()'` and not `' ()'`.

Fixes: #1160

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2024-09-03 21:03:48 +02:00
parent 444bd8a3d1
commit fc3c46fbda
2 changed files with 8 additions and 7 deletions

View file

@ -716,7 +716,7 @@ void tests::keyboard_entry()
step("Separators with auto-spacing");
cstring seps2 = "{}()[]";
cstring seps2auto = "{ } ( ) []";
cstring seps2auto = "{ } () []";
test(CLEAR, seps2).editor(seps2auto);
step("Key repeat");
@ -743,13 +743,13 @@ void tests::keyboard_entry()
.test(KEY3).editor("'1=2+3'");
step("F key in equation inserts parentheses")
.test(MUL).editor("'1=2+3·'")
.test(F).editor("'1=2+3· ()'");
.test(F).editor("'1=2+3·()'");
step("Automatic insertion of parentheses after functions")
.test(D).editor("'1=2+3· (exp())'")
.test(KEY0).editor("'1=2+3· (exp(0))'");
.test(D).editor("'1=2+3·(exp())'")
.test(KEY0).editor("'1=2+3·(exp(0))'");
step("Space key in parentheses insert semi-colon")
.test(SPACE).editor("'1=2+3· (exp(0;))'")
.test(KEY7).editor("'1=2+3· (exp(0;7))'");
.test(SPACE).editor("'1=2+3·(exp(0;))'")
.test(KEY7).editor("'1=2+3·(exp(0;7))'");
step("STO key while entering equation (bug #390)")
.test(CLEAR, EXIT, KEY1, KEY2, F,

View file

@ -193,7 +193,8 @@ void user_interface::edit(unicode c, modes m, bool autoclose)
if (closing && autoclose)
{
byte *ed = rt.editor();
if (mode == PROGRAM || mode == DIRECT || is_algebraic(mode))
if (mode == PROGRAM || mode == DIRECT ||
(is_algebraic(mode) && c != '('))
if (savec > 0 && ed[savec] != ' ')
insert(savec, ' ');
size_t back = insert(cursor, closing);