fix: separate mouse and keyboard scrolling commands

So that fast_scroll and alt_scroll modes apply *only* to mouse inputs.

see #507
This commit is contained in:
CJ van den Berg 2026-02-18 14:50:17 +01:00
parent f11b99b5ad
commit 767d3a5bfd
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 30 additions and 24 deletions

View file

@ -3021,25 +3021,23 @@ pub const Editor = struct {
self.update_scroll_dest_abs(dest_row); self.update_scroll_dest_abs(dest_row);
} }
pub fn scroll_up_pageup(self: *Self, ctx: Context) Result { pub fn mouse_scroll_up(self: *Self) void {
if (tui.alt_scroll()) if (tui.alt_scroll())
try self.move_scroll_left(ctx) self.mouse_scroll_left()
else if (tui.fast_scroll()) else if (tui.fast_scroll())
self.scroll_pageup() self.scroll_pageup()
else else
self.scroll_up(); self.scroll_up();
} }
pub const scroll_up_pageup_meta: Meta = .{};
pub fn scroll_down_pagedown(self: *Self, ctx: Context) Result { pub fn mouse_scroll_down(self: *Self) void {
if (tui.alt_scroll()) if (tui.alt_scroll())
try self.move_scroll_right(ctx) self.mouse_scroll_right()
else if (tui.fast_scroll()) else if (tui.fast_scroll())
self.scroll_pagedown() self.scroll_pagedown()
else else
self.scroll_down(); self.scroll_down();
} }
pub const scroll_down_pagedown_meta: Meta = .{};
pub fn scroll_to(self: *Self, row: usize) void { pub fn scroll_to(self: *Self, row: usize) void {
self.update_scroll_dest_abs(row); self.update_scroll_dest_abs(row);
@ -4398,25 +4396,33 @@ pub const Editor = struct {
pub const move_scroll_down_meta: Meta = .{ .description = "Move and scroll down", .arguments = &.{.integer} }; pub const move_scroll_down_meta: Meta = .{ .description = "Move and scroll down", .arguments = &.{.integer} };
pub fn move_scroll_left(self: *Self, _: Context) Result { pub fn move_scroll_left(self: *Self, _: Context) Result {
const scroll_step_horizontal = tui.config().scroll_step_horizontal; self.view.move_left(tui.config().scroll_step_horizontal) catch {};
const scroll_step_horizontal_fast = scroll_step_horizontal * 5;
if (tui.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 const move_scroll_left_meta: Meta = .{ .description = "Scroll left" };
pub fn move_scroll_right(self: *Self, _: Context) Result { pub fn move_scroll_right(self: *Self, _: Context) Result {
const scroll_step_horizontal = tui.config().scroll_step_horizontal; self.view.move_right(tui.config().scroll_step_horizontal) catch {};
const scroll_step_horizontal_fast = scroll_step_horizontal * 5;
if (tui.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" }; pub const move_scroll_right_meta: Meta = .{ .description = "Scroll right" };
pub fn mouse_scroll_left(self: *Self) void {
const scroll_step_horizontal = tui.config().scroll_step_horizontal;
const scroll_step_horizontal_fast = scroll_step_horizontal * 5;
self.view.move_left(if (tui.fast_scroll())
scroll_step_horizontal_fast
else
scroll_step_horizontal) catch {};
}
pub fn mouse_scroll_right(self: *Self) void {
const scroll_step_horizontal = tui.config().scroll_step_horizontal;
const scroll_step_horizontal_fast = scroll_step_horizontal * 5;
self.view.move_right(if (tui.fast_scroll())
scroll_step_horizontal_fast
else
scroll_step_horizontal) catch {};
}
pub fn move_scroll_page_up(self: *Self, _: Context) Result { pub fn move_scroll_page_up(self: *Self, _: Context) Result {
if (self.screen_cursor(&self.get_primary().cursor)) |cursor| { if (self.screen_cursor(&self.get_primary().cursor)) |cursor| {
const root = try self.buf_root(); const root = try self.buf_root();
@ -7533,19 +7539,19 @@ pub const EditorWidget = struct {
} }
fn mouse_click_button4(self: *Self, _: c_int, _: c_int, _: c_int, _: c_int) Result { fn mouse_click_button4(self: *Self, _: c_int, _: c_int, _: c_int, _: c_int) Result {
try self.editor.scroll_up_pageup(.{}); self.editor.mouse_scroll_up();
} }
fn mouse_click_button5(self: *Self, _: c_int, _: c_int, _: c_int, _: c_int) Result { fn mouse_click_button5(self: *Self, _: c_int, _: c_int, _: c_int, _: c_int) Result {
try self.editor.scroll_down_pagedown(.{}); self.editor.mouse_scroll_down();
} }
fn mouse_click_button6(self: *Self, _: c_int, _: c_int, _: c_int, _: c_int) Result { fn mouse_click_button6(self: *Self, _: c_int, _: c_int, _: c_int, _: c_int) Result {
try self.editor.move_scroll_left(.{}); self.editor.mouse_scroll_left();
} }
fn mouse_click_button7(self: *Self, _: c_int, _: c_int, _: c_int, _: c_int) Result { fn mouse_click_button7(self: *Self, _: c_int, _: c_int, _: c_int, _: c_int) Result {
try self.editor.move_scroll_right(.{}); self.editor.mouse_scroll_right();
} }
fn mouse_click_button8(_: *Self, _: c_int, _: c_int, _: c_int, _: c_int) Result { fn mouse_click_button8(_: *Self, _: c_int, _: c_int, _: c_int, _: c_int) Result {

View file

@ -369,12 +369,12 @@ fn middle_click(_: *Self) error{Exit}!bool {
} }
fn mouse_click_button4(self: *Self) error{Exit}!bool { fn mouse_click_button4(self: *Self) error{Exit}!bool {
self.editor.scroll_up_pageup(.{}) catch {}; self.editor.mouse_scroll_up();
return true; return true;
} }
fn mouse_click_button5(self: *Self) error{Exit}!bool { fn mouse_click_button5(self: *Self) error{Exit}!bool {
self.editor.scroll_down_pagedown(.{}) catch {}; self.editor.mouse_scroll_down();
return true; return true;
} }