From 938380e88b614c5f76ad930d295f3def2db013b5 Mon Sep 17 00:00:00 2001 From: martinfalisse Date: Wed, 5 Jan 2022 21:11:31 +0100 Subject: [PATCH] LibGUI: Table View navigating with arrow keys continuity after update When a user is navigating a table view with arrow keys and a row is outside of the current view, then scroll_into_view is called, and the position of the rectangle passed to this should take into account the column headers. This can be seen making more pleasant the navigation in the System Monitor in the Processes view, for example. --- Userland/Libraries/LibGUI/SortingProxyModel.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibGUI/SortingProxyModel.cpp b/Userland/Libraries/LibGUI/SortingProxyModel.cpp index 33bc1db1cf9..9d25de86624 100644 --- a/Userland/Libraries/LibGUI/SortingProxyModel.cpp +++ b/Userland/Libraries/LibGUI/SortingProxyModel.cpp @@ -190,18 +190,6 @@ void SortingProxyModel::sort_mapping(Mapping& mapping, int column, SortOrder sor // FIXME: I really feel like this should be done at the view layer somehow. for_each_view([&](AbstractView& view) { - // Update the view's cursor. - auto cursor = view.cursor_index(); - if (cursor.is_valid() && cursor.parent() == mapping.source_parent) { - for (size_t i = 0; i < mapping.source_rows.size(); ++i) { - if (mapping.source_rows[i] == view.cursor_index().row()) { - auto new_source_index = this->index(i, view.cursor_index().column(), mapping.source_parent); - view.set_cursor(new_source_index, AbstractView::SelectionUpdate::None, false); - break; - } - } - } - // Update the view's selection. view.selection().change_from_model({}, [&](ModelSelection& selection) { Vector selected_indices_in_source; @@ -222,6 +210,10 @@ void SortingProxyModel::sort_mapping(Mapping& mapping, int column, SortOrder sor if (mapping.source_rows[i] == index.row()) { auto new_source_index = this->index(i, index.column(), mapping.source_parent); selection.add(new_source_index); + // Update the view's cursor. + auto cursor = view.cursor_index(); + if (cursor.is_valid() && cursor.parent() == mapping.source_parent) + view.set_cursor(new_source_index, AbstractView::SelectionUpdate::None, false); break; } }