feat: add fast_scroll mode support to horizontal scrolling

Also, bump the basic scroll step to 5 columns like other editors.
This commit is contained in:
CJ van den Berg 2026-01-14 11:08:17 +01:00
parent 961b88ffd5
commit a53ef127ec
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 17 additions and 7 deletions

View file

@ -29,14 +29,16 @@ pub inline fn eql(self: Self, other: Self) bool {
return self.row == other.row and self.col == other.col and self.rows == other.rows and self.cols == other.cols;
}
pub fn move_left(self: *Self) !void {
if (self.col > 0) {
self.col -= 1;
pub fn move_left(self: *Self, n: usize) error{Stop}!void {
if (self.col > n) {
self.col -= n;
} else if (self.col > 0) {
self.col = 0;
} else return error.Stop;
}
pub fn move_right(self: *Self) !void {
self.col += 1;
pub fn move_right(self: *Self, n: usize) error{Stop}!void {
self.col += n;
}
pub fn move_up(self: *Self) !void {

View file

@ -37,6 +37,8 @@ const Allocator = std.mem.Allocator;
const time = std.time;
const scroll_step_small = 3;
const scroll_step_horizontal = 5;
const scroll_step_horizontal_fast = scroll_step_horizontal * 5;
const scroll_cursor_min_border_distance = 5;
const double_click_time_ms = 350;
@ -4150,12 +4152,18 @@ pub const Editor = struct {
pub const move_scroll_down_meta: Meta = .{ .description = "Move and scroll down", .arguments = &.{.integer} };
pub fn move_scroll_left(self: *Self, _: Context) Result {
self.view.move_left() catch {};
if (self.fast_scroll)
self.view.move_left(scroll_step_horizontal_fast) catch {}
else
self.view.move_left(scroll_step_horizontal) catch {};
}
pub const move_scroll_left_meta: Meta = .{ .description = "Scroll left" };
pub fn move_scroll_right(self: *Self, _: Context) Result {
self.view.move_right() catch {};
if (self.fast_scroll)
self.view.move_right(scroll_step_horizontal_fast) catch {}
else
self.view.move_right(scroll_step_horizontal) catch {};
}
pub const move_scroll_right_meta: Meta = .{ .description = "Scroll right" };