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:
AnotherTest 2020-11-29 11:08:11 +03:30 committed by Andreas Kling
parent c84756efa8
commit b66f3166cb
Notes: sideshowbarker 2024-07-19 01:09:26 +09:00

View file

@ -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); });
}
}