diff -up vifm-0.5/src/keys.c.old vifm-0.5/src/keys.c
--- vifm-0.5/src/keys.c.old 2010-05-16 16:06:52.000000000 +0200
+++ vifm-0.5/src/keys.c 2010-05-16 16:11:21.000000000 +0200
@@ -330,6 +330,49 @@ restore_filename_filter(FileView *view)
moveto_list_pos(view, view->list_pos);
}
+/** Deselects all files.
+ */
+static void
+deselect_all_files(FileView* view)
+{
+ int x;
+ for(x = 0; x < view->list_rows; x++)
+ view->dir_entry[x].selected = 0;
+ view->selected_files = 0;
+}
+
+/** Selects given number of files or current file.
+
+ If count == 0 and there is no selection, selects the current file.
+ Otherwise, if count == 1, selects number of files specified by
+ count_buf.
+ */
+static void
+select_n_files(FileView* view, int count, char* count_buf)
+{
+ if (count)
+ {
+ int x = 0;
+ int y = view->list_pos;
+
+ deselect_all_files(view);
+
+ for ( ; x < atoi(count_buf); x++)
+ {
+ view->dir_entry[y].selected = 1;
+ y++;
+ if (y >= view->list_rows)
+ break;
+ }
+ view->selected_files = y - view->list_pos;
+ }
+ else if (!view->selected_files)
+ {
+ view->dir_entry[view->list_pos].selected = 1;
+ view->selected_files = 1;
+ }
+}
+
static void
yank_files(FileView *view, int count, char *count_buf)
{
@@ -376,6 +419,25 @@ yank_files(FileView *view, int count, ch
}
static void
+delete_files(FileView *view, int count, char *count_buf)
+{
+ char buf[32];
+
+ select_n_files(view, count, count_buf);
+ get_all_selected_files(view);
+ delete_file(view);
+ free_selected_file_array(view);
+ count = view->selected_files;
+ deselect_all_files(view);
+
+ draw_dir_list(view, view->top_line, view->list_pos);
+ moveto_list_pos(view, view->list_pos);
+ snprintf(buf, sizeof(buf), " %d %s deleted.", count,
+ count == 1 ? "file" : "files");
+ status_bar_message(buf);
+}
+
+static void
tag_file(FileView *view)
{
if(view->dir_entry[view->list_pos].selected == 0)
@@ -1077,21 +1139,7 @@ main_key_press_cb(FileView *view)
if(curr_stats.last_char == 'd')
{
clear_num_window();
- if(view->selected_files)
- delete_file(view);
- else if(count)
- {
- int x;
- int y = view->list_pos;
- for(x = 0; x < atoi(count_buf); x++)
- {
- view->dir_entry[y].selected = 1;
- y++;
- }
- delete_file(view);
- }
- else
- delete_file(view);
+ delete_files(view, count, count_buf);
reset_last_char = 1;
}
}