mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +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:
parent
c84756efa8
commit
b66f3166cb
Notes:
sideshowbarker
2024-07-19 01:09:26 +09:00
Author: https://github.com/alimpfard
Commit: b66f3166cb
Pull-request: https://github.com/SerenityOS/serenity/pull/4177
Issue: https://github.com/SerenityOS/serenity/issues/4167
Issue: https://github.com/SerenityOS/serenity/issues/4168
Issue: https://github.com/SerenityOS/serenity/issues/4170
Issue: https://github.com/SerenityOS/serenity/issues/4171
Reviewed-by: https://github.com/awesomekling
1 changed files with 14 additions and 5 deletions
|
@ -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); });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue