Skip to content

Commit 72a3d61

Browse files
committed
panel: make Up/Down cycle through matches during quick search
Currently, pressing Up/Down during an active quick search exits the search and moves the cursor normally. This is unexpected — users coming from Total Commander or Double Commander expect arrows to jump to the next/previous file matching the search pattern. When quick search is active, Up/Down now cycle through matching files with wrap-around. All other keys (Left, Right, Enter, Esc) still exit the search as before. Also document the new behavior in the man page and NEWS. Signed-off-by: Ilia Karpov <iakarpov@edu.hse.ru> Signed-off-by: ki <karpovilia@gmail.com>
1 parent 1796996 commit 72a3d61

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

doc/NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Starting with this release, we will be using language features that require a C9
44

55
- Core
66

7+
* Quick search: Up/Down arrow keys now cycle through matching files instead of exiting the search
78
* Minimal version of Automake is 1.14 (#4604)
89
* Upgrade C standard to C99 (#4604)
910
* Support ksh variants as subshell (#3748)

doc/man/mc.1.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,13 @@ or
565565
keys can be used to correct typing mistakes. If C\-s is pressed
566566
again, the next match is searched for.
567567
.P
568+
The
569+
.I Up
570+
and
571+
.I Down
572+
arrow keys can be used to cycle through files matching the current
573+
search pattern, wrapping around at the beginning or end of the list.
574+
.P
568575
If quick search is started with double pressing of C\-s, the previous quick
569576
search pattern will be used for current search.
570577
.P

src/filemanager/panel.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,6 +3530,79 @@ panel_execute_cmd (WPanel *panel, long command)
35303530
{
35313531
int res = MSG_HANDLED;
35323532

3533+
/* When quick search is active, Up/Down cycle through matches instead of exiting search */
3534+
if (panel->quick_search.active && (command == CK_Up || command == CK_Down))
3535+
{
3536+
int i, start, direction, found = -1;
3537+
gboolean wrapped = FALSE;
3538+
char *reg_exp, *esc_str;
3539+
mc_search_t *search;
3540+
3541+
if (panel->quick_search.buffer->len == 0)
3542+
goto normal_cmd;
3543+
3544+
direction = (command == CK_Down) ? 1 : -1;
3545+
start = panel->current + direction;
3546+
3547+
reg_exp = g_strdup_printf ("%s*", panel->quick_search.buffer->str);
3548+
esc_str = str_escape (reg_exp, -1, ",|\\{}[]", TRUE);
3549+
search = mc_search_new (esc_str, NULL);
3550+
search->search_type = MC_SEARCH_T_GLOB;
3551+
search->is_entire_line = TRUE;
3552+
3553+
switch (panels_options.qsearch_mode)
3554+
{
3555+
case QSEARCH_CASE_SENSITIVE:
3556+
search->is_case_sensitive = TRUE;
3557+
break;
3558+
case QSEARCH_CASE_INSENSITIVE:
3559+
search->is_case_sensitive = FALSE;
3560+
break;
3561+
default:
3562+
search->is_case_sensitive = panel->sort_info.case_sensitive;
3563+
break;
3564+
}
3565+
3566+
for (i = start; !wrapped || i != start; i += direction)
3567+
{
3568+
if (i >= panel->dir.len)
3569+
{
3570+
i = 0;
3571+
if (wrapped)
3572+
break;
3573+
wrapped = TRUE;
3574+
}
3575+
if (i < 0)
3576+
{
3577+
i = panel->dir.len - 1;
3578+
if (wrapped)
3579+
break;
3580+
wrapped = TRUE;
3581+
}
3582+
if (mc_search_run (search, panel->dir.list[i].fname->str, 0,
3583+
panel->dir.list[i].fname->len, NULL))
3584+
{
3585+
found = i;
3586+
break;
3587+
}
3588+
}
3589+
3590+
mc_search_free (search);
3591+
g_free (reg_exp);
3592+
g_free (esc_str);
3593+
3594+
if (found >= 0)
3595+
{
3596+
unselect_item (panel);
3597+
panel->current = found;
3598+
select_item (panel);
3599+
widget_draw (WIDGET (panel));
3600+
}
3601+
3602+
return MSG_HANDLED;
3603+
}
3604+
3605+
normal_cmd:
35333606
if (command != CK_Search)
35343607
stop_search (panel);
35353608

0 commit comments

Comments
 (0)