menus: Do not execute if-then-else and similar

Commands like `if then else` should not evaluate from the menu, but
always insert in the text editor.

Fixes: #1014
Fixes: #1015

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2024-07-11 00:19:07 +02:00
parent 189694f6e5
commit d2cccb096c
3 changed files with 25 additions and 4 deletions

View file

@ -131,6 +131,7 @@ ID_RANGE(is_unit, unit, unit)
ID_RANGE(is_plot, Function, Parametric)
ID_RANGE(is_program, program, funcall)
ID_RANGE(is_graph, grob, bitmap)
ID_RANGE(is_forced_entry, IfThen, CaseWhen, IfErrThen, IfErrThenElse)

View file

@ -162,7 +162,7 @@ void tests::run(bool onlyCurrent)
if (onlyCurrent)
{
here().begin("Current");
complex_arithmetic();
editor_operations();
}
else
{
@ -804,7 +804,20 @@ void tests::editor_operations()
.test(DOWN)
.editor("'x and y'")
.test(ENTER);
}
step("Insert if-then from menu")
.test(CLEAR, LSHIFT, KEY3, LSHIFT, F2, LSHIFT, F1)
.editor("if then end ");
step("Insert if-then-else from menu")
.test(CLEAR, LSHIFT, KEY3, LSHIFT, F2, LSHIFT, F2)
.editor("if then else end ");
step("Insert iferr-then from menu")
.test(CLEAR, LSHIFT, KEY3, LSHIFT, F2, LSHIFT, F3)
.editor("iferr then end ");
step("Insert iferr-then-else from menu")
.test(CLEAR, LSHIFT, KEY3, LSHIFT, F2, LSHIFT, F4)
.editor("iferr then else end ");
}
void tests::stack_operations()

View file

@ -4453,9 +4453,16 @@ bool user_interface::handle_functions(int key)
"Handle function for key %d (plane %d) ", key, shift_plane());
if (object_p obj = object_for_key(key))
{
save<int> saveEvaluating(evaluating, key);
save<int> saveEvaluating(evaluating, key);
object::id ty = obj->type();
bool imm = object::is_immediate(ty);
if (object::is_forced_entry(ty))
{
dirtyEditor = true;
edRows = 0;
return obj->insert() != object::ERROR;
}
bool imm = object::is_immediate(ty);
bool editing = rt.editing();
if (editing && !imm)
{