From 7a4b912ece600ac94a9e2c5b9991475fbd0c20fd Mon Sep 17 00:00:00 2001 From: Aayush Date: Wed, 28 Dec 2022 21:53:23 +0100 Subject: [PATCH] LibGUI: Fix invalid ModelIndices during shift-click multiselection Previously, If the widget was unfocused, the selection start index would be invalid. This would result in invalid selections when doing shift+click on the widget (while it is unfocused). Now, we reassign the selection start index to current index before we initiate multiselection, if selection start index is invalid. Should Fix SerenityOS#11999 and the same bug inside FileManager. --- Userland/Libraries/LibGUI/AbstractView.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Userland/Libraries/LibGUI/AbstractView.cpp b/Userland/Libraries/LibGUI/AbstractView.cpp index 8ad6ba9d3a..b267a8f861 100644 --- a/Userland/Libraries/LibGUI/AbstractView.cpp +++ b/Userland/Libraries/LibGUI/AbstractView.cpp @@ -493,6 +493,8 @@ void AbstractView::set_cursor(ModelIndex index, SelectionUpdate selection_update if (!m_selection.contains(index)) clear_selection(); } else if (selection_update == SelectionUpdate::Shift) { + if (!selection_start_index().is_valid()) + set_selection_start_index(index); select_range(index); }