Skip to content

Commit

Permalink
Merge branch 'consider-slash-for-select-cmd-pat'
Browse files Browse the repository at this point in the history
Consider trailing / in :[un]select by pattern.

Thanks to filterfalse.
  • Loading branch information
xaizek committed May 18, 2016
2 parents b742f1d + f68b837 commit 448f32c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
8 changes: 5 additions & 3 deletions data/man/vifm.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH VIFM 1 "May 13, 2016" "vifm 0.8.1a"
.TH VIFM 1 "May 18, 2016" "vifm 0.8.1a"
.\" ---------------------------------------------------------------------------
.SH NAME
.\" ---------------------------------------------------------------------------
Expand Down Expand Up @@ -2333,7 +2333,8 @@ select files in the given range (current file if no range is given).
.TP
.BI ":select {pattern}"
select files that match specified pattern. Possible {pattern} forms are
described in "Patterns" section below.
described in "Patterns" section below. Trailing slash for directories is taken
into account, so `:select *[^/]` selects only files.
.TP
.BI ":select //[iI]"
same as item above, but reuses last search pattern.
Expand Down Expand Up @@ -2538,7 +2539,8 @@ unselect files in the given range (current file if no range is given).
.TP
.BI ":unselect {pattern}"
unselect files that match specified pattern. Possible {pattern} forms are
described in "Patterns" section below.
described in "Patterns" section below. Trailing slash for directories is taken
into account, so `:unselect */` unselects directories.
.TP
.BI ":unselect !{external command}"
unselect files from the list supplied by external command. Files are matched by
Expand Down
8 changes: 5 additions & 3 deletions data/vim/doc/app/vifm-app.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*vifm-app.txt* For Vifm version 0.8.1a Last change: 2016 May 13
*vifm-app.txt* For Vifm version 0.8.1a Last change: 2016 May 18

Email for bugs and suggestions: <xaizek@openmailbox.org>

Expand Down Expand Up @@ -1974,7 +1974,8 @@ yet supported) and might be changed in future releases, or get an alias.
select files in the given range (current file if no range is given).
:select {pattern}
select files that match specified pattern. Possible {pattern} forms are
described in |vifm-patterns|.
described in |vifm-patterns|. Trailing slash for directories is taken
into account, so `:select *[^/]` selects only files.
:select //[iI]
same as item above, but reuses last search pattern.
:select !{external command}
Expand Down Expand Up @@ -2125,7 +2126,8 @@ yet supported) and might be changed in future releases, or get an alias.
unselect files in the given range (current file if no range is given).
:unselect {pattern}
unselect files that match specified pattern. Possible {pattern} forms are
described in |vifm-patterns|.
described in |vifm-patterns|. Trailing slash for directories is taken
into account, so `:unselect */` unselects directories.
:unselect !{external command}
unselect files from the list supplied by external command. Files are
matched by full paths, relative paths are converted to absolute ones
Expand Down
18 changes: 12 additions & 6 deletions src/cmd_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -3923,16 +3923,17 @@ select_unselect_by_filter(const cmd_info_t *cmd_info, int select)
{
char full_path[PATH_MAX];
void *ignored_data;
dir_entry_t *const entry = &curr_view->dir_entry[i];

if((curr_view->dir_entry[i].selected != 0) == select)
if((entry->selected != 0) == select)
{
continue;
}

get_full_path_at(curr_view, i, sizeof(full_path), full_path);
get_full_path_of(entry, sizeof(full_path), full_path);
if(trie_get(selection_trie, full_path, &ignored_data) == 0)
{
curr_view->dir_entry[i].selected = select;
entry->selected = select;
curr_view->selected_files += (select ? 1 : -1);
}
}
Expand Down Expand Up @@ -3969,17 +3970,22 @@ select_unselect_by_pattern(const cmd_info_t *cmd_info, int select)
for(i = 0; i < curr_view->list_rows; ++i)
{
char file_path[PATH_MAX];
dir_entry_t *const entry = &curr_view->dir_entry[i];

if((curr_view->dir_entry[i].selected != 0) == select)
if((entry->selected != 0) == select)
{
continue;
}

get_full_path_at(curr_view, i, sizeof(file_path), file_path);
get_full_path_of(entry, sizeof(file_path) - 1U, file_path);
if(is_directory_entry(entry))
{
strcat(file_path, "/");
}

if(matcher_matches(m, file_path))
{
curr_view->dir_entry[i].selected = select;
entry->selected = select;
curr_view->selected_files += (select ? 1 : -1);
}
}
Expand Down
31 changes: 31 additions & 0 deletions tests/misc/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,37 @@ TEST(select_and_unselect_accept_external_command)
assert_false(lwin.dir_entry[2].selected);
}

TEST(select_and_unselect_consider_trailing_slash)
{
strcpy(lwin.curr_dir, cwd);
assert_success(chdir(cwd));

lwin.list_rows = 4;
lwin.list_pos = 0;
lwin.dir_entry = dynarray_cextend(NULL,
lwin.list_rows*sizeof(*lwin.dir_entry));
lwin.dir_entry[0].name = strdup("a");
lwin.dir_entry[0].origin = &lwin.curr_dir[0];
lwin.dir_entry[0].type = FT_REG;
lwin.dir_entry[1].name = strdup("a");
lwin.dir_entry[1].origin = &lwin.curr_dir[0];
lwin.dir_entry[1].type = FT_DIR;
lwin.dir_entry[2].name = strdup("b");
lwin.dir_entry[2].origin = &lwin.curr_dir[0];
lwin.dir_entry[2].type = FT_REG;
lwin.dir_entry[3].name = strdup("b");
lwin.dir_entry[3].origin = &lwin.curr_dir[0];
lwin.dir_entry[3].type = FT_DIR;
lwin.selected_files = 0;

assert_success(exec_commands("select */", &lwin, CIT_COMMAND));
assert_int_equal(2, lwin.selected_files);
assert_false(lwin.dir_entry[0].selected);
assert_true(lwin.dir_entry[1].selected);
assert_false(lwin.dir_entry[2].selected);
assert_true(lwin.dir_entry[3].selected);
}

static void
check_filetype(void)
{
Expand Down

0 comments on commit 448f32c

Please sign in to comment.