mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-05 08:06:09 +00:00
LibGUI: Throw less view state away in model_did_update()
When `DontInvalidIndexes` is passed, be optimistic and keep the old indices when the model validates them. This is currently fine, as the group of models that use DontInvalidateIndexes use it as "The old indices are still ok" (there's a note about this in ProcessModel.cpp).
This commit is contained in:
committed by
Andreas Kling
parent
c84756efa8
commit
b66f3166cb
@@ -69,14 +69,23 @@ void AbstractView::set_model(RefPtr<Model> model)
|
||||
|
||||
void AbstractView::model_did_update(unsigned int flags)
|
||||
{
|
||||
// FIXME: It's unfortunate that we lose so much view state when the model updates in any way.
|
||||
stop_editing();
|
||||
m_edit_index = {};
|
||||
m_hovered_index = {};
|
||||
m_cursor_index = {};
|
||||
if (!model() || (flags & GUI::Model::InvalidateAllIndexes)) {
|
||||
stop_editing();
|
||||
m_edit_index = {};
|
||||
m_hovered_index = {};
|
||||
m_cursor_index = {};
|
||||
clear_selection();
|
||||
} else {
|
||||
// FIXME: These may no longer point to whatever they did before,
|
||||
// but let's be optimistic until we can be sure about it.
|
||||
if (!model()->is_valid(m_edit_index)) {
|
||||
stop_editing();
|
||||
m_edit_index = {};
|
||||
}
|
||||
if (!model()->is_valid(m_hovered_index))
|
||||
m_hovered_index = {};
|
||||
if (!model()->is_valid(m_cursor_index))
|
||||
m_cursor_index = {};
|
||||
selection().remove_matching([this](auto& index) { return !model()->is_valid(index); });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user