parent
b8261f924e
commit
053bf19110
2 changed files with 43 additions and 5 deletions
|
@ -1478,6 +1478,14 @@ pub const Editor = struct {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_eol_right_vim(root: Buffer.Root, cursor: *const Cursor) bool {
|
||||||
|
const line_width = root.line_width(cursor.row) catch return true;
|
||||||
|
if (line_width == 0) return true;
|
||||||
|
if (cursor.col >= line_width - 1)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fn move_cursor_left(root: Buffer.Root, cursor: *Cursor) error{Stop}!void {
|
fn move_cursor_left(root: Buffer.Root, cursor: *Cursor) error{Stop}!void {
|
||||||
try cursor.move_left(root);
|
try cursor.move_left(root);
|
||||||
}
|
}
|
||||||
|
@ -1487,6 +1495,11 @@ pub const Editor = struct {
|
||||||
move_cursor_left(root, cursor) catch return;
|
move_cursor_left(root, cursor) catch return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn move_cursor_left_unless(root: Buffer.Root, cursor: *Cursor, pred: cursor_predicate) void {
|
||||||
|
if (!pred(root, cursor))
|
||||||
|
move_cursor_left(root, cursor) catch return;
|
||||||
|
}
|
||||||
|
|
||||||
fn move_cursor_begin(_: Buffer.Root, cursor: *Cursor) !void {
|
fn move_cursor_begin(_: Buffer.Root, cursor: *Cursor) !void {
|
||||||
cursor.move_begin();
|
cursor.move_begin();
|
||||||
}
|
}
|
||||||
|
@ -1505,6 +1518,11 @@ pub const Editor = struct {
|
||||||
move_cursor_right(root, cursor) catch return;
|
move_cursor_right(root, cursor) catch return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn move_cursor_right_unless(root: Buffer.Root, cursor: *Cursor, pred: cursor_predicate) void {
|
||||||
|
if (!pred(root, cursor))
|
||||||
|
move_cursor_right(root, cursor) catch return;
|
||||||
|
}
|
||||||
|
|
||||||
fn move_cursor_end(root: Buffer.Root, cursor: *Cursor) !void {
|
fn move_cursor_end(root: Buffer.Root, cursor: *Cursor) !void {
|
||||||
cursor.move_end(root);
|
cursor.move_end(root);
|
||||||
}
|
}
|
||||||
|
@ -1928,6 +1946,26 @@ pub const Editor = struct {
|
||||||
self.clamp();
|
self.clamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn move_cursor_left_vim(root: Buffer.Root, cursor: *Cursor) error{Stop}!void {
|
||||||
|
move_cursor_left_unless(root, cursor, is_eol_left);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_cursor_right_vim(root: Buffer.Root, cursor: *Cursor) error{Stop}!void {
|
||||||
|
move_cursor_right_unless(root, cursor, is_eol_right_vim);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn move_left_vim(self: *Self, _: command.Context) tp.result {
|
||||||
|
const root = self.buf_root() catch |e| return tp.exit_error(e);
|
||||||
|
self.with_cursors_const(root, move_cursor_left_vim) catch {};
|
||||||
|
self.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn move_right_vim(self: *Self, _: command.Context) tp.result {
|
||||||
|
const root = self.buf_root() catch |e| return tp.exit_error(e);
|
||||||
|
self.with_cursors_const(root, move_cursor_right_vim) catch {};
|
||||||
|
self.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
fn move_cursor_word_begin(root: Buffer.Root, cursor: *Cursor) error{Stop}!void {
|
fn move_cursor_word_begin(root: Buffer.Root, cursor: *Cursor) error{Stop}!void {
|
||||||
if (is_non_word_char_at_cursor(root, cursor)) {
|
if (is_non_word_char_at_cursor(root, cursor)) {
|
||||||
move_cursor_left_until(root, cursor, is_word_boundary_right);
|
move_cursor_left_until(root, cursor, is_word_boundary_right);
|
||||||
|
|
|
@ -224,11 +224,11 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
||||||
'/' => self.cmd("enter_find_mode", .{}),
|
'/' => self.cmd("enter_find_mode", .{}),
|
||||||
'n' => self.cmd("goto_next_match", .{}),
|
'n' => self.cmd("goto_next_match", .{}),
|
||||||
|
|
||||||
'h' => self.cmd_count("move_left", .{}),
|
'h' => self.cmd_count("move_left_vim", .{}),
|
||||||
'j' => self.cmd_count("move_down", .{}),
|
'j' => self.cmd_count("move_down", .{}),
|
||||||
'k' => self.cmd_count("move_up", .{}),
|
'k' => self.cmd_count("move_up", .{}),
|
||||||
'l' => self.cmd_count("move_right", .{}),
|
'l' => self.cmd_count("move_right_vim", .{}),
|
||||||
' ' => self.cmd_count("move_right", .{}),
|
' ' => self.cmd_count("move_right_vim", .{}),
|
||||||
|
|
||||||
'b' => self.cmd_count("move_word_left", .{}),
|
'b' => self.cmd_count("move_word_left", .{}),
|
||||||
'w' => self.cmd_count("move_word_right_vim", .{}),
|
'w' => self.cmd_count("move_word_right_vim", .{}),
|
||||||
|
@ -260,8 +260,8 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
||||||
'p' => self.cmd("paste", .{}),
|
'p' => self.cmd("paste", .{}),
|
||||||
'o' => self.seq(.{ "smart_insert_line_after", "enter_mode" }, command.fmt(.{"vim/insert"})),
|
'o' => self.seq(.{ "smart_insert_line_after", "enter_mode" }, command.fmt(.{"vim/insert"})),
|
||||||
|
|
||||||
key.LEFT => self.cmd("move_left", .{}),
|
key.LEFT => self.cmd("move_left_vim", .{}),
|
||||||
key.RIGHT => self.cmd("move_right", .{}),
|
key.RIGHT => self.cmd("move_right_vim", .{}),
|
||||||
key.UP => self.cmd("move_up", .{}),
|
key.UP => self.cmd("move_up", .{}),
|
||||||
key.DOWN => self.cmd("move_down", .{}),
|
key.DOWN => self.cmd("move_down", .{}),
|
||||||
key.HOME => self.cmd("smart_move_begin", .{}),
|
key.HOME => self.cmd("smart_move_begin", .{}),
|
||||||
|
|
Loading…
Add table
Reference in a new issue