Compare commits

..

3 commits

Author SHA1 Message Date
a532665afb
fix: make create_scratch_buffer work correctly across splits 2026-01-20 16:16:32 +01:00
dd0e108f76
fix: call create_scratch_buffer syncronously in run_task to improve error handling 2026-01-20 16:15:37 +01:00
a7d4fc5729
refactor: add command.fmtbuf
This is useful for recursive command calling to avoid overwriting the
global command arguments buffer.
2026-01-20 16:13:40 +01:00
3 changed files with 26 additions and 1 deletions

View file

@ -18,11 +18,20 @@ pub const Context = struct {
cbor.writeValue(&context_buffer.writer, value) catch @panic("command.Context.fmt failed");
return .{ .args = .{ .buf = context_buffer.written() } };
}
fn fmtbuf(buf: []u8, value: anytype) error{CommandContextBufferNoSpaceLeft}!Context {
var writer: std.Io.Writer = .fixed(buf);
cbor.writeValue(&writer, value) catch |e| return switch (e) {
error.WriteFailed => error.CommandContextBufferNoSpaceLeft,
};
return .{ .args = .{ .buf = writer.buffered() } };
}
};
const context_buffer_allocator = std.heap.c_allocator;
threadlocal var context_buffer: std.Io.Writer.Allocating = .init(context_buffer_allocator);
pub const fmt = Context.fmt;
pub const fmtbuf = Context.fmtbuf;
const Vtable = struct {
id: ID = ID_unknown,

View file

@ -724,6 +724,21 @@ const cmds = struct {
const args = try ctx.args.clone(self.allocator);
defer self.allocator.free(args.buf);
tui.reset_drag_context();
var file_path: []const u8 = undefined;
if (ctx.args.match(.{ tp.extract(&file_path), tp.string, tp.string }) catch false or
ctx.args.match(.{ tp.extract(&file_path), tp.string }) catch false or
ctx.args.match(.{tp.extract(&file_path)}) catch false)
{
if (self.buffer_manager.get_buffer_for_file(file_path)) |_| {
var buf: [tp.max_message_size]u8 = undefined;
try command.executeName("navigate", try command.fmtbuf(&buf, .{ .file = file_path }));
tui.need_render(@src());
self.location_update_from_editor();
return;
}
}
try self.create_editor();
try command.executeName("open_scratch_buffer", .{ .args = args });
tui.need_render(@src());

View file

@ -1354,7 +1354,8 @@ const cmds = struct {
defer buffer_name.deinit();
buffer_name.writer.print("*{s}*", .{cmd}) catch {};
call_add_task(task);
tp.self_pid().send(.{ "cmd", "create_scratch_buffer", .{ buffer_name.written(), "", "conf" } }) catch |e| self.logger.err("task", e);
var buf: [tp.max_message_size]u8 = undefined;
try command.executeName("create_scratch_buffer", try command.fmtbuf(&buf, .{ buffer_name.written(), "", "conf" }));
tp.self_pid().send(.{ "cmd", "shell_execute_stream", .{cmd} }) catch |e| self.logger.err("task", e);
} else {
return self.enter_overlay_mode(@import("mode/overlay/task_palette.zig").Type);