mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09: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:
parent
76a0acb5bc
commit
9cf37901cd
Notes:
sideshowbarker
2024-07-19 03:05:26 +09:00
Author: https://github.com/awesomekling
Commit: 9cf37901cd
8 changed files with 79 additions and 49 deletions
|
@ -47,7 +47,14 @@ public:
|
|||
PageDown,
|
||||
};
|
||||
|
||||
virtual void move_cursor(CursorMovement) { }
|
||||
enum class SelectionUpdate {
|
||||
None,
|
||||
Set,
|
||||
Shift,
|
||||
Ctrl,
|
||||
};
|
||||
|
||||
virtual void move_cursor(CursorMovement, SelectionUpdate) { }
|
||||
|
||||
void set_model(RefPtr<Model>);
|
||||
Model* model() { return m_model.ptr(); }
|
||||
|
@ -94,6 +101,11 @@ public:
|
|||
int key_column() const { return m_key_column; }
|
||||
SortOrder sort_order() const { return m_sort_order; }
|
||||
|
||||
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);
|
||||
|
||||
protected:
|
||||
AbstractView();
|
||||
virtual ~AbstractView() override;
|
||||
|
@ -137,6 +149,7 @@ private:
|
|||
RefPtr<Model> m_model;
|
||||
OwnPtr<ModelEditingDelegate> m_editing_delegate;
|
||||
ModelSelection m_selection;
|
||||
ModelIndex m_cursor_index;
|
||||
bool m_activates_on_selection { false };
|
||||
bool m_multi_select { true };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue