diff --git a/src/keybind/dynamic/keybindings.json b/src/keybind/dynamic/keybindings.json index 0d1bf94..4c96c25 100644 --- a/src/keybind/dynamic/keybindings.json +++ b/src/keybind/dynamic/keybindings.json @@ -13,7 +13,7 @@ ["ctrl+o", "open_file"], ["ctrl+w", "close_file"], ["ctrl+s", "save_file"], - ["ctrl+l", "cmd_cycle3", "scroll_view_center", "scroll_view_top", "scroll_view_bottom"], + ["ctrl+l", "scroll_view_center_cycle"], ["ctrl+n", "goto_next_match"], ["ctrl+p", "goto_prev_match"], ["ctrl+b", "move_to_char", false], @@ -245,7 +245,7 @@ ["ctrl+u", "mini_mode_reset"], ["ctrl+g", "mini_mode_cancel"], ["ctrl+c", "mini_mode_cancel"], - ["ctrl+l", "scroll_view_center"], + ["ctrl+l", "scroll_view_center_cycle"], ["ctrl+space", "mini_mode_cancel"], ["escape", "mini_mode_cancel"], @@ -278,7 +278,7 @@ ["ctrl+u", "mini_mode_reset"], ["ctrl+g", "mini_mode_cancel"], ["ctrl+c", "mini_mode_cancel"], - ["ctrl+l", "scroll_view_center"], + ["ctrl+l", "scroll_view_center_cycle"], ["ctrl+i", "mini_mode_insert_bytes", "\t"], ["ctrl+space", "mini_mode_cancel"], ["ctrl+backspace", "mini_mode_delete_to_previous_path_segment"], @@ -307,7 +307,7 @@ ["ctrl+u", "mini_mode_reset"], ["ctrl+g", "exit_mini_mode"], ["ctrl+c", "exit_mini_mode"], - ["ctrl+l", "scroll_view_center"], + ["ctrl+l", "scroll_view_center_cycle"], ["ctrl+f", "goto_next_match"], ["ctrl+n", "goto_next_match"], ["ctrl+p", "goto_prev_match"], @@ -344,7 +344,7 @@ ["ctrl+u", "mini_mode_reset"], ["ctrl+g", "mini_mode_cancel"], ["ctrl+c", "mini_mode_cancel"], - ["ctrl+l", "scroll_view_center"], + ["ctrl+l", "scroll_view_center_cycle"], ["ctrl+f", "goto_next_match"], ["ctrl+n", "goto_next_match"], ["ctrl+p", "goto_prev_match"], diff --git a/src/keybind/static/input/flow.zig b/src/keybind/static/input/flow.zig index 5454ce2..fafe566 100644 --- a/src/keybind/static/input/flow.zig +++ b/src/keybind/static/input/flow.zig @@ -74,7 +74,7 @@ fn map_press(self: *Self, keypress: input.Key, egc: input.Key, modifiers: input. 'O' => self.cmd("open_file", .{}), 'W' => self.cmd("close_file", .{}), 'S' => self.cmd("save_file", .{}), - 'L' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), + 'L' => self.cmd("scroll_view_center_cycle", .{}), 'N' => self.cmd("goto_next_match", .{}), 'P' => self.cmd("goto_prev_match", .{}), 'B' => self.cmd("move_to_char", command.fmt(.{false})), @@ -289,15 +289,6 @@ fn cmd(self: *Self, name_: []const u8, ctx: command.Context) tp.result { try command.executeName(name_, ctx); } -fn cmd_cycle3(self: *Self, name1: []const u8, name2: []const u8, name3: []const u8, ctx: command.Context) tp.result { - return if (std.mem.eql(u8, self.last_cmd, name2)) - self.cmd(name3, ctx) - else if (std.mem.eql(u8, self.last_cmd, name1)) - self.cmd(name2, ctx) - else - self.cmd(name1, ctx); -} - fn cmd_async(self: *Self, name_: []const u8) tp.result { self.last_cmd = name_; return tp.self_pid().send(.{ "cmd", name_ }); @@ -382,9 +373,7 @@ pub const hints = keybind.KeybindHints.initComptime(.{ .{ "references", "S-F12" }, .{ "save_as", "C-S-s" }, .{ "save_file", "C-s" }, - .{ "scroll_view_bottom", "C-l" }, - .{ "scroll_view_center", "C-l" }, - .{ "scroll_view_top", "C-l" }, + .{ "scroll_view_center_cycle", "C-l" }, .{ "select_all", "C-a" }, .{ "select_buffer_begin", "C-S-home" }, .{ "select_buffer_end", "C-S-end" }, diff --git a/src/keybind/static/input/helix/insert.zig b/src/keybind/static/input/helix/insert.zig index 52515ea..c1fa36f 100644 --- a/src/keybind/static/input/helix/insert.zig +++ b/src/keybind/static/input/helix/insert.zig @@ -79,7 +79,7 @@ fn map_press(self: *Self, keypress: input.Key, egc: input.Key, modifiers: input. 'Q' => self.cmd("quit", .{}), 'W' => self.cmd("close_file", .{}), 'S' => self.cmd("save_file", .{}), - 'L' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), + 'L' => self.cmd("scroll_view_center_cycle", .{}), 'N' => self.cmd("goto_next_match", .{}), 'P' => self.cmd("goto_prev_match", .{}), 'B' => self.cmd("move_to_char", command.fmt(.{false})), @@ -272,15 +272,6 @@ fn cmd(self: *Self, name_: []const u8, ctx: command.Context) tp.result { try command.executeName(name_, ctx); } -fn cmd_cycle3(self: *Self, name1: []const u8, name2: []const u8, name3: []const u8, ctx: command.Context) tp.result { - return if (std.mem.eql(u8, self.last_cmd, name2)) - self.cmd(name3, ctx) - else if (std.mem.eql(u8, self.last_cmd, name1)) - self.cmd(name2, ctx) - else - self.cmd(name1, ctx); -} - fn cmd_async(self: *Self, name_: []const u8) tp.result { self.last_cmd = name_; return tp.self_pid().send(.{ "cmd", name_ }); diff --git a/src/keybind/static/input/helix/normal.zig b/src/keybind/static/input/helix/normal.zig index c0668a8..b3ae253 100644 --- a/src/keybind/static/input/helix/normal.zig +++ b/src/keybind/static/input/helix/normal.zig @@ -489,15 +489,6 @@ fn cmd_count(self: *Self, name_: []const u8, ctx: command.Context) tp.result { try command.executeName(name_, ctx); } -fn cmd_cycle3(self: *Self, name1: []const u8, name2: []const u8, name3: []const u8, ctx: command.Context) tp.result { - return if (std.mem.eql(u8, self.last_cmd, name2)) - self.cmd(name3, ctx) - else if (std.mem.eql(u8, self.last_cmd, name1)) - self.cmd(name2, ctx) - else - self.cmd(name1, ctx); -} - fn cmd_async(self: *Self, name_: []const u8) tp.result { self.last_cmd = name_; return tp.self_pid().send(.{ "cmd", name_ }); @@ -600,9 +591,7 @@ pub const hints = keybind.KeybindHints.initComptime(.{ .{ "quit_without_saving", "C-S-q" }, .{ "redo", "C-S-z, C-y" }, .{ "save_file", "C-s" }, - .{ "scroll_view_bottom", "C-l, z z" }, - .{ "scroll_view_center", "C-l, z z" }, - .{ "scroll_view_top", "C-l, z z" }, + .{ "scroll_view_center_cycle", "C-l, z z" }, .{ "select_all", "C-a" }, .{ "select_buffer_begin", "C-S-home" }, .{ "select_buffer_end", "C-S-end" }, diff --git a/src/keybind/static/input/helix/select.zig b/src/keybind/static/input/helix/select.zig index 980f54f..2d968ca 100644 --- a/src/keybind/static/input/helix/select.zig +++ b/src/keybind/static/input/helix/select.zig @@ -489,15 +489,6 @@ fn cmd_count(self: *Self, name_: []const u8, ctx: command.Context) tp.result { try command.executeName(name_, ctx); } -fn cmd_cycle3(self: *Self, name1: []const u8, name2: []const u8, name3: []const u8, ctx: command.Context) tp.result { - return if (std.mem.eql(u8, self.last_cmd, name2)) - self.cmd(name3, ctx) - else if (std.mem.eql(u8, self.last_cmd, name1)) - self.cmd(name2, ctx) - else - self.cmd(name1, ctx); -} - fn cmd_async(self: *Self, name_: []const u8) tp.result { self.last_cmd = name_; return tp.self_pid().send(.{ "cmd", name_ }); @@ -600,9 +591,7 @@ pub const hints = keybind.KeybindHints.initComptime(.{ .{ "quit_without_saving", "C-S-q" }, .{ "redo", "C-S-z, C-y" }, .{ "save_file", "C-s" }, - .{ "scroll_view_bottom", "C-l, z z" }, - .{ "scroll_view_center", "C-l, z z" }, - .{ "scroll_view_top", "C-l, z z" }, + .{ "scroll_view_center_cycle", "C-l, z z" }, .{ "select_all", "C-a" }, .{ "select_buffer_begin", "C-S-home" }, .{ "select_buffer_end", "C-S-end" }, diff --git a/src/keybind/static/input/vim/insert.zig b/src/keybind/static/input/vim/insert.zig index e258fa9..1061abb 100644 --- a/src/keybind/static/input/vim/insert.zig +++ b/src/keybind/static/input/vim/insert.zig @@ -129,7 +129,7 @@ fn map_press(self: *Self, keypress: input.Key, egc: input.Key, modifiers: input. 'Q' => self.cmd("quit", .{}), 'W' => self.cmd("close_file", .{}), 'S' => self.cmd("save_file", .{}), - 'L' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), + 'L' => self.cmd("scroll_view_center_cycle", .{}), 'N' => self.cmd("goto_next_match", .{}), 'P' => self.cmd("goto_prev_match", .{}), 'B' => self.cmd("move_to_char", command.fmt(.{false})), @@ -323,15 +323,6 @@ fn cmd(self: *Self, name_: []const u8, ctx: command.Context) tp.result { try command.executeName(name_, ctx); } -fn cmd_cycle3(self: *Self, name1: []const u8, name2: []const u8, name3: []const u8, ctx: command.Context) tp.result { - return if (std.mem.eql(u8, self.last_cmd, name2)) - self.cmd(name3, ctx) - else if (std.mem.eql(u8, self.last_cmd, name1)) - self.cmd(name2, ctx) - else - self.cmd(name1, ctx); -} - fn cmd_async(self: *Self, name_: []const u8) tp.result { self.last_cmd = name_; return tp.self_pid().send(.{ "cmd", name_ }); diff --git a/src/keybind/static/input/vim/normal.zig b/src/keybind/static/input/vim/normal.zig index d0a455b..f88b3a8 100644 --- a/src/keybind/static/input/vim/normal.zig +++ b/src/keybind/static/input/vim/normal.zig @@ -85,7 +85,7 @@ fn mapPress(self: *Self, keypress: input.Key, egc: input.Key, modifiers: input.M 'Q' => self.cmd("quit", .{}), 'W' => self.cmd("close_file", .{}), 'S' => self.cmd("save_file", .{}), - 'L' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), + 'L' => self.cmd("scroll_view_center_cycle", .{}), 'N' => self.cmd("goto_next_match", .{}), 'P' => self.cmd("goto_prev_match", .{}), 'B' => self.cmd("move_to_char", command.fmt(.{false})), @@ -354,7 +354,7 @@ fn mapFollower(self: *Self, keypress: input.Key, egc: input.Key, modifiers: inpu }, 'Z' => switch (modifiers) { 0 => switch (keypress) { - 'Z' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), + 'Z' => self.cmd("scroll_view_center_cycle", .{}), else => {}, }, else => {}, @@ -455,15 +455,6 @@ fn cmd_count(self: *Self, name_: []const u8, ctx: command.Context) tp.result { try command.executeName(name_, ctx); } -fn cmd_cycle3(self: *Self, name1: []const u8, name2: []const u8, name3: []const u8, ctx: command.Context) tp.result { - return if (std.mem.eql(u8, self.last_cmd, name2)) - self.cmd(name3, ctx) - else if (std.mem.eql(u8, self.last_cmd, name1)) - self.cmd(name2, ctx) - else - self.cmd(name1, ctx); -} - fn cmd_async(self: *Self, name_: []const u8) tp.result { self.last_cmd = name_; return tp.self_pid().send(.{ "cmd", name_ }); @@ -566,9 +557,7 @@ pub const hints = keybind.KeybindHints.initComptime(.{ .{ "quit_without_saving", "C-S-q" }, .{ "redo", "C-S-z, C-y" }, .{ "save_file", "C-s" }, - .{ "scroll_view_bottom", "C-l, z z" }, - .{ "scroll_view_center", "C-l, z z" }, - .{ "scroll_view_top", "C-l, z z" }, + .{ "scroll_view_center_cycle", "C-l, z z" }, .{ "select_all", "C-a" }, .{ "select_buffer_begin", "C-S-home" }, .{ "select_buffer_end", "C-S-end" }, diff --git a/src/keybind/static/input/vim/visual.zig b/src/keybind/static/input/vim/visual.zig index 4a62969..3d494a6 100644 --- a/src/keybind/static/input/vim/visual.zig +++ b/src/keybind/static/input/vim/visual.zig @@ -85,7 +85,7 @@ fn map_press(self: *Self, keypress: input.Key, egc: input.Key, modifiers: input. 'Q' => self.cmd("quit", .{}), 'W' => self.cmd("close_file", .{}), 'S' => self.cmd("save_file", .{}), - 'L' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), + 'L' => self.cmd("scroll_view_center_cycle", .{}), 'N' => self.cmd("goto_next_match", .{}), 'P' => self.cmd("goto_prev_match", .{}), 'B' => self.cmd("move_to_char", command.fmt(.{false})), @@ -332,7 +332,7 @@ fn mapFollower(self: *Self, keypress: input.Key, egc: input.Key, modifiers: inpu }, 'Z' => switch (modifiers) { 0 => switch (keypress) { - 'Z' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), + 'Z' => self.cmd("scroll_view_center_cycle", .{}), else => {}, }, else => {}, @@ -406,15 +406,6 @@ fn cmd_count(self: *Self, name_: []const u8, ctx: command.Context) tp.result { try command.executeName(name_, ctx); } -fn cmd_cycle3(self: *Self, name1: []const u8, name2: []const u8, name3: []const u8, ctx: command.Context) tp.result { - return if (std.mem.eql(u8, self.last_cmd, name2)) - self.cmd(name3, ctx) - else if (std.mem.eql(u8, self.last_cmd, name1)) - self.cmd(name2, ctx) - else - self.cmd(name1, ctx); -} - fn cmd_async(self: *Self, name_: []const u8) tp.result { self.last_cmd = name_; return tp.self_pid().send(.{ "cmd", name_ }); @@ -514,9 +505,7 @@ pub const hints = keybind.KeybindHints.initComptime(.{ .{ "quit_without_saving", "C-S-q" }, .{ "redo", "C-S-z, C-y" }, .{ "save_file", "C-s" }, - .{ "scroll_view_bottom", "C-l, z z" }, - .{ "scroll_view_center", "C-l, z z" }, - .{ "scroll_view_top", "C-l, z z" }, + .{ "scroll_view_center_cycle", "C-l, z z" }, .{ "select_all", "C-a" }, .{ "select_buffer_begin", "C-S-home" }, .{ "select_buffer_end", "C-S-end" }, diff --git a/src/keybind/static/mini/file_browser.zig b/src/keybind/static/mini/file_browser.zig index a0d138a..f86525c 100644 --- a/src/keybind/static/mini/file_browser.zig +++ b/src/keybind/static/mini/file_browser.zig @@ -36,7 +36,7 @@ fn map_press(keypress: input.Key, egc: input.Key, modifiers: input.Mods) !void { 'U' => command.executeName("mini_mode_reset", .{}), 'G' => command.executeName("mini_mode_cancel", .{}), 'C' => command.executeName("mini_mode_cancel", .{}), - 'L' => command.executeName("scroll_view_center", .{}), + 'L' => command.executeName("scroll_view_center_cycle", .{}), 'I' => command.executeName("mini_mode_insert_bytes", command.fmt(.{"\t"})), input.key.space => command.executeName("mini_mode_cancel", .{}), input.key.backspace => command.executeName("mini_mode_delete_to_previous_path_segment", .{}), diff --git a/src/keybind/static/mini/find.zig b/src/keybind/static/mini/find.zig index 67ab2b4..9db7a09 100644 --- a/src/keybind/static/mini/find.zig +++ b/src/keybind/static/mini/find.zig @@ -36,7 +36,7 @@ fn map_press(keypress: input.Key, egc: input.Key, modifiers: input.Mods) !void { 'U' => command.executeName("mini_mode_reset", .{}), 'G' => command.executeName("mini_mode_cancel", .{}), 'C' => command.executeName("mini_mode_cancel", .{}), - 'L' => command.executeName("scroll_view_center", .{}), + 'L' => command.executeName("scroll_view_center_cycle", .{}), 'F' => command.executeName("goto_next_match", .{}), 'N' => command.executeName("goto_next_match", .{}), 'P' => command.executeName("goto_prev_match", .{}), diff --git a/src/keybind/static/mini/find_in_files.zig b/src/keybind/static/mini/find_in_files.zig index b0483aa..b3ac04f 100644 --- a/src/keybind/static/mini/find_in_files.zig +++ b/src/keybind/static/mini/find_in_files.zig @@ -37,7 +37,7 @@ fn map_press(keypress: input.Key, egc: input.Key, modifiers: input.Mods) !void { 'U' => command.executeName("mini_mode_reset", .{}), 'G' => command.executeName("exit_mini_mode", .{}), 'C' => command.executeName("exit_mini_mode", .{}), - 'L' => command.executeName("scroll_view_center", .{}), + 'L' => command.executeName("scroll_view_center_cycle", .{}), 'F' => command.executeName("goto_next_match", .{}), 'N' => command.executeName("goto_next_match", .{}), 'P' => command.executeName("goto_prev_match", .{}), diff --git a/src/keybind/static/mini/goto.zig b/src/keybind/static/mini/goto.zig index f9f202e..26f4a1f 100644 --- a/src/keybind/static/mini/goto.zig +++ b/src/keybind/static/mini/goto.zig @@ -33,7 +33,7 @@ fn map_press(keypress: input.Key, modifiers: input.Mods) tp.result { 'U' => command.executeName("mini_mode_reset", .{}), 'G' => command.executeName("mini_mode_cancel", .{}), 'C' => command.executeName("mini_mode_cancel", .{}), - 'L' => command.executeName("scroll_view_center", .{}), + 'L' => command.executeName("scroll_view_center_cycle", .{}), input.key.space => command.executeName("mini_mode_cancel", .{}), else => {}, }, diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 72e9955..b2234bb 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -1943,7 +1943,18 @@ pub const Editor = struct { pub fn scroll_view_center(self: *Self, _: Context) Result { return self.scroll_view_offset(self.view.rows / 2); } - pub const scroll_view_center_meta = .{ .description = "Scroll cursor to center/top/bottom of view" }; + pub const scroll_view_center_meta = .{ .description = "Scroll cursor to center of view" }; + + pub fn scroll_view_center_cycle(self: *Self, _: Context) Result { + const cursor_row = self.get_primary().cursor.row; + return if (cursor_row == self.view.row + scroll_cursor_min_border_distance) + self.scroll_view_bottom(.{}) + else if (cursor_row == self.view.row + self.view.rows / 2) + self.scroll_view_top(.{}) + else + self.scroll_view_offset(self.view.rows / 2); + } + pub const scroll_view_center_cycle_meta = .{ .description = "Scroll cursor to center/top/bottom of view" }; pub fn scroll_view_top(self: *Self, _: Context) Result { return self.scroll_view_offset(scroll_cursor_min_border_distance);