feat: improve shell_execute_stream_output to follow output tail only if cursor is at buffer end

This commit is contained in:
CJ van den Berg 2025-02-21 21:38:25 +01:00
parent c37848bfb3
commit 7c354c994f
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 15 additions and 2 deletions

View file

@ -3993,6 +3993,20 @@ pub const Editor = struct {
}
pub const smart_insert_line_after_meta = .{ .description = "Insert line after (smart)" };
pub fn smart_buffer_append(self: *Self, ctx: Context) Result {
var chars: []const u8 = undefined;
if (!try ctx.args.match(.{tp.extract(&chars)}))
return error.InvalidInsertCharsArgument;
const b = try self.buf_for_update();
var root = b.root;
var cursel: CurSel = .{};
cursel.cursor.move_buffer_end(root, self.metrics);
root = try self.insert(root, &cursel, chars, b.allocator);
try self.update_buf(root);
self.clamp();
}
pub const smart_buffer_append_meta = .{ .arguments = &.{.string} };
pub fn enable_fast_scroll(self: *Self, _: Context) Result {
self.fast_scroll = true;
}

View file

@ -847,8 +847,7 @@ const cmds = struct {
return error.InvalidShellOutputArgument;
const buffer = self.buffer_manager.buffer_from_ref(buffer_ref) orelse return;
if (self.get_active_editor()) |editor| if (editor.buffer) |eb| if (eb == buffer) {
editor.move_buffer_end(.{}) catch {};
editor.insert_chars(command.fmt(.{output})) catch {};
editor.smart_buffer_append(command.fmt(.{output})) catch {};
tui.need_render();
return;
};