diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2019-08-16 19:08:54 +0100 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2019-08-16 19:08:54 +0100 |
commit | c6ce270ee1e54fc7ae9c4029923bccedbcac5ad2 (patch) | |
tree | 4a5158d82b0a566edab9d94ad49a2b3885fa1a0a /src/navigator.c | |
parent | 505340f9fdd7e8d8356c25035b254c8f9ee367a6 (diff) | |
download | imv-c6ce270ee1e54fc7ae9c4029923bccedbcac5ad2.tar.gz |
imv: Add index/all argument to close command
Diffstat (limited to 'src/navigator.c')
-rw-r--r-- | src/navigator.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/navigator.c b/src/navigator.c index 98c1976..6b77643 100644 --- a/src/navigator.c +++ b/src/navigator.c @@ -215,6 +215,44 @@ void imv_navigator_remove(struct imv_navigator *nav, const char *path) nav->changed = 1; } +void imv_navigator_remove_at(struct imv_navigator *nav, size_t index) +{ + if (index >= nav->paths->len) { + return; + } + struct nav_item *item = nav->paths->items[index]; + free(item->path); + free(item); + list_remove(nav->paths, index); + + if (nav->cur_path == index) { + /* We just removed the current path */ + if (nav->last_move_direction < 0) { + /* Move left */ + imv_navigator_select_rel(nav, -1); + } else { + /* Try to stay where we are, unless we ran out of room */ + if (nav->cur_path == nav->paths->len) { + nav->cur_path = 0; + nav->wrapped = 1; + } + } + } + nav->changed = 1; +} + +void imv_navigator_remove_all(struct imv_navigator *nav) +{ + for (size_t i = 0; i < nav->paths->len; ++i) { + struct nav_item *item = nav->paths->items[i]; + free(item->path); + free(item); + } + list_clear(nav->paths); + nav->cur_path = 0; + nav->changed = 1; +} + ssize_t imv_navigator_find_path(struct imv_navigator *nav, const char *path) { /* first try to match the exact path */ |