diff --git a/src/buffer/View.zig b/src/buffer/View.zig index c6579ad..a11e54e 100644 --- a/src/buffer/View.zig +++ b/src/buffer/View.zig @@ -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 { diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 712392d..e126bbc 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -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" };