feat: add theme selection palette

Also, refactor to share palette code and make palettes scroll properly
with the mouse wheel.
This commit is contained in:
CJ van den Berg 2024-08-14 21:27:32 +02:00
parent 8c3c786357
commit 4b6c08154b
11 changed files with 675 additions and 490 deletions

View file

@ -234,6 +234,7 @@ fn mapFollower(self: *Self, keypress: u32, _: u32, modifiers: u32) !void {
'U' => self.cmd("delete_to_begin", .{}),
'K' => self.cmd("delete_to_end", .{}),
'D' => self.cmd("move_cursor_next_match", .{}),
'T' => self.cmd("change_theme", .{}),
else => {},
},
else => {},
@ -389,6 +390,7 @@ const hints = tui.KeybindHints.initComptime(.{
.{ "select_right", "S-right" },
.{ "select_scroll_down", "C-S-down" },
.{ "select_scroll_up", "C-S-up" },
.{ "change_theme", "C-k C-t" },
.{ "select_up", "S-up" },
.{ "select_word_left", "C-S-left" },
.{ "select_word_right", "C-S-right" },

View file

@ -14,6 +14,7 @@ const Self = @This();
a: std.mem.Allocator,
f: usize = 0,
leader: ?struct { keypress: u32, modifiers: u32 } = null,
pub fn create(a: std.mem.Allocator) !tui.Mode {
const self: *Self = try a.create(Self);
@ -53,6 +54,7 @@ fn mapEvent(self: *Self, evtype: u32, keypress: u32, modifiers: u32) tp.result {
fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result {
const keynormal = if ('a' <= keypress and keypress <= 'z') keypress - ('a' - 'A') else keypress;
if (self.leader) |_| return self.mapFollower(keynormal, modifiers);
return switch (modifiers) {
mod.CTRL => switch (keynormal) {
'F' => self.sheeran(),
@ -63,6 +65,7 @@ fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result {
'E' => self.cmd("open_recent", .{}),
'P' => self.cmd("open_command_palette", .{}),
'/' => self.cmd("open_help", .{}),
'K' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers },
else => {},
},
mod.CTRL | mod.SHIFT => switch (keynormal) {
@ -94,6 +97,7 @@ fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result {
'r' => self.msg("open recent project not implemented"),
'p' => self.cmd("open_command_palette", .{}),
'c' => self.cmd("open_config", .{}),
't' => self.cmd("change_theme", .{}),
'q' => self.cmd("quit", .{}),
key.F01 => self.cmd("open_help", .{}),
@ -111,6 +115,24 @@ fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result {
};
}
fn mapFollower(self: *Self, keypress: u32, modifiers: u32) !void {
defer self.leader = null;
const ldr = if (self.leader) |leader| leader else return;
return switch (ldr.modifiers) {
mod.CTRL => switch (ldr.keypress) {
'K' => switch (modifiers) {
mod.CTRL => switch (keypress) {
'T' => self.cmd("change_theme", .{}),
else => {},
},
else => {},
},
else => {},
},
else => {},
};
}
fn cmd(_: *Self, name_: []const u8, ctx: command.Context) tp.result {
try command.executeName(name_, ctx);
}
@ -146,6 +168,7 @@ const hints = tui.KeybindHints.initComptime(.{
.{ "quit", "q, C-q, C-w" },
.{ "quit_without_saving", "C-S-q" },
.{ "restart", "C-S-r" },
.{ "change_theme", "t, C-k C-t" },
.{ "theme_next", "F10" },
.{ "theme_prev", "F9" },
.{ "toggle_inputview", "F12, A-i" },

View file

@ -236,6 +236,7 @@ fn mapFollower(self: *Self, keypress: u32, _: u32, modifiers: u32) !void {
'U' => self.cmd("delete_to_begin", .{}),
'K' => self.cmd("delete_to_end", .{}),
'D' => self.cmd("move_cursor_next_match", .{}),
'T' => self.cmd("change_theme", .{}),
else => {},
},
else => {},

View file

@ -308,6 +308,7 @@ fn mapFollower(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
'U' => self.cmd("delete_to_begin", .{}),
'K' => self.cmd("delete_to_end", .{}),
'D' => self.cmd("move_cursor_next_match", .{}),
'T' => self.cmd("change_theme", .{}),
else => {},
},
else => {},
@ -580,6 +581,7 @@ const hints = tui.KeybindHints.initComptime(.{
.{ "select_right", "S-right" },
.{ "select_scroll_down", "C-S-down" },
.{ "select_scroll_up", "C-S-up" },
.{ "change_theme", "C-k C-t" },
.{ "select_up", "S-up" },
.{ "select_word_left", "C-S-left" },
.{ "select_word_right", "C-S-right" },

View file

@ -306,6 +306,7 @@ fn mapFollower(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void {
'U' => self.cmd("delete_to_begin", .{}),
'K' => self.cmd("delete_to_end", .{}),
'D' => self.cmd("move_cursor_next_match", .{}),
'T' => self.cmd("change_theme", .{}),
else => {},
},
else => {},
@ -540,6 +541,7 @@ const hints = tui.KeybindHints.initComptime(.{
.{ "select_right", "S-right" },
.{ "select_scroll_down", "C-S-down" },
.{ "select_scroll_up", "C-S-up" },
.{ "change_theme", "C-k C-t" },
.{ "select_up", "S-up" },
.{ "select_word_left", "C-S-left" },
.{ "select_word_right", "C-S-right" },