Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/man/mc.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,18 @@ or
keys can be used to correct typing mistakes. If C\-s is pressed
again, the next match is searched for.
.P
The
.I SearchNext
and
.I SearchPrev
panel actions can be used to cycle through files matching the current
search pattern, wrapping around at the beginning or end of the list.
By default,
.I SearchNext
is bound to C\-s (same as repeating the search).
.I SearchPrev
has no default binding but can be configured in the keymap file.
.P
If quick search is started with double pressing of C\-s, the previous quick
search pattern will be used for current search.
.P
Expand Down
2 changes: 2 additions & 0 deletions lib/keybind.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ static name_keymap_t command_names[] = {
ADD_KEYMAP_NAME (EditUserMenu),
ADD_KEYMAP_NAME (Search),
ADD_KEYMAP_NAME (SearchContinue),
ADD_KEYMAP_NAME (SearchNext),
ADD_KEYMAP_NAME (SearchPrev),
ADD_KEYMAP_NAME (Replace),
ADD_KEYMAP_NAME (ReplaceContinue),
ADD_KEYMAP_NAME (Help),
Expand Down
2 changes: 2 additions & 0 deletions lib/keybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ enum
CK_Replace,
CK_ReplaceContinue,
CK_SearchStop,
CK_SearchNext,
CK_SearchPrev,
CK_Help,
CK_Edit,
CK_EditNew,
Expand Down
72 changes: 71 additions & 1 deletion src/filemanager/panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3530,11 +3530,81 @@ panel_execute_cmd (WPanel *panel, long command)
{
int res = MSG_HANDLED;

if (command != CK_Search)
if (command != CK_Search && command != CK_SearchNext && command != CK_SearchPrev)
stop_search (panel);

switch (command)
{
case CK_SearchNext:
case CK_SearchPrev:
if (panel->quick_search.active)
{
int direction = (command == CK_SearchNext) ? 1 : -1;
int start = panel->current + direction;
int i, found = -1;
gboolean wrapped = FALSE;
char *reg_exp, *esc_str;
mc_search_t *search;

if (panel->quick_search.buffer->len == 0)
break;

reg_exp = g_strdup_printf ("%s*", panel->quick_search.buffer->str);
esc_str = str_escape (reg_exp, -1, ",|\\{}[]", TRUE);
search = mc_search_new (esc_str, NULL);
search->search_type = MC_SEARCH_T_GLOB;
search->is_entire_line = TRUE;

switch (panels_options.qsearch_mode)
{
case QSEARCH_CASE_SENSITIVE:
search->is_case_sensitive = TRUE;
break;
case QSEARCH_CASE_INSENSITIVE:
search->is_case_sensitive = FALSE;
break;
default:
search->is_case_sensitive = panel->sort_info.case_sensitive;
break;
}

for (i = start; !wrapped || i != start; i += direction)
{
if (i >= panel->dir.len)
{
i = 0;
if (wrapped)
break;
wrapped = TRUE;
}
if (i < 0)
{
i = panel->dir.len - 1;
if (wrapped)
break;
wrapped = TRUE;
}
if (mc_search_run (search, panel->dir.list[i].fname->str, 0,
panel->dir.list[i].fname->len, NULL))
{
found = i;
break;
}
}

mc_search_free (search);
g_free (reg_exp);
g_free (esc_str);

if (found >= 0)
{
unselect_item (panel);
panel->current = found;
select_item (panel);
widget_draw (WIDGET (panel));
}
}
break;
case CK_Up:
case CK_Down:
case CK_Left:
Expand Down
2 changes: 2 additions & 0 deletions src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ static const global_keymap_ini_t default_panel_keymap[] = {
{ "PageUp", "pgup; alt-v" },
{ "SelectCodepage", "alt-e" },
{ "Search", "ctrl-s; alt-s" },
{ "SearchNext", "ctrl-s" },
{ "SearchPrev", "" },
{ "PanelOtherSync", "alt-i" },
{
NULL,
Expand Down