summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-10-28 21:40:31 +0100
committerAndreas Kling <kling@serenityos.org>2020-10-28 21:40:31 +0100
commitde3dc15a6e887c33ad092faa69dfd31d780ccd13 (patch)
tree2a373a46a534fb0a7c46c518c088ba24981391bc /Libraries/LibGUI
parent1f789a07b18e71692414ba5b2f2af79bafa8be47 (diff)
downloadserenity-de3dc15a6e887c33ad092faa69dfd31d780ccd13.zip
LibGUI: Default-initialize cursor when focusing an AbstractView
If an AbstractView receives focus without a valid cursor index, we now ask it to move its cursor to the home position. This way, the user can actually start moving the cursor after tabbing to a view.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r--Libraries/LibGUI/AbstractView.cpp8
-rw-r--r--Libraries/LibGUI/AbstractView.h1
2 files changed, 9 insertions, 0 deletions
diff --git a/Libraries/LibGUI/AbstractView.cpp b/Libraries/LibGUI/AbstractView.cpp
index 8f91294f7d..33b542d109 100644
--- a/Libraries/LibGUI/AbstractView.cpp
+++ b/Libraries/LibGUI/AbstractView.cpp
@@ -678,4 +678,12 @@ void AbstractView::draw_item_text(Gfx::Painter& painter, const ModelIndex& index
}
}
+void AbstractView::focusin_event(FocusEvent& event)
+{
+ ScrollableWidget::focusin_event(event);
+
+ if (model() && !cursor_index().is_valid())
+ move_cursor(CursorMovement::Home, SelectionUpdate::None);
+}
+
}
diff --git a/Libraries/LibGUI/AbstractView.h b/Libraries/LibGUI/AbstractView.h
index 5c3dbefb8a..7e6fbabd47 100644
--- a/Libraries/LibGUI/AbstractView.h
+++ b/Libraries/LibGUI/AbstractView.h
@@ -137,6 +137,7 @@ protected:
virtual void drop_event(DropEvent&) override;
virtual void leave_event(Core::Event&) override;
virtual void hide_event(HideEvent&) override;
+ virtual void focusin_event(FocusEvent&) override;
virtual void clear_selection();
virtual void set_selection(const ModelIndex&);