refactor: add get_view_for_file helper function

This commit is contained in:
CJ van den Berg 2025-12-03 22:31:11 +01:00
parent 82e2d2f4ec
commit 5dbe4b887e
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -1511,6 +1511,16 @@ pub fn get_active_editor(self: *Self) ?*ed.Editor {
return null;
}
pub fn get_view_for_file(self: *Self, file_path: []const u8) ?usize {
for (self.views.widgets.items, 0..) |*view, n| {
const editor = view.widget.get("editor") orelse continue;
if (editor.dynamic_cast(ed.EditorWidget)) |p|
if (std.mem.eql(u8, p.editor.file_path orelse continue, file_path))
return n;
}
return null;
}
pub fn get_active_file_path(self: *Self) ?[]const u8 {
return if (self.get_active_editor()) |editor| editor.file_path orelse null else null;
}