Compare commits

...

7 commits

Author SHA1 Message Date
1dc0fcf9b5
feat: scroll editor horizontally when in alt scroll mode 2026-01-14 11:11:19 +01:00
6828b24367
feat: add enable/disable_alt_scroll commands 2026-01-14 11:10:46 +01:00
385478741f
refactor: reset alt_scroll mode on mode change 2026-01-14 11:10:02 +01:00
a53ef127ec
feat: add fast_scroll mode support to horizontal scrolling
Also, bump the basic scroll step to 5 columns like other editors.
2026-01-14 11:09:42 +01:00
961b88ffd5
refactor: do not report missing commands for alt_scroll mode bindings 2026-01-14 11:06:48 +01:00
7c0d841bb6
refactor: add enable/disalb_alt_scroll keybinds to flow mode 2026-01-14 11:05:52 +01:00
15b582243c
fix: ignore modifiers on all modifier keys
This allows combining of modifier key event keybindings without having
to bind all modifier combinations. ie. with this we can use fast_scroll
and jump_mode at the same time by holding both modifiers down.
2026-01-14 11:03:46 +01:00
7 changed files with 55 additions and 17 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

@ -207,6 +207,8 @@ pub fn get_icon(id: ID) ?[]const u8 {
const suppressed_errors = std.StaticStringMap(void).initComptime(.{
.{ "enable_fast_scroll", void },
.{ "disable_fast_scroll", void },
.{ "enable_alt_scroll", void },
.{ "disable_alt_scroll", void },
.{ "clear_diagnostics", void },
.{ "palette_menu_cancel", void },
});

View file

@ -255,13 +255,17 @@
["left_control", "enable_jump_mode"],
["right_control", "enable_jump_mode"],
["left_alt", "enable_fast_scroll"],
["right_alt", "enable_fast_scroll"]
["right_alt", "enable_fast_scroll"],
["left_shift", "enable_alt_scroll"],
["right_shift", "enable_alt_scroll"]
],
"release": [
["left_control", "disable_jump_mode"],
["right_control", "disable_jump_mode"],
["left_alt", "disable_fast_scroll"],
["right_alt", "disable_fast_scroll"]
["right_alt", "disable_fast_scroll"],
["left_shift", "disable_alt_scroll"],
["right_shift", "disable_alt_scroll"]
]
},
"select": {

View file

@ -717,6 +717,9 @@ const BindingSet = struct {
const mods = switch (key_event.key) {
input.key.left_control, input.key.right_control => 0,
input.key.left_alt, input.key.right_alt => 0,
input.key.left_shift, input.key.right_shift => 0,
input.key.left_super, input.key.right_super => 0,
input.key.iso_level_3_shift, input.key.iso_level_5_shift => 0,
else => switch (mode_flag) {
.ignore_alt_text_modifiers => if (std.mem.eql(u8, text, codepoint)) key_event.modifiers else 0,
.normal => key_event.modifiers,

View file

@ -126,10 +126,11 @@ pub const KeyEvent = struct {
modifiers: Mods,
) @This() {
const mods_ = switch (keypress_) {
key.left_super, key.right_super => modifiers & ~mod.super,
key.left_shift, key.right_shift => modifiers & ~mod.shift,
key.left_control, key.right_control => modifiers & ~mod.ctrl,
key.left_alt, key.right_alt => modifiers & ~mod.alt,
key.left_control, key.right_control => 0,
key.left_alt, key.right_alt => 0,
key.left_shift, key.right_shift => 0,
key.left_super, key.right_super => 0,
key.iso_level_3_shift, key.iso_level_5_shift => 0,
else => modifiers,
};

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;
@ -371,6 +373,7 @@ pub const Editor = struct {
handlers: EventHandler.List,
scroll_dest: usize = 0,
fast_scroll: bool = false,
alt_scroll: bool = false,
jump_mode: bool = false,
animation_step: usize = 0,
@ -2791,16 +2794,20 @@ pub const Editor = struct {
self.update_scroll_dest_abs(dest.row);
}
pub fn scroll_up_pageup(self: *Self, _: Context) Result {
if (self.fast_scroll)
pub fn scroll_up_pageup(self: *Self, ctx: Context) Result {
if (self.alt_scroll)
try self.move_scroll_left(ctx)
else if (self.fast_scroll)
self.scroll_pageup()
else
self.scroll_up();
}
pub const scroll_up_pageup_meta: Meta = .{};
pub fn scroll_down_pagedown(self: *Self, _: Context) Result {
if (self.fast_scroll)
pub fn scroll_down_pagedown(self: *Self, ctx: Context) Result {
if (self.alt_scroll)
try self.move_scroll_right(ctx)
else if (self.fast_scroll)
self.scroll_pagedown()
else
self.scroll_down();
@ -4150,12 +4157,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" };
@ -5090,6 +5103,16 @@ pub const Editor = struct {
}
pub const disable_fast_scroll_meta: Meta = .{};
pub fn enable_alt_scroll(self: *Self, _: Context) Result {
self.alt_scroll = true;
}
pub const enable_alt_scroll_meta: Meta = .{ .description = "Enable horizontal scroll mode" };
pub fn disable_alt_scroll(self: *Self, _: Context) Result {
self.alt_scroll = false;
}
pub const disable_alt_scroll_meta: Meta = .{};
pub fn enable_jump_mode(self: *Self, _: Context) Result {
self.jump_mode = true;
tui.rdr().request_mouse_cursor_pointer(true);

View file

@ -882,6 +882,7 @@ pub fn is_mainview_focused() bool {
fn enter_overlay_mode(self: *Self, mode: type) command.Result {
command.executeName("disable_fast_scroll", .{}) catch {};
command.executeName("disable_alt_scroll", .{}) catch {};
command.executeName("disable_jump_mode", .{}) catch {};
if (self.mini_mode_) |_| try cmds.exit_mini_mode(self, .{});
if (self.input_mode_outer_) |_| try cmds.exit_overlay_mode(self, .{});
@ -894,6 +895,7 @@ fn enter_overlay_mode(self: *Self, mode: type) command.Result {
fn enter_overlay_mode_with_args(self: *Self, mode: type, ctx: command.Context) command.Result {
command.executeName("disable_fast_scroll", .{}) catch {};
command.executeName("disable_alt_scroll", .{}) catch {};
command.executeName("disable_jump_mode", .{}) catch {};
if (self.mini_mode_) |_| try cmds.exit_mini_mode(self, .{});
if (self.input_mode_outer_) |_| try cmds.exit_overlay_mode(self, .{});
@ -1469,6 +1471,7 @@ const cmds = struct {
fn enter_mini_mode(self: *Self, comptime mode: anytype, ctx: Ctx) !void {
command.executeName("disable_fast_scroll", .{}) catch {};
command.executeName("disable_alt_scroll", .{}) catch {};
command.executeName("disable_jump_mode", .{}) catch {};
if (self.mini_mode_) |_| try exit_mini_mode(self, .{});
if (self.input_mode_outer_) |_| try exit_overlay_mode(self, .{});