Skip to content

Commit 963afd1

Browse files
committed
Guard FileView recursion against file nodes
1 parent dca3a35 commit 963afd1

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/FolderManager/FileView.vala

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,31 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
221221
return (!)item;
222222
}
223223

224-
if (item is Code.Widgets.SourceList.ExpandableItem) {
225-
var expander = item as Code.Widgets.SourceList.ExpandableItem;
226-
if (!path.has_prefix (code_item.path)) {
227-
continue;
224+
if (item is FolderItem) {
225+
var folder = item as FolderItem;
226+
var folder_path = folder.path;
227+
var ends_with_separator = folder_path.has_suffix (Path.DIR_SEPARATOR_S);
228+
if (ends_with_separator) {
229+
if (!path.has_prefix (folder_path) || path.length <= folder_path.length) {
230+
continue;
231+
}
232+
} else {
233+
var folder_prefix = folder_path + Path.DIR_SEPARATOR_S;
234+
if (!path.has_prefix (folder_prefix)) {
235+
continue;
236+
}
228237
}
229238

230-
if (!expander.expanded) {
239+
if (!folder.expanded) {
231240
if (expand) {
232-
((FolderItem)expander).load_children (); //Synchronous
233-
expander.expanded = true;
241+
folder.load_children (); //Synchronous
242+
folder.expanded = true;
234243
} else {
235244
continue;
236245
}
237246
}
238247

239-
unowned var recurse_item = find_path (expander, path, expand);
248+
unowned var recurse_item = find_path (folder, path, expand);
240249
if (recurse_item != null) {
241250
return recurse_item;
242251
}

0 commit comments

Comments
 (0)