Skip to content

Commit b56af9e

Browse files
committed
panel: add SearchNext/SearchPrev actions for quick search
Add two new panel actions CK_SearchNext and CK_SearchPrev that cycle through files matching the current quick search pattern, with wrap-around. These are only active while quick search is running. By default, SearchNext is bound to Ctrl+S (same key that starts the search), and SearchPrev has no default binding. Both can be customized in the [Panel] section of the keymap file. This approach follows the existing mc convention of using symbolic action names bound through keymap files, rather than hardcoding keys. Signed-off-by: Ilia Karpov <iakarpov@edu.hse.ru> Signed-off-by: ki <karpovilia@gmail.com>
1 parent 1796996 commit b56af9e

5 files changed

Lines changed: 89 additions & 1 deletion

File tree

doc/man/mc.1.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,18 @@ 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 SearchNext
570+
and
571+
.I SearchPrev
572+
panel actions can be used to cycle through files matching the current
573+
search pattern, wrapping around at the beginning or end of the list.
574+
By default,
575+
.I SearchNext
576+
is bound to C\-s (same as repeating the search).
577+
.I SearchPrev
578+
has no default binding but can be configured in the keymap file.
579+
.P
568580
If quick search is started with double pressing of C\-s, the previous quick
569581
search pattern will be used for current search.
570582
.P

lib/keybind.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ static name_keymap_t command_names[] = {
9898
ADD_KEYMAP_NAME (EditUserMenu),
9999
ADD_KEYMAP_NAME (Search),
100100
ADD_KEYMAP_NAME (SearchContinue),
101+
ADD_KEYMAP_NAME (SearchNext),
102+
ADD_KEYMAP_NAME (SearchPrev),
101103
ADD_KEYMAP_NAME (Replace),
102104
ADD_KEYMAP_NAME (ReplaceContinue),
103105
ADD_KEYMAP_NAME (Help),

lib/keybind.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ enum
8080
CK_Replace,
8181
CK_ReplaceContinue,
8282
CK_SearchStop,
83+
CK_SearchNext,
84+
CK_SearchPrev,
8385
CK_Help,
8486
CK_Edit,
8587
CK_EditNew,

src/filemanager/panel.c

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3530,11 +3530,81 @@ panel_execute_cmd (WPanel *panel, long command)
35303530
{
35313531
int res = MSG_HANDLED;
35323532

3533-
if (command != CK_Search)
3533+
if (command != CK_Search && command != CK_SearchNext && command != CK_SearchPrev)
35343534
stop_search (panel);
35353535

35363536
switch (command)
35373537
{
3538+
case CK_SearchNext:
3539+
case CK_SearchPrev:
3540+
if (panel->quick_search.active)
3541+
{
3542+
int direction = (command == CK_SearchNext) ? 1 : -1;
3543+
int start = panel->current + direction;
3544+
int i, found = -1;
3545+
gboolean wrapped = FALSE;
3546+
char *reg_exp, *esc_str;
3547+
mc_search_t *search;
3548+
3549+
if (panel->quick_search.buffer->len == 0)
3550+
break;
3551+
3552+
reg_exp = g_strdup_printf ("%s*", panel->quick_search.buffer->str);
3553+
esc_str = str_escape (reg_exp, -1, ",|\\{}[]", TRUE);
3554+
search = mc_search_new (esc_str, NULL);
3555+
search->search_type = MC_SEARCH_T_GLOB;
3556+
search->is_entire_line = TRUE;
3557+
3558+
switch (panels_options.qsearch_mode)
3559+
{
3560+
case QSEARCH_CASE_SENSITIVE:
3561+
search->is_case_sensitive = TRUE;
3562+
break;
3563+
case QSEARCH_CASE_INSENSITIVE:
3564+
search->is_case_sensitive = FALSE;
3565+
break;
3566+
default:
3567+
search->is_case_sensitive = panel->sort_info.case_sensitive;
3568+
break;
3569+
}
3570+
3571+
for (i = start; !wrapped || i != start; i += direction)
3572+
{
3573+
if (i >= panel->dir.len)
3574+
{
3575+
i = 0;
3576+
if (wrapped)
3577+
break;
3578+
wrapped = TRUE;
3579+
}
3580+
if (i < 0)
3581+
{
3582+
i = panel->dir.len - 1;
3583+
if (wrapped)
3584+
break;
3585+
wrapped = TRUE;
3586+
}
3587+
if (mc_search_run (search, panel->dir.list[i].fname->str, 0,
3588+
panel->dir.list[i].fname->len, NULL))
3589+
{
3590+
found = i;
3591+
break;
3592+
}
3593+
}
3594+
3595+
mc_search_free (search);
3596+
g_free (reg_exp);
3597+
g_free (esc_str);
3598+
3599+
if (found >= 0)
3600+
{
3601+
unselect_item (panel);
3602+
panel->current = found;
3603+
select_item (panel);
3604+
widget_draw (WIDGET (panel));
3605+
}
3606+
}
3607+
break;
35383608
case CK_Up:
35393609
case CK_Down:
35403610
case CK_Left:

src/keymap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ static const global_keymap_ini_t default_panel_keymap[] = {
226226
{ "PageUp", "pgup; alt-v" },
227227
{ "SelectCodepage", "alt-e" },
228228
{ "Search", "ctrl-s; alt-s" },
229+
{ "SearchNext", "ctrl-s" },
230+
{ "SearchPrev", "" },
229231
{ "PanelOtherSync", "alt-i" },
230232
{
231233
NULL,

0 commit comments

Comments
 (0)