Skip to content

Commit c6b090f

Browse files
committed
panel: improve quick search keyboard handling
- Up/Down arrow keys now cycle through matching files instead of exiting the search, with wrap-around. - When quick search is NOT active, Space marks the current file and Backspace navigates to the parent directory. - When quick search IS active, Space and Backspace are passed to the search input (space as a character, backspace to delete). - Quick search is no longer started by Space or Backspace when command_prompt is disabled. 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 c6b090f

3 files changed

Lines changed: 103 additions & 1 deletion

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: 95 additions & 1 deletion
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

@@ -3732,6 +3805,27 @@ panel_key (WPanel *panel, int key)
37323805
return MSG_HANDLED;
37333806
}
37343807

3808+
/* When quick search is NOT active: Space = mark file, Backspace = parent dir.
3809+
When quick search IS active: Space and Backspace go to the search input. */
3810+
if (!panel->quick_search.active)
3811+
{
3812+
if (key == ' ')
3813+
{
3814+
const file_entry_t *fe;
3815+
3816+
fe = panel_current_entry (panel);
3817+
if (fe != NULL)
3818+
do_file_mark (panel, panel->current, fe->f.marked ? 0 : 1);
3819+
widget_draw (WIDGET (panel));
3820+
return MSG_HANDLED;
3821+
}
3822+
if (key == KEY_BACKSPACE)
3823+
{
3824+
goto_parent_dir (panel);
3825+
return MSG_HANDLED;
3826+
}
3827+
}
3828+
37353829
if (panel->quick_search.active && ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE))
37363830
{
37373831
do_search (panel, key);
@@ -3742,7 +3836,7 @@ panel_key (WPanel *panel, int key)
37423836
if (command != CK_IgnoreKey)
37433837
return panel_execute_cmd (panel, command);
37443838

3745-
if (!command_prompt && ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE))
3839+
if (!command_prompt && key > ' ' && key <= 255)
37463840
{
37473841
start_search (panel);
37483842
do_search (panel, key);

0 commit comments

Comments
 (0)