Compare commits
3 commits
563eb57e44
...
716f871d03
Author | SHA1 | Date | |
---|---|---|---|
716f871d03 | |||
63270246d9 | |||
6743c99c12 |
5 changed files with 68 additions and 41 deletions
|
@ -67,9 +67,9 @@
|
||||||
["shift+b", "move_prev_long_word_start"],
|
["shift+b", "move_prev_long_word_start"],
|
||||||
["shift+e", "move_next_long_word_end"],
|
["shift+e", "move_next_long_word_end"],
|
||||||
|
|
||||||
["shift+i", ["smart_move_begin"], ["enter_mode", "insert"]],
|
["shift+i", ["enter_mode", "insert"], ["smart_move_begin"]],
|
||||||
["shift+a", ["move_end"], ["enter_mode", "insert"]],
|
["shift+a", ["enter_mode", "insert"], ["move_end"]],
|
||||||
["shift+o", ["smart_insert_line_before"], ["enter_mode", "insert"]],
|
["shift+o", ["enter_mode", "insert"], ["smart_insert_line_before"]],
|
||||||
|
|
||||||
["shift+c", "copy_selection_on_next_line"],
|
["shift+c", "copy_selection_on_next_line"],
|
||||||
["shift+s", "split_selection"],
|
["shift+s", "split_selection"],
|
||||||
|
@ -143,11 +143,11 @@
|
||||||
["g shift+d", "goto_declaration"],
|
["g shift+d", "goto_declaration"],
|
||||||
|
|
||||||
["i", "enter_mode", "insert"],
|
["i", "enter_mode", "insert"],
|
||||||
["a", ["move_right"], ["enter_mode", "insert"]],
|
["a", ["enter_mode", "insert"], ["move_right"]],
|
||||||
["o", ["smart_insert_line_after"], ["enter_mode", "insert"]],
|
["o", ["enter_mode", "insert"], ["smart_insert_line_after"]],
|
||||||
|
|
||||||
["d", "cut_forward_internal_inclusive"],
|
["d", "cut_forward_internal_inclusive"],
|
||||||
["c", ["cut_forward_internal_inclusive"], ["enter_mode", "insert"]],
|
["c", ["enter_mode", "insert"], ["cut_forward_internal_inclusive"]],
|
||||||
|
|
||||||
["s", "select_regex"],
|
["s", "select_regex"],
|
||||||
[";", "collapse_selections"],
|
[";", "collapse_selections"],
|
||||||
|
@ -240,6 +240,8 @@
|
||||||
"name": "INS",
|
"name": "INS",
|
||||||
"line_numbers": "absolute",
|
"line_numbers": "absolute",
|
||||||
"cursor": "beam",
|
"cursor": "beam",
|
||||||
|
"init_command": ["pause_undo_history"],
|
||||||
|
"deinit_command": ["resume_undo_history"],
|
||||||
"press": [
|
"press": [
|
||||||
["ctrl+u", "move_scroll_page_up"],
|
["ctrl+u", "move_scroll_page_up"],
|
||||||
["ctrl+d", "move_scroll_page_down"],
|
["ctrl+d", "move_scroll_page_down"],
|
||||||
|
@ -276,7 +278,7 @@
|
||||||
["alt+`", "switch_to_uppercase"],
|
["alt+`", "switch_to_uppercase"],
|
||||||
|
|
||||||
["alt+d", "delete_backward"],
|
["alt+d", "delete_backward"],
|
||||||
["alt+c", ["delete_backward"], ["enter_mode", "insert"]],
|
["alt+c", ["enter_mode", "insert"], ["delete_backward"]],
|
||||||
|
|
||||||
["alt+s", "split_selection_on_newline"],
|
["alt+s", "split_selection_on_newline"],
|
||||||
["alt+-", "merge_selections"],
|
["alt+-", "merge_selections"],
|
||||||
|
@ -328,10 +330,10 @@
|
||||||
|
|
||||||
["shift+g", "move_buffer_end_or_count_line"],
|
["shift+g", "move_buffer_end_or_count_line"],
|
||||||
|
|
||||||
["shift+i", ["smart_move_begin"], ["enter_mode", "insert"]],
|
["shift+i", ["enter_mode", "insert"], ["smart_move_begin"]],
|
||||||
["shift+a", ["move_end"], ["enter_mode", "insert"]],
|
["shift+a", ["enter_mode", "insert"], ["move_end"]],
|
||||||
|
|
||||||
["shift+o", ["smart_insert_line_before"], ["enter_mode", "insert"]],
|
["shift+o", ["enter_mode", "insert"], ["smart_insert_line_before"]],
|
||||||
|
|
||||||
["shift+c", "copy_selection_on_next_line"],
|
["shift+c", "copy_selection_on_next_line"],
|
||||||
|
|
||||||
|
@ -415,11 +417,11 @@
|
||||||
["g shift+d", "goto_declaration"],
|
["g shift+d", "goto_declaration"],
|
||||||
|
|
||||||
["i", "enter_mode", "insert"],
|
["i", "enter_mode", "insert"],
|
||||||
["a", ["move_right"], ["enter_mode", "insert"]],
|
["a", ["enter_mode", "insert"], ["move_right"]],
|
||||||
["o", ["smart_insert_line_after"], ["enter_mode", "insert"]],
|
["o", ["enter_mode", "insert"], ["smart_insert_line_after"]],
|
||||||
|
|
||||||
["d", "cut"],
|
["d", "cut"],
|
||||||
["c", ["cut"], ["enter_mode", "insert"]],
|
["c", ["enter_mode", "insert"], ["cut"]],
|
||||||
|
|
||||||
["s", "select_regex"],
|
["s", "select_regex"],
|
||||||
[";", "collapse_selections"],
|
[";", "collapse_selections"],
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
["B", "move_word_left"],
|
["B", "move_word_left"],
|
||||||
["e", "move_word_right_end_vim"],
|
["e", "move_word_right_end_vim"],
|
||||||
["x", "cut_forward_internal"],
|
["x", "cut_forward_internal"],
|
||||||
["s", ["cut_forward_internal"], ["enter_mode", "insert"]],
|
["s", ["enter_mode", "insert"], ["cut_forward_internal"]],
|
||||||
["u", "undo"],
|
["u", "undo"],
|
||||||
|
|
||||||
["j", "move_down_vim"],
|
["j", "move_down_vim"],
|
||||||
|
@ -27,11 +27,11 @@
|
||||||
["<Space>", "move_right_vim"],
|
["<Space>", "move_right_vim"],
|
||||||
|
|
||||||
["i", "enter_mode", "insert"],
|
["i", "enter_mode", "insert"],
|
||||||
["a", ["move_right"], ["enter_mode", "insert"]],
|
["a", ["enter_mode", "insert"], ["move_right"]],
|
||||||
["I", ["smart_move_begin"], ["enter_mode", "insert"]],
|
["I", ["enter_mode", "insert"], ["smart_move_begin"]],
|
||||||
["A", ["move_end"], ["enter_mode", "insert"]],
|
["A", ["enter_mode", "insert"], ["move_end"]],
|
||||||
["o", ["smart_insert_line_after"], ["enter_mode", "insert"]],
|
["o", ["enter_mode", "insert"], ["smart_insert_line_after"]],
|
||||||
["O", ["smart_insert_line_before"], ["enter_mode", "insert"]],
|
["O", ["enter_mode", "insert"], ["smart_insert_line_before"]],
|
||||||
|
|
||||||
["<S-.><S-.>", "indent"],
|
["<S-.><S-.>", "indent"],
|
||||||
["<S-,><S-,>", "unindent"],
|
["<S-,><S-,>", "unindent"],
|
||||||
|
@ -63,11 +63,11 @@
|
||||||
["dd", "cut_internal_vim"],
|
["dd", "cut_internal_vim"],
|
||||||
["\"_dd", "delete_line"],
|
["\"_dd", "delete_line"],
|
||||||
|
|
||||||
["cc", ["cut_internal_vim"], ["enter_mode", "insert"]],
|
["cc", ["enter_mode", "insert"], ["cut_internal_vim"]],
|
||||||
["C", ["cut_to_end_vim"], ["enter_mode", "insert"]],
|
["C", ["enter_mode", "insert"], ["cut_to_end_vim"]],
|
||||||
["D", "cut_to_end_vim"],
|
["D", "cut_to_end_vim"],
|
||||||
["cw", ["cut_word_right_vim"], ["enter_mode", "insert"]],
|
["cw", ["enter_mode", "insert"], ["cut_word_right_vim"]],
|
||||||
["cb", ["cut_word_left_vim"], ["enter_mode", "insert"]],
|
["cb", ["enter_mode", "insert"], ["cut_word_left_vim"]],
|
||||||
|
|
||||||
["yy", ["copy_line_internal_vim"], ["cancel"]],
|
["yy", ["copy_line_internal_vim"], ["cancel"]],
|
||||||
|
|
||||||
|
@ -132,10 +132,10 @@
|
||||||
|
|
||||||
["x", ["cut_forward_internal"], ["enter_mode", "normal"]],
|
["x", ["cut_forward_internal"], ["enter_mode", "normal"]],
|
||||||
["d", ["cut_forward_internal"], ["enter_mode", "normal"]],
|
["d", ["cut_forward_internal"], ["enter_mode", "normal"]],
|
||||||
["s", ["cut_forward_internal"], ["enter_mode", "insert"]],
|
["s", ["enter_mode", "insert"], ["cut_forward_internal"]],
|
||||||
|
|
||||||
["c", ["cut_forward_internal"], ["enter_mode", "insert"]],
|
["c", ["enter_mode", "insert"], ["cut_forward_internal"]],
|
||||||
["C", ["cut_to_end_vim"], ["enter_mode", "insert"]],
|
["C", ["enter_mode", "insert"], ["cut_to_end_vim"]],
|
||||||
["D", "cut_to_end_vim"]
|
["D", "cut_to_end_vim"]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -169,10 +169,10 @@
|
||||||
|
|
||||||
["x", ["cut_internal_vim"], ["enter_mode", "normal"]],
|
["x", ["cut_internal_vim"], ["enter_mode", "normal"]],
|
||||||
["d", ["cut_internal_vim"], ["enter_mode", "normal"]],
|
["d", ["cut_internal_vim"], ["enter_mode", "normal"]],
|
||||||
["s", ["cut_internal_vim"], ["enter_mode", "insert"]],
|
["s", ["enter_mode", "insert"], ["cut_internal_vim"]],
|
||||||
|
|
||||||
["c", ["cut_internal_vim"], ["enter_mode", "insert"]],
|
["c", ["enter_mode", "insert"], ["cut_internal_vim"]],
|
||||||
["C", ["cut_to_end_vim"], ["enter_mode", "insert"]],
|
["C", ["enter_mode", "insert"], ["cut_to_end_vim"]],
|
||||||
["D", "cut_to_end_vim"]
|
["D", "cut_to_end_vim"]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -181,6 +181,8 @@
|
||||||
"name": "INSERT",
|
"name": "INSERT",
|
||||||
"line_numbers": "absolute",
|
"line_numbers": "absolute",
|
||||||
"cursor": "beam",
|
"cursor": "beam",
|
||||||
|
"init_command": ["pause_undo_history"],
|
||||||
|
"deinit_command": ["resume_undo_history"],
|
||||||
"press": [
|
"press": [
|
||||||
["<Esc>", ["move_left_vim"], ["enter_mode", "normal"]],
|
["<Esc>", ["move_left_vim"], ["enter_mode", "normal"]],
|
||||||
["<Del>", "delete_forward"],
|
["<Del>", "delete_forward"],
|
||||||
|
|
|
@ -61,6 +61,8 @@ const Handler = struct {
|
||||||
.line_numbers = self.bindings.line_numbers,
|
.line_numbers = self.bindings.line_numbers,
|
||||||
.cursor_shape = self.bindings.cursor_shape,
|
.cursor_shape = self.bindings.cursor_shape,
|
||||||
.selection_style = self.bindings.selection_style,
|
.selection_style = self.bindings.selection_style,
|
||||||
|
.init_command = self.bindings.init_command,
|
||||||
|
.deinit_command = self.bindings.deinit_command,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub fn deinit(self: *@This()) void {
|
pub fn deinit(self: *@This()) void {
|
||||||
|
@ -82,8 +84,12 @@ pub const Mode = struct {
|
||||||
keybind_hints: *const KeybindHints,
|
keybind_hints: *const KeybindHints,
|
||||||
cursor_shape: ?CursorShape = null,
|
cursor_shape: ?CursorShape = null,
|
||||||
selection_style: SelectionStyle,
|
selection_style: SelectionStyle,
|
||||||
|
init_command: ?Command = null,
|
||||||
|
deinit_command: ?Command = null,
|
||||||
|
|
||||||
pub fn deinit(self: *Mode) void {
|
pub fn deinit(self: *Mode) void {
|
||||||
|
if (self.deinit_command) |deinit_|
|
||||||
|
deinit_.execute_const();
|
||||||
self.allocator.free(self.mode);
|
self.allocator.free(self.mode);
|
||||||
self.input_handler.deinit();
|
self.input_handler.deinit();
|
||||||
if (self.event_handler) |eh| eh.deinit();
|
if (self.event_handler) |eh| eh.deinit();
|
||||||
|
@ -139,18 +145,10 @@ pub fn set_namespace(namespace_name: []const u8) LoadError!void {
|
||||||
const new_namespace = try get_or_load_namespace(namespace_name);
|
const new_namespace = try get_or_load_namespace(namespace_name);
|
||||||
if (globals.current_namespace) |old_namespace|
|
if (globals.current_namespace) |old_namespace|
|
||||||
if (old_namespace.deinit_command) |deinit|
|
if (old_namespace.deinit_command) |deinit|
|
||||||
deinit.execute_const() catch |e| {
|
deinit.execute_const();
|
||||||
const logger = log.logger("keybind");
|
|
||||||
logger.print_err("deinit_command", "ERROR: {s} {s}", .{ deinit.command, @errorName(e) });
|
|
||||||
logger.deinit();
|
|
||||||
};
|
|
||||||
globals.current_namespace = new_namespace;
|
globals.current_namespace = new_namespace;
|
||||||
if (new_namespace.init_command) |init|
|
if (new_namespace.init_command) |init|
|
||||||
init.execute_const() catch |e| {
|
init.execute_const();
|
||||||
const logger = log.logger("keybind");
|
|
||||||
logger.print_err("init_command", "ERROR: {s} {s}", .{ init.command, @errorName(e) });
|
|
||||||
logger.deinit();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_mode_binding_set(mode_name: []const u8, insert_command: []const u8) LoadError!*const BindingSet {
|
fn get_mode_binding_set(mode_name: []const u8, insert_command: []const u8) LoadError!*const BindingSet {
|
||||||
|
@ -267,10 +265,14 @@ const Command = struct {
|
||||||
try command.execute(id, .{ .args = .{ .buf = buf[0..self.args.len] } });
|
try command.execute(id, .{ .args = .{ .buf = buf[0..self.args.len] } });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_const(self: *const @This()) !void {
|
pub fn execute_const(self: *const @This()) void {
|
||||||
var buf: [2048]u8 = undefined;
|
var buf: [2048]u8 = undefined;
|
||||||
@memcpy(buf[0..self.args.len], self.args);
|
@memcpy(buf[0..self.args.len], self.args);
|
||||||
try command.executeName(self.command, .{ .args = .{ .buf = buf[0..self.args.len] } });
|
command.executeName(self.command, .{ .args = .{ .buf = buf[0..self.args.len] } }) catch |e| {
|
||||||
|
const logger = log.logger("keybind");
|
||||||
|
logger.print_err("init/deinit_command", "ERROR: {s} {s}", .{ self.command, @errorName(e) });
|
||||||
|
logger.deinit();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(allocator: std.mem.Allocator, tokens: []const std.json.Value) (parse_flow.ParseError || parse_vim.ParseError)!Command {
|
fn load(allocator: std.mem.Allocator, tokens: []const std.json.Value) (parse_flow.ParseError || parse_vim.ParseError)!Command {
|
||||||
|
@ -373,6 +375,8 @@ const BindingSet = struct {
|
||||||
selection_style: SelectionStyle,
|
selection_style: SelectionStyle,
|
||||||
insert_command: []const u8 = "",
|
insert_command: []const u8 = "",
|
||||||
hints_map: KeybindHints = .{},
|
hints_map: KeybindHints = .{},
|
||||||
|
init_command: ?Command = null,
|
||||||
|
deinit_command: ?Command = null,
|
||||||
|
|
||||||
const KeySyntax = enum { flow, vim };
|
const KeySyntax = enum { flow, vim };
|
||||||
const OnMatchFailure = enum { insert, ignore };
|
const OnMatchFailure = enum { insert, ignore };
|
||||||
|
@ -391,6 +395,8 @@ const BindingSet = struct {
|
||||||
inherit: ?[]const u8 = null,
|
inherit: ?[]const u8 = null,
|
||||||
inherits: ?[][]const u8 = null,
|
inherits: ?[][]const u8 = null,
|
||||||
selection: ?SelectionStyle = null,
|
selection: ?SelectionStyle = null,
|
||||||
|
init_command: ?[]const std.json.Value = null,
|
||||||
|
deinit_command: ?[]const std.json.Value = null,
|
||||||
};
|
};
|
||||||
const parsed = try std.json.parseFromValue(JsonConfig, allocator, mode_bindings, .{
|
const parsed = try std.json.parseFromValue(JsonConfig, allocator, mode_bindings, .{
|
||||||
.ignore_unknown_fields = true,
|
.ignore_unknown_fields = true,
|
||||||
|
@ -402,6 +408,8 @@ const BindingSet = struct {
|
||||||
self.line_numbers = parsed.value.line_numbers;
|
self.line_numbers = parsed.value.line_numbers;
|
||||||
self.cursor_shape = parsed.value.cursor;
|
self.cursor_shape = parsed.value.cursor;
|
||||||
self.selection_style = parsed.value.selection orelse .normal;
|
self.selection_style = parsed.value.selection orelse .normal;
|
||||||
|
if (parsed.value.init_command) |cmd| self.init_command = try Command.load(allocator, cmd);
|
||||||
|
if (parsed.value.deinit_command) |cmd| self.deinit_command = try Command.load(allocator, cmd);
|
||||||
try self.load_event(allocator, &self.press, input.event.press, parsed.value.press);
|
try self.load_event(allocator, &self.press, input.event.press, parsed.value.press);
|
||||||
try self.load_event(allocator, &self.release, input.event.release, parsed.value.release);
|
try self.load_event(allocator, &self.release, input.event.release, parsed.value.release);
|
||||||
if (parsed.value.inherits) |sibling_fallbacks| {
|
if (parsed.value.inherits) |sibling_fallbacks| {
|
||||||
|
|
|
@ -269,6 +269,7 @@ pub const Editor = struct {
|
||||||
buffer_manager: *Buffer.Manager,
|
buffer_manager: *Buffer.Manager,
|
||||||
lsp_version: usize = 1,
|
lsp_version: usize = 1,
|
||||||
pause_undo: bool = false,
|
pause_undo: bool = false,
|
||||||
|
pause_undo_root: ?Buffer.Root = null,
|
||||||
|
|
||||||
cursels: CurSel.List,
|
cursels: CurSel.List,
|
||||||
cursels_saved: CurSel.List,
|
cursels_saved: CurSel.List,
|
||||||
|
@ -780,11 +781,23 @@ pub const Editor = struct {
|
||||||
|
|
||||||
pub fn pause_undo_history(self: *Self, _: Context) Result {
|
pub fn pause_undo_history(self: *Self, _: Context) Result {
|
||||||
self.pause_undo = true;
|
self.pause_undo = true;
|
||||||
|
self.pause_undo_root = self.buf_root() catch return;
|
||||||
|
self.cursels_saved.clearAndFree();
|
||||||
|
self.cursels_saved = try self.cursels.clone();
|
||||||
}
|
}
|
||||||
pub const pause_undo_history_meta: Meta = .{ .description = "Pause undo history" };
|
pub const pause_undo_history_meta: Meta = .{ .description = "Pause undo history" };
|
||||||
|
|
||||||
pub fn resume_undo_history(self: *Self, _: Context) Result {
|
pub fn resume_undo_history(self: *Self, _: Context) Result {
|
||||||
self.pause_undo = false;
|
self.pause_undo = false;
|
||||||
|
const b = self.buffer orelse return;
|
||||||
|
var sfa = std.heap.stackFallback(512, self.allocator);
|
||||||
|
const allocator = sfa.get();
|
||||||
|
const meta = try self.store_undo_meta(allocator);
|
||||||
|
defer allocator.free(meta);
|
||||||
|
const root = self.buf_root() catch return;
|
||||||
|
if (self.pause_undo_root) |paused_root| b.update(paused_root);
|
||||||
|
try b.store_undo(meta);
|
||||||
|
b.update(root);
|
||||||
}
|
}
|
||||||
pub const resume_undo_history_meta: Meta = .{ .description = "Resume undo history" };
|
pub const resume_undo_history_meta: Meta = .{ .description = "Resume undo history" };
|
||||||
|
|
||||||
|
|
|
@ -673,6 +673,8 @@ fn enter_input_mode(self: *Self, new_mode: Mode) command.Result {
|
||||||
self.input_mode_ = null;
|
self.input_mode_ = null;
|
||||||
}
|
}
|
||||||
self.input_mode_ = new_mode;
|
self.input_mode_ = new_mode;
|
||||||
|
if (new_mode.init_command) |cmd|
|
||||||
|
cmd.execute_const();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn refresh_input_mode(self: *Self) command.Result {
|
fn refresh_input_mode(self: *Self) command.Result {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue