summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-29 00:17:42 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-29 00:17:42 +0200
commitfed53e19c7390130e21442bfa975524f9f54a1b2 (patch)
tree3982748634a4da525223984a004450625705f2ca /Libraries
parent734035857ed84e04e6540c498f98f118aa23909f (diff)
downloadserenity-fed53e19c7390130e21442bfa975524f9f54a1b2.zip
LibGUI: Make AbstractView::set_cursor() scrolling into view optional
Sometimes you just want to set the cursor programmatically without scrolling the view to make the cursor visible.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/AbstractView.cpp9
-rw-r--r--Libraries/LibGUI/AbstractView.h2
2 files changed, 7 insertions, 4 deletions
diff --git a/Libraries/LibGUI/AbstractView.cpp b/Libraries/LibGUI/AbstractView.cpp
index 80aa11fa10..f4a2eb28eb 100644
--- a/Libraries/LibGUI/AbstractView.cpp
+++ b/Libraries/LibGUI/AbstractView.cpp
@@ -423,7 +423,7 @@ void AbstractView::set_key_column_and_sort_order(int column, SortOrder sort_orde
update();
}
-void AbstractView::set_cursor(ModelIndex index, SelectionUpdate selection_update)
+void AbstractView::set_cursor(ModelIndex index, SelectionUpdate selection_update, bool scroll_cursor_into_view)
{
if (m_cursor_index == index)
return;
@@ -442,8 +442,11 @@ void AbstractView::set_cursor(ModelIndex index, SelectionUpdate selection_update
// FIXME: Support the other SelectionUpdate types
m_cursor_index = index;
- // FIXME: We should scroll into view both vertically *and* horizontally.
- scroll_into_view(index, false, true);
+
+ if (scroll_cursor_into_view) {
+ // FIXME: We should scroll into view both vertically *and* horizontally.
+ scroll_into_view(index, false, true);
+ }
update();
}
}
diff --git a/Libraries/LibGUI/AbstractView.h b/Libraries/LibGUI/AbstractView.h
index add58c9cb0..84f3a7689a 100644
--- a/Libraries/LibGUI/AbstractView.h
+++ b/Libraries/LibGUI/AbstractView.h
@@ -114,7 +114,7 @@ public:
virtual void scroll_into_view(const ModelIndex&, [[maybe_unused]] bool scroll_horizontally = true, [[maybe_unused]] bool scroll_vertically = true) { }
const ModelIndex& cursor_index() const { return m_cursor_index; }
- void set_cursor(ModelIndex, SelectionUpdate);
+ void set_cursor(ModelIndex, SelectionUpdate, bool scroll_cursor_into_view = true);
bool is_tab_key_navigation_enabled() const { return m_tab_key_navigation_enabled; }
void set_tab_key_navigation_enabled(bool enabled) { m_tab_key_navigation_enabled = enabled; }