refactor: send highlight references to correct editor for file path

This commit is contained in:
CJ van den Berg 2026-01-12 16:14:52 +01:00
parent 021dfa8d4c
commit 6a6fb11c8e
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -166,13 +166,13 @@ pub fn receive(self: *Self, from_: tp.pid_ref, m: tp.message) error{Exit}!bool {
self.find_in_files_state = .done; self.find_in_files_state = .done;
return true; return true;
} else if (try m.match(.{ "HREF", tp.extract(&path), tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos) })) { } else if (try m.match(.{ "HREF", tp.extract(&path), tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos) })) {
if (self.get_active_editor()) |editor| editor.add_highlight_reference(.{ if (self.get_editor_for_file(path)) |editor| editor.add_highlight_reference(.{
.begin = .{ .row = begin_line, .col = begin_pos }, .begin = .{ .row = begin_line, .col = begin_pos },
.end = .{ .row = end_line, .col = end_pos }, .end = .{ .row = end_line, .col = end_pos },
}); });
return true; return true;
} else if (try m.match(.{ "HREF", tp.extract(&path), "done" })) { } else if (try m.match(.{ "HREF", tp.extract(&path), "done" })) {
if (self.get_active_editor()) |editor| editor.done_highlight_reference(); if (self.get_editor_for_file(path)) |editor| editor.done_highlight_reference();
return true; return true;
} else if (try m.match(.{ "hover", tp.extract(&path), tp.string, tp.extract(&lines), tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos) })) { } else if (try m.match(.{ "hover", tp.extract(&path), tp.string, tp.extract(&lines), tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos) })) {
try self.set_info_content(lines, .replace); try self.set_info_content(lines, .replace);
@ -1593,6 +1593,16 @@ pub fn get_editor_for_buffer(self: *Self, buffer: *Buffer) ?*ed.Editor {
return null; return null;
} }
pub fn get_editor_for_file(self: *Self, file_path: []const u8) ?*ed.Editor {
for (self.views.widgets.items) |*view| {
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 &p.editor;
}
return null;
}
pub fn get_view_for_file(self: *Self, file_path: []const u8) ?usize { pub fn get_view_for_file(self: *Self, file_path: []const u8) ?usize {
for (self.views.widgets.items, 0..) |*view, n| { for (self.views.widgets.items, 0..) |*view, n| {
const editor = view.widget.get("editor") orelse continue; const editor = view.widget.get("editor") orelse continue;