LibGUI: Remove Indices with dangling FileSystemModel::Node on deletion

When a file deletion event happens, we now iterate over all views of the
FileSystemModel and remove any selection & cursor indices that hold
dangling references do the deleted filesystem node.

This fixes #9602.
This commit is contained in:
Itamar 2021-09-10 13:13:51 +03:00 committed by Andreas Kling
parent a2f5589d3a
commit de31603028
Notes: sideshowbarker 2024-07-18 04:05:54 +09:00

View file

@ -12,6 +12,7 @@
#include <LibCore/DirIterator.h>
#include <LibCore/File.h>
#include <LibCore/StandardPaths.h>
#include <LibGUI/AbstractView.h>
#include <LibGUI/FileIconProvider.h>
#include <LibGUI/FileSystemModel.h>
#include <LibGUI/Painter.h>
@ -420,6 +421,16 @@ void FileSystemModel::handle_file_event(Core::FileWatcherEvent const& event)
parent->m_children.remove(index.row());
end_delete_rows();
for_each_view([&](AbstractView& view) {
view.selection().remove_matching([&](auto& selection_index) {
return selection_index.internal_data() == index.internal_data();
});
if (view.cursor_index().internal_data() == index.internal_data()) {
view.set_cursor({}, GUI::AbstractView::SelectionUpdate::None);
}
});
break;
}
case Core::FileWatcherEvent::Type::MetadataModified: {