Skip to content

Commit f2d8c2a

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

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/FolderManager/FileView.vala

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
212212
private unowned Code.Widgets.SourceList.Item? find_path (
213213
Code.Widgets.SourceList.ExpandableItem list,
214214
string path,
215-
bool expand = false) {
215+
bool expand = false,
216+
GLib.File? target_file = null) {
217+
218+
var target = target_file ?? GLib.File.new_for_path (path);
216219

217220
foreach (var item in list.children) {
218221
if (item is Item) {
@@ -221,22 +224,23 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
221224
return (!)item;
222225
}
223226

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+
if (item is FolderItem) {
228+
var folder = item as FolderItem;
229+
var folder_root = folder.file.file;
230+
if (folder_root.get_relative_path (target) == null) {
227231
continue;
228232
}
229233

230-
if (!expander.expanded) {
234+
if (!folder.expanded) {
231235
if (expand) {
232-
((FolderItem)expander).load_children (); //Synchronous
233-
expander.expanded = true;
236+
folder.load_children (); //Synchronous
237+
folder.expanded = true;
234238
} else {
235239
continue;
236240
}
237241
}
238242

239-
unowned var recurse_item = find_path (expander, path, expand);
243+
unowned var recurse_item = find_path (folder, path, expand, target);
240244
if (recurse_item != null) {
241245
return recurse_item;
242246
}

0 commit comments

Comments
 (0)