feat: allow runtime changing of the gutter mode
This commit is contained in:
parent
f61701150d
commit
9aea1f54f5
7 changed files with 37 additions and 1 deletions
|
@ -89,6 +89,8 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
|||
|
||||
if (try m.match(.{ "B", nc.event_type.PRESS, nc.key.BUTTON1, tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) }))
|
||||
return self.primary_click(y);
|
||||
if (try m.match(.{ "B", nc.event_type.PRESS, nc.key.BUTTON3, tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) }))
|
||||
return self.secondary_click();
|
||||
if (try m.match(.{ "D", nc.event_type.PRESS, nc.key.BUTTON1, tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) }))
|
||||
return self.primary_drag(y);
|
||||
if (try m.match(.{ "B", nc.event_type.PRESS, nc.key.BUTTON4, tp.more }))
|
||||
|
@ -232,6 +234,11 @@ fn primary_drag(_: *const Self, y: i32) error{Exit}!bool {
|
|||
return true;
|
||||
}
|
||||
|
||||
fn secondary_click(_: *Self) error{Exit}!bool {
|
||||
try command.executeName("gutter_mode_next", .{});
|
||||
return true;
|
||||
}
|
||||
|
||||
fn mouse_click_button4(_: *Self) error{Exit}!bool {
|
||||
try command.executeName("scroll_up_pageup", .{});
|
||||
return true;
|
||||
|
|
|
@ -262,6 +262,31 @@ const cmds = struct {
|
|||
pub fn show_home(self: *Self, _: Ctx) tp.result {
|
||||
return self.create_home();
|
||||
}
|
||||
|
||||
pub fn gutter_mode_next(self: *Self, _: Ctx) tp.result {
|
||||
const tui_ = tui.current();
|
||||
var ln = tui_.config.gutter_line_numbers;
|
||||
var lnr = tui_.config.gutter_line_numbers_relative;
|
||||
if (ln and !lnr) {
|
||||
ln = true;
|
||||
lnr = true;
|
||||
} else if (ln and lnr) {
|
||||
ln = false;
|
||||
lnr = false;
|
||||
} else {
|
||||
ln = true;
|
||||
lnr = false;
|
||||
}
|
||||
tui_.config.gutter_line_numbers = ln;
|
||||
tui_.config.gutter_line_numbers_relative = lnr;
|
||||
tui_.save_config() catch |e| return tp.exit_error(e);
|
||||
if (self.widgets.get("editor_gutter")) |gutter_widget| {
|
||||
const gutter = if (gutter_widget.dynamic_cast(@import("editor_gutter.zig"))) |p| p else return;
|
||||
gutter.linenum = ln;
|
||||
gutter.relative = lnr;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result {
|
||||
|
|
|
@ -193,6 +193,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
|||
key.F11 => self.cmd("toggle_logview", .{}),
|
||||
key.F12 => self.cmd("goto_definition", .{}),
|
||||
key.F34 => self.cmd("toggle_whitespace", .{}), // C-F10
|
||||
key.F58 => self.cmd("gutter_mode_next", .{}), // A-F10
|
||||
key.ESC => self.cmd("cancel", .{}),
|
||||
key.ENTER => self.cmd("smart_insert_line", .{}),
|
||||
key.DEL => self.cmd("delete_forward", .{}),
|
||||
|
|
|
@ -194,6 +194,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
|||
key.F11 => self.cmd("toggle_logview", .{}),
|
||||
key.F12 => self.cmd("goto_definition", .{}),
|
||||
key.F34 => self.cmd("toggle_whitespace", .{}), // C-F10
|
||||
key.F58 => self.cmd("gutter_mode_next", .{}), // A-F10
|
||||
key.ESC => self.cmd("enter_mode", command.fmt(.{"vim/normal"})),
|
||||
key.ENTER => self.cmd("smart_insert_line", .{}),
|
||||
key.DEL => self.cmd("delete_forward", .{}),
|
||||
|
|
|
@ -213,6 +213,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
|||
key.F11 => self.cmd("toggle_logview", .{}),
|
||||
key.F12 => self.cmd("goto_definition", .{}),
|
||||
key.F34 => self.cmd("toggle_whitespace", .{}), // C-F10
|
||||
key.F58 => self.cmd("gutter_mode_next", .{}), // A-F10
|
||||
key.ESC => self.cmd("cancel", .{}),
|
||||
key.ENTER => self.cmd("smart_insert_line", .{}),
|
||||
key.DEL => self.cmd("delete_forward", .{}),
|
||||
|
|
|
@ -209,6 +209,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
|||
key.F11 => self.cmd("toggle_logview", .{}),
|
||||
key.F12 => self.cmd("goto_definition", .{}),
|
||||
key.F34 => self.cmd("toggle_whitespace", .{}), // C-F10
|
||||
key.F58 => self.cmd("gutter_mode_next", .{}), // A-F10
|
||||
key.ESC => self.seq(.{ "cancel", "enter_mode" }, command.fmt(.{"vim/normal"})),
|
||||
key.ENTER => self.cmd("smart_insert_line", .{}),
|
||||
key.DEL => self.cmd("delete_forward", .{}),
|
||||
|
|
|
@ -679,7 +679,7 @@ fn send_input(self: *Self, from: tp.pid_ref, m: tp.message) void {
|
|||
mode.handler.send(from, m) catch |e| self.logger.err("input handler", e);
|
||||
}
|
||||
|
||||
fn save_config(self: *const Self) !void {
|
||||
pub fn save_config(self: *const Self) !void {
|
||||
try root.write_config(self.config, self.a);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue