Skip to content

Commit bc0c8cc

Browse files
committed
filter-view: Explicitly select the first item when filtering is
applied. Focus order out of the filter box is not reliable, and this matches the old behavior where the first item was automatically selected. Fixes #3780
1 parent a4b2add commit bc0c8cc

6 files changed

Lines changed: 81 additions & 0 deletions

File tree

libnemo-private/nemo-icon-container.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6199,6 +6199,43 @@ nemo_icon_container_select_all (NemoIconContainer *container)
61996199
}
62006200
}
62016201

6202+
/**
6203+
* nemo_icon_container_select_first:
6204+
* @container: An icon container widget.
6205+
*
6206+
* Selects the first icon in display order, unselecting any others.
6207+
* The icon list is resorted first if pending changes (such as
6208+
* a filtered add) left it out of order.
6209+
**/
6210+
void
6211+
nemo_icon_container_select_first (NemoIconContainer *container)
6212+
{
6213+
NemoIcon *icon;
6214+
6215+
g_return_if_fail (NEMO_IS_ICON_CONTAINER (container));
6216+
6217+
if (container->details->needs_resort) {
6218+
nemo_icon_container_resort (container);
6219+
container->details->needs_resort = FALSE;
6220+
}
6221+
6222+
if (container->details->icons == NULL) {
6223+
return;
6224+
}
6225+
6226+
icon = container->details->icons->data;
6227+
6228+
/* Drop any stale keyboard focus from the previous selection so arrow-key
6229+
* navigation starts from this new selection. */
6230+
clear_keyboard_focus (container);
6231+
clear_keyboard_rubberband_start (container);
6232+
container->details->range_selection_base_icon = icon;
6233+
6234+
if (select_one_unselect_others (container, icon)) {
6235+
g_signal_emit (container, signals[SELECTION_CHANGED], 0);
6236+
}
6237+
}
6238+
62026239
/**
62036240
* nemo_icon_container_set_selection:
62046241
* @container: An icon container widget.

libnemo-private/nemo-icon-container.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ void nemo_icon_container_set_highlighted_for_clipboard (NemoIconCon
302302
/* operations on all icons */
303303
void nemo_icon_container_unselect_all (NemoIconContainer *view);
304304
void nemo_icon_container_select_all (NemoIconContainer *view);
305+
void nemo_icon_container_select_first (NemoIconContainer *container);
305306

306307

307308
/* operations on the selection */

src/nemo-icon-view.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,17 @@ nemo_icon_view_update_filter_text (NemoView *view,
23802380
}
23812381
}
23822382

2383+
static void
2384+
nemo_icon_view_select_first (NemoView *view)
2385+
{
2386+
NemoIconContainer *container;
2387+
2388+
container = nemo_icon_view_get_icon_container (NEMO_ICON_VIEW (view));
2389+
if (container != NULL) {
2390+
nemo_icon_container_select_first (container);
2391+
}
2392+
}
2393+
23832394
static gboolean
23842395
icon_container_activate_filter_cb (NemoIconContainer *container,
23852396
GdkEvent *event,
@@ -2775,6 +2786,7 @@ nemo_icon_view_class_init (NemoIconViewClass *klass)
27752786
nemo_view_class->invert_selection = nemo_icon_view_invert_selection;
27762787
nemo_view_class->compare_files = compare_files;
27772788
nemo_view_class->update_filter_text = nemo_icon_view_update_filter_text;
2789+
nemo_view_class->select_first = nemo_icon_view_select_first;
27782790
nemo_view_class->zoom_to_level = nemo_icon_view_zoom_to_level;
27792791
nemo_view_class->get_zoom_level = nemo_icon_view_get_zoom_level;
27802792
nemo_view_class->click_policy_changed = nemo_icon_view_click_policy_changed;

src/nemo-list-view.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ get_default_sort_order (NemoFile *file, gboolean *reversed)
274274
}
275275

276276
static void nemo_list_view_update_filter_text (NemoView *view, const char *filter_text);
277+
static void nemo_list_view_select_first (NemoView *view);
277278

278279
static void
279280
tooltip_prefs_changed_callback (NemoListView *view)
@@ -4427,6 +4428,7 @@ nemo_list_view_class_init (NemoListViewClass *class)
44274428
nemo_view_class->invert_selection = nemo_list_view_invert_selection;
44284429
nemo_view_class->compare_files = nemo_list_view_compare_files;
44294430
nemo_view_class->update_filter_text = nemo_list_view_update_filter_text;
4431+
nemo_view_class->select_first = nemo_list_view_select_first;
44304432
nemo_view_class->sort_directories_first_changed = nemo_list_view_sort_directories_first_changed;
44314433
nemo_view_class->sort_favorites_first_changed = nemo_list_view_sort_favorites_first_changed;
44324434
nemo_view_class->start_renaming_file = nemo_list_view_start_renaming_file;
@@ -4598,3 +4600,20 @@ nemo_list_view_update_filter_text (NemoView *view,
45984600
nemo_list_model_set_filter_active (list_view->details->model,
45994601
filter_text != NULL && filter_text[0] != '\0');
46004602
}
4603+
4604+
static void
4605+
nemo_list_view_select_first (NemoView *view)
4606+
{
4607+
NemoListView *list_view = NEMO_LIST_VIEW (view);
4608+
GtkTreeModel *model = GTK_TREE_MODEL (list_view->details->model);
4609+
GtkTreeIter iter;
4610+
GtkTreePath *path;
4611+
4612+
if (!gtk_tree_model_get_iter_first (model, &iter)) {
4613+
return;
4614+
}
4615+
4616+
path = gtk_tree_model_get_path (model, &iter);
4617+
gtk_tree_view_set_cursor (list_view->details->tree_view, path, NULL, FALSE);
4618+
gtk_tree_path_free (path);
4619+
}

src/nemo-view.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10928,6 +10928,10 @@ apply_filter_debounce_cb (gpointer data)
1092810928
NEMO_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->update_filter_text (view, view->details->filter_text);
1092910929
nemo_view_apply_filter (view);
1093010930

10931+
if (view->details->filter_active) {
10932+
NEMO_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->select_first (view);
10933+
}
10934+
1093110935
/* Re-emit so the slot can update the "no matching files" indicator
1093210936
* now that apply_filter has updated the view contents. */
1093310937
g_signal_emit (view, signals[ACTIVATE_FILTER], 0, view->details->filter_text);
@@ -11091,6 +11095,11 @@ real_update_filter_text (NemoView *view, const char *filter_text)
1109111095
{
1109211096
}
1109311097

11098+
static void
11099+
real_select_first (NemoView *view)
11100+
{
11101+
}
11102+
1109411103
static void
1109511104
schedule_update_menus_callback (gpointer callback_data)
1109611105
{
@@ -11549,6 +11558,7 @@ nemo_view_class_init (NemoViewClass *klass)
1154911558
klass->unmerge_menus = real_unmerge_menus;
1155011559
klass->update_menus = real_update_menus;
1155111560
klass->update_filter_text = real_update_filter_text;
11561+
klass->select_first = real_select_first;
1155211562
klass->trash = real_trash;
1155311563
klass->delete = real_delete;
1155411564

src/nemo-view.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ struct NemoViewClass {
317317
void (* update_filter_text) (NemoView *view,
318318
const char *filter_text);
319319

320+
void (* select_first) (NemoView *view);
321+
320322
/* Signals used only for keybindings */
321323
gboolean (* trash) (NemoView *view);
322324
gboolean (* delete) (NemoView *view);

0 commit comments

Comments
 (0)