Skip to content

Commit

Permalink
ui: Directly execute VariablesMenu entries in direct mode
Browse files Browse the repository at this point in the history
When text editing is in direct mode (e.g. outside of a program),
directly execute the entries in the variable menu instead of appending
them to the command line

Also fixed an issue where the editor would not jump to the cursor
position when inserting a variable command.

Fixes: #420

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
  • Loading branch information
c3d committed Oct 19, 2023
1 parent 4dce487 commit ef3250a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/user_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct user_interface
int menu_screen_bottom() { return menuHeight; }
bool showingHelp() { return help + 1 != 0; }
uint cursorPosition() { return cursor; }
void cursorPosition(uint pos){ cursor = pos; dirtyEditor = true; }
void cursorPosition(uint pos){ cursor = pos; dirtyEditor = true; edRows = 0; }
void autoCompleteMenu() { autoComplete = true; }
bool currentWord(size_t &start, size_t &size);
bool currentWord(utf8 &start, size_t &size);
Expand Down
21 changes: 18 additions & 3 deletions src/variables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,12 @@ COMMAND_BODY(VariablesMenuExecute)
{
int key = ui.evaluating;
if (rt.editing())
return insert_cmd(key, "", " ");
{
if (ui.editing_mode() != ui.DIRECT)
return insert_cmd(key, "", " ");
if (!ui.end_edit())
return object::ERROR;
}

if (key >= KEY_F1 && key <= KEY_F6)
{
Expand Down Expand Up @@ -933,7 +938,12 @@ COMMAND_BODY(VariablesMenuRecall)
{
int key = ui.evaluating;
if (rt.editing())
return insert_cmd(key, "'", "' Recall ");
{
if (ui.editing_mode() != ui.DIRECT)
return insert_cmd(key, "'", "' Recall ");
if (!ui.end_edit())
return object::ERROR;
}

if (key >= KEY_F1 && key <= KEY_F6)
if (symbol_p name = ui.label(key - KEY_F1))
Expand All @@ -953,7 +963,12 @@ COMMAND_BODY(VariablesMenuStore)
{
int key = ui.evaluating;
if (rt.editing())
return insert_cmd(key, "'", "' Store ");
{
if (ui.editing_mode() != ui.DIRECT)
return insert_cmd(key, "'", "' Store ");
if (!ui.end_edit())
return object::ERROR;
}

if (key >= KEY_F1 && key <= KEY_F6)
if (symbol_p name = ui.label(key - KEY_F1))
Expand Down

0 comments on commit ef3250a

Please sign in to comment.