From 338d7f7bf34c22f1b943a3843ea1eb4c03794695 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 1 Jul 2025 21:09:26 +0200 Subject: [PATCH] feat: add follow_cursor_on_buffer_switch option (default false) With this option disabled (the default) flow will not change the buffer position at all when switching active buffers. Enable the option to return to previous behaviour where the cursor is always scrolled into view. closes #271 --- src/config.zig | 1 + src/tui/editor.zig | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/config.zig b/src/config.zig index def68be..22c233c 100644 --- a/src/config.zig +++ b/src/config.zig @@ -19,6 +19,7 @@ animation_min_lag: usize = 0, //milliseconds animation_max_lag: usize = 150, //milliseconds enable_format_on_save: bool = false, restore_last_cursor_position: bool = true, +follow_cursor_on_buffer_switch: bool = false, //scroll cursor into view on buffer switch default_cursor: []const u8 = "default", indent_size: usize = 4, diff --git a/src/tui/editor.zig b/src/tui/editor.zig index e067208..5b14afc 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -433,7 +433,8 @@ pub const Editor = struct { return error.RestoreFindHistory; self.push_find_history(value); } - self.clamp(); + if (tui.config().follow_cursor_on_buffer_switch) + self.clamp(); } fn init(self: *Self, allocator: Allocator, n: Plane, buffer_manager: *Buffer.Manager) void { @@ -4715,7 +4716,8 @@ pub const Editor = struct { var file_path: []const u8 = undefined; if (ctx.args.match(.{tp.extract(&file_path)}) catch false) { try self.open(file_path); - self.clamp(); + if (tui.config().follow_cursor_on_buffer_switch) + self.clamp(); } else return error.InvalidOpenBufferFromFileArgument; } pub const open_buffer_from_file_meta: Meta = .{ .arguments = &.{.string} };