Browse Source

LibGUI: Fix GTreeView crash on pressing Left/Right without selection

Andreas Kling 5 năm trước cách đây
mục cha
commit
870df4a8c6
1 tập tin đã thay đổi với 2 bổ sung2 xóa
  1. 2 2
      Libraries/LibGUI/GTreeView.cpp

+ 2 - 2
Libraries/LibGUI/GTreeView.cpp

@@ -370,7 +370,7 @@ void GTreeView::keydown_event(GKeyEvent& event)
         return;
     }
     if (event.key() == KeyCode::Key_Left) {
-        if (model()->row_count(cursor_index)) {
+        if (cursor_index.is_valid() && model()->row_count(cursor_index)) {
             auto& metadata = ensure_metadata_for_index(cursor_index);
             if (metadata.open) {
                 metadata.open = false;
@@ -382,7 +382,7 @@ void GTreeView::keydown_event(GKeyEvent& event)
         }
     }
     if (event.key() == KeyCode::Key_Right) {
-        if (model()->row_count(cursor_index)) {
+        if (cursor_index.is_valid() && model()->row_count(cursor_index)) {
             auto& metadata = ensure_metadata_for_index(cursor_index);
             if (!metadata.open) {
                 metadata.open = true;