refactor: simplify getting the active editor and selection

This commit is contained in:
CJ van den Berg 2024-12-11 20:54:53 +01:00
parent 4b3904d5f2
commit 038ed4da2b
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
10 changed files with 138 additions and 143 deletions

View file

@ -908,6 +908,18 @@ pub fn current() *Self {
return instance_ orelse @panic("tui call out of context");
}
pub fn get_active_editor() ?*@import("editor.zig").Editor {
if (current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_active_editor()) |editor|
return editor;
return null;
}
pub fn get_active_selection(allocator: std.mem.Allocator) ?[]u8 {
const editor = get_active_editor() orelse return null;
const sel = editor.get_primary().selection orelse return null;
return editor.get_selection(sel, allocator) catch null;
}
fn context_check() void {
if (instance_ == null) @panic("tui call out of context");
}