[Script] Fix keep-selection add keep-filter

Fixes: #1962
This commit is contained in:
Qball Cow 2024-05-12 21:35:26 +02:00
parent 9580c4a191
commit dee97eb540
2 changed files with 16 additions and 4 deletions

View file

@ -109,6 +109,8 @@ The following extra options exists:
- **keep-selection**: If set, the selection is not moved to the first entry, - **keep-selection**: If set, the selection is not moved to the first entry,
but the current position is maintained. The filter is cleared. but the current position is maintained. The filter is cleared.
- **keep-filter**: If set, the filter is not cleared.
- **new-selection**: If `keep-selection` is set, this allows you to override - **new-selection**: If `keep-selection` is set, this allows you to override
the selected entry (absolute position). the selected entry (absolute position).

View file

@ -72,6 +72,8 @@ typedef struct {
char delim; char delim;
/** no custom */ /** no custom */
gboolean no_custom; gboolean no_custom;
/** keep filter */
gboolean keep_filter;
gboolean use_hot_keys; gboolean use_hot_keys;
} ScriptModePrivateData; } ScriptModePrivateData;
@ -157,6 +159,8 @@ static void parse_header_entry(Mode *sw, char *line, ssize_t length) {
pd->use_hot_keys = (strcasecmp(value, "true") == 0); pd->use_hot_keys = (strcasecmp(value, "true") == 0);
} else if (strcasecmp(line, "keep-selection") == 0) { } else if (strcasecmp(line, "keep-selection") == 0) {
pd->keep_selection = (strcasecmp(value, "true") == 0); pd->keep_selection = (strcasecmp(value, "true") == 0);
} else if (strcasecmp(line, "keep-filter") == 0) {
pd->keep_filter = (strcasecmp(value, "true") == 0);
} else if (strcasecmp(line, "new-selection") == 0) { } else if (strcasecmp(line, "new-selection") == 0) {
pd->new_selection = (int64_t)g_ascii_strtoll(value, NULL, 0); pd->new_selection = (int64_t)g_ascii_strtoll(value, NULL, 0);
} else if (strcasecmp(line, "data") == 0) { } else if (strcasecmp(line, "data") == 0) {
@ -184,6 +188,7 @@ static DmenuScriptEntry *execute_executor(Mode *sw, char *arg,
// Reset these between runs. // Reset these between runs.
pd->new_selection = -1; pd->new_selection = -1;
pd->keep_selection = 0; pd->keep_selection = 0;
pd->keep_filter = 0;
// Environment // Environment
char **env = g_get_environ(); char **env = g_get_environ();
@ -320,6 +325,9 @@ static ModeMode script_mode_result(Mode *sw, int mretv, char **input,
ModeMode retv = MODE_EXIT; ModeMode retv = MODE_EXIT;
DmenuScriptEntry *new_list = NULL; DmenuScriptEntry *new_list = NULL;
unsigned int new_length = 0; unsigned int new_length = 0;
// store them as they might be different on next executor and reset.
gboolean keep_filter = rmpd->keep_filter;
gboolean keep_selection = rmpd->keep_selection;
if ((mretv & MENU_CUSTOM_COMMAND)) { if ((mretv & MENU_CUSTOM_COMMAND)) {
if (rmpd->use_hot_keys) { if (rmpd->use_hot_keys) {
@ -370,7 +378,7 @@ static ModeMode script_mode_result(Mode *sw, int mretv, char **input,
rmpd->cmd_list = new_list; rmpd->cmd_list = new_list;
rmpd->cmd_list_length = new_length; rmpd->cmd_list_length = new_length;
if (rmpd->keep_selection) { if (keep_selection) {
if (rmpd->new_selection >= 0 && if (rmpd->new_selection >= 0 &&
rmpd->new_selection < rmpd->cmd_list_length) { rmpd->new_selection < rmpd->cmd_list_length) {
rofi_view_set_selected_line(rofi_view_get_active(), rofi_view_set_selected_line(rofi_view_get_active(),
@ -378,12 +386,14 @@ static ModeMode script_mode_result(Mode *sw, int mretv, char **input,
} else { } else {
rofi_view_set_selected_line(rofi_view_get_active(), selected_line); rofi_view_set_selected_line(rofi_view_get_active(), selected_line);
} }
} else {
rofi_view_set_selected_line(rofi_view_get_active(), 0);
}
if (keep_filter == FALSE) {
g_free(*input); g_free(*input);
*input = NULL; *input = NULL;
retv = RELOAD_DIALOG;
} else {
retv = RESET_DIALOG;
} }
retv = RELOAD_DIALOG;
} }
return retv; return retv;
} }