From 94551149d1b5b468f5d8779386178ba9ee9207fe Mon Sep 17 00:00:00 2001 From: Marcus Nilsson Date: Thu, 3 Jun 2021 19:15:26 +0200 Subject: [PATCH] TreeView: Don't try to move cursor with invalid index When clicking on the TreeView in profiler without selecting a node and then pressing up or pgup, cursor_index was in an invalid state. Instead select the first node in the index. --- Userland/Libraries/LibGUI/TreeView.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Libraries/LibGUI/TreeView.cpp b/Userland/Libraries/LibGUI/TreeView.cpp index 56133847332..1a9fa59b433 100644 --- a/Userland/Libraries/LibGUI/TreeView.cpp +++ b/Userland/Libraries/LibGUI/TreeView.cpp @@ -480,6 +480,9 @@ void TreeView::move_cursor(CursorMovement movement, SelectionUpdate selection_up { auto& model = *this->model(); + if (!cursor_index().is_valid()) + set_cursor(model.index(0, model.tree_column(), cursor_index()), SelectionUpdate::Set); + auto find_last_index_in_tree = [&](const ModelIndex tree_index) -> ModelIndex { auto last_index = tree_index; size_t row_count = model.row_count(last_index);