mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-02 22:04:42 +00:00
LibGUI: Add a cursor to AbstractView, separate from the selection
Views now have a cursor index (retrievable via cursor_index()) which is separate from the selection. Until now, we've been using the first entry in the selection as "the cursor", which gets messy whenever you want to select more than one index in the model. When setting the cursor, the selection is implicitly updated as well to maintain the old behavior (for the most part.) Going forward, this will make it much easier to implement things like shift-select (extend selection from cursor) and such. :^)
This commit is contained in:
@@ -219,7 +219,7 @@ void AbstractView::mousedown_event(MouseEvent& event)
|
||||
// We might be starting a drag, so don't throw away other selected items yet.
|
||||
m_might_drag = true;
|
||||
} else {
|
||||
set_selection(index);
|
||||
set_cursor(index, SelectionUpdate::Set);
|
||||
}
|
||||
|
||||
update();
|
||||
@@ -424,4 +424,29 @@ void AbstractView::set_key_column_and_sort_order(int column, SortOrder sort_orde
|
||||
update();
|
||||
}
|
||||
|
||||
void AbstractView::set_cursor(ModelIndex index, SelectionUpdate selection_update)
|
||||
{
|
||||
if (m_cursor_index == index)
|
||||
return;
|
||||
|
||||
if (!model()) {
|
||||
m_cursor_index = {};
|
||||
return;
|
||||
}
|
||||
|
||||
if (model()->is_valid(index)) {
|
||||
if (selection_update == SelectionUpdate::Set)
|
||||
selection().set(index);
|
||||
else if (selection_update == SelectionUpdate::Ctrl)
|
||||
selection().toggle(index);
|
||||
|
||||
// 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);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user