feat: implement scroll_view_center_cycle to replace cmd_cycle3

This commit is contained in:
CJ van den Berg 2024-11-17 22:43:14 +01:00
parent 43c49125f8
commit e172590ba8
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
13 changed files with 33 additions and 95 deletions

View file

@ -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"],

View file

@ -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" },

View file

@ -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_ });

View file

@ -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" },

View file

@ -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" },

View file

@ -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_ });

View file

@ -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" },

View file

@ -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" },

View file

@ -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", .{}),

View file

@ -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", .{}),

View file

@ -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", .{}),

View file

@ -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 => {},
},

View file

@ -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);