-
-
Notifications
You must be signed in to change notification settings - Fork 19
User menu: select first item that matches the condition, not second #4725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I have cleaned up this PR to the best of my ability... |
On Tue, 24 Jun 2025 22:14:20 -0700 "Yury V. Zaytsev" ***@***.***> wrote:
@zyv requested your review on: MidnightCommander/mc#4725 User menu: select first item that matches the condition, not second.
In the patch, two variables are changed together in all three cases:
```
selected = menu_lines;
found_default = TRUE;
```
I think, only `selected` is enough: negative value for `found_default == FALSE` and zero or positive value for `found_default == TRUE`.
The following patch is working for me for the testcase in the starting post:
```
diff --git a/src/usermenu.c b/src/usermenu.c
index 81e1158f7..37c933f5a 100644
--- a/src/usermenu.c
+++ b/src/usermenu.c
@@ -986,7 +986,7 @@ user_menu_cmd (const Widget *edit_widget, const char *menu_file, int selected_en
int max_cols = 0;
int col = 0;
gboolean accept_entry = TRUE;
- int selected = 0;
+ int selected = -1;
gboolean old_patterns;
gboolean res = FALSE;
gboolean interactive = TRUE;
@@ -1063,7 +1063,7 @@ user_menu_cmd (const Widget *edit_widget, const char *menu_file, int selected_en
{
// Combined adding and default
p = test_line (edit_widget, p + 1, &accept_entry);
- if (selected == 0 && accept_entry)
+ if (selected < 0 && accept_entry)
selected = menu_lines;
}
else
@@ -1078,7 +1078,7 @@ user_menu_cmd (const Widget *edit_widget, const char *menu_file, int selected_en
{
// Combined adding and default
p = test_line (edit_widget, p + 1, &accept_entry);
- if (selected == 0 && accept_entry)
+ if (selected < 0 && accept_entry)
selected = menu_lines;
}
else
@@ -1087,7 +1087,7 @@ user_menu_cmd (const Widget *edit_widget, const char *menu_file, int selected_en
gboolean ok = TRUE;
p = test_line (edit_widget, p, &ok);
- if (selected == 0 && ok)
+ if (selected < 0 && ok)
selected = menu_lines;
}
break;
```
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aborodin, I guess this is better. I have updated the PR again.
@moose-kazan, could you please test and confirm that it works for you?
Yes. Patch from @aborodin solve this issue. |
/rebase |
…ondition, not second Signed-off-by: Andrew Borodin <[email protected]> Signed-off-by: Yury V. Zaytsev <[email protected]>
Thank you! |
Resolves: #4555 (I hope ;-))