Compare commits
5 commits
f26e68b651
...
b52b06735b
| Author | SHA1 | Date | |
|---|---|---|---|
| b52b06735b | |||
| fffedb7371 | |||
| 0dcf63bd38 | |||
| a9ee5321ac | |||
| c6c310b9d0 |
6 changed files with 53 additions and 8 deletions
|
|
@ -263,6 +263,7 @@
|
||||||
"inherit": "normal",
|
"inherit": "normal",
|
||||||
"cursor": "block",
|
"cursor": "block",
|
||||||
"press": [
|
"press": [
|
||||||
|
["ctrl+g", "goto", "select"],
|
||||||
["left", "select_left"],
|
["left", "select_left"],
|
||||||
["right", "select_right"],
|
["right", "select_right"],
|
||||||
["ctrl+left", "select_word_left"],
|
["ctrl+left", "select_word_left"],
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,7 @@
|
||||||
["t", "move_to_char", "extend_till_char_right_helix"],
|
["t", "move_to_char", "extend_till_char_right_helix"],
|
||||||
["f", "move_to_char", "extend_to_char_right_helix"],
|
["f", "move_to_char", "extend_to_char_right_helix"],
|
||||||
|
|
||||||
["G", "goto_line"],
|
["G", "select_to_line"],
|
||||||
|
|
||||||
["I", ["enter_mode", "insert"], ["smart_move_begin"]],
|
["I", ["enter_mode", "insert"], ["smart_move_begin"]],
|
||||||
["A", ["enter_mode", "insert"], ["move_end"]],
|
["A", ["enter_mode", "insert"], ["move_end"]],
|
||||||
|
|
@ -413,8 +413,8 @@
|
||||||
["end", "extend_to_line_end"],
|
["end", "extend_to_line_end"],
|
||||||
["v", "enter_mode", "normal"],
|
["v", "enter_mode", "normal"],
|
||||||
|
|
||||||
["g g", "goto_line_vim"],
|
["g g", "select_to_line_vim"],
|
||||||
["g e", "move_buffer_end"],
|
["g e", "select_buffer_end"],
|
||||||
["g f", "goto_file"],
|
["g f", "goto_file"],
|
||||||
["g h", "move_begin"],
|
["g h", "move_begin"],
|
||||||
["g l", "select_end"],
|
["g l", "select_end"],
|
||||||
|
|
|
||||||
|
|
@ -3432,6 +3432,19 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
pub const move_word_right_end_vim_meta: Meta = .{ .description = "Move cursor right by end of word (vim)", .arguments = &.{.integer} };
|
pub const move_word_right_end_vim_meta: Meta = .{ .description = "Move cursor right by end of word (vim)", .arguments = &.{.integer} };
|
||||||
|
|
||||||
|
fn move_cursor_to_line(root: Buffer.Root, cursor: *Cursor, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void {
|
||||||
|
var line: usize = 0;
|
||||||
|
if (!(ctx.args.match(.{tp.extract(&line)}) catch return error.Stop))
|
||||||
|
return error.Stop;
|
||||||
|
try cursor.move_to(root, line -| 1, cursor.col, metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_cursor_to_line_vim(root: Buffer.Root, cursor: *Cursor, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void {
|
||||||
|
var line: usize = 0;
|
||||||
|
_ = ctx.args.match(.{tp.extract(&line)}) catch false;
|
||||||
|
try cursor.move_to(root, line -| 1, cursor.col, metrics);
|
||||||
|
}
|
||||||
|
|
||||||
fn move_cursor_to_char_left(root: Buffer.Root, cursor: *Cursor, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void {
|
fn move_cursor_to_char_left(root: Buffer.Root, cursor: *Cursor, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void {
|
||||||
var egc: []const u8 = undefined;
|
var egc: []const u8 = undefined;
|
||||||
if (!(ctx.args.match(.{tp.extract(&egc)}) catch return error.Stop))
|
if (!(ctx.args.match(.{tp.extract(&egc)}) catch return error.Stop))
|
||||||
|
|
@ -5740,6 +5753,15 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
pub const goto_line_meta: Meta = .{ .arguments = &.{.integer} };
|
pub const goto_line_meta: Meta = .{ .arguments = &.{.integer} };
|
||||||
|
|
||||||
|
pub fn select_to_line(self: *Self, ctx: Context) Result {
|
||||||
|
try self.send_editor_jump_source();
|
||||||
|
const root = self.buf_root() catch return;
|
||||||
|
self.with_selections_const_arg(root, move_cursor_to_line, ctx) catch {};
|
||||||
|
self.clamp();
|
||||||
|
try self.send_editor_jump_destination();
|
||||||
|
}
|
||||||
|
pub const select_to_line_meta: Meta = .{ .arguments = &.{.integer} };
|
||||||
|
|
||||||
pub fn goto_line_vim(self: *Self, ctx: Context) Result {
|
pub fn goto_line_vim(self: *Self, ctx: Context) Result {
|
||||||
try self.send_editor_jump_source();
|
try self.send_editor_jump_source();
|
||||||
var line: usize = 0;
|
var line: usize = 0;
|
||||||
|
|
@ -5752,6 +5774,15 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
pub const goto_line_vim_meta: Meta = .{ .arguments = &.{.integer} };
|
pub const goto_line_vim_meta: Meta = .{ .arguments = &.{.integer} };
|
||||||
|
|
||||||
|
pub fn select_to_line_vim(self: *Self, ctx: Context) Result {
|
||||||
|
try self.send_editor_jump_source();
|
||||||
|
const root = self.buf_root() catch return;
|
||||||
|
self.with_selections_const_arg(root, move_cursor_to_line_vim, ctx) catch {};
|
||||||
|
self.clamp();
|
||||||
|
try self.send_editor_jump_destination();
|
||||||
|
}
|
||||||
|
pub const select_to_line_vim_meta: Meta = .{ .arguments = &.{.integer} };
|
||||||
|
|
||||||
pub fn goto_column(self: *Self, ctx: Context) Result {
|
pub fn goto_column(self: *Self, ctx: Context) Result {
|
||||||
const root = self.buf_root() catch return;
|
const root = self.buf_root() catch return;
|
||||||
const primary = self.get_primary();
|
const primary = self.get_primary();
|
||||||
|
|
|
||||||
|
|
@ -446,7 +446,7 @@ fn print_digits(self: *Self, n_: anytype, style_: DigitStyle) !void {
|
||||||
if (n == 0) break;
|
if (n == 0) break;
|
||||||
}
|
}
|
||||||
std.mem.reverse([]const u8, digits.items);
|
std.mem.reverse([]const u8, digits.items);
|
||||||
try self.plane.cursor_move_yx(@intCast(self.plane.cursor_y()), @intCast(self.width - digits.items.len - 1));
|
try self.plane.cursor_move_yx(@intCast(self.plane.cursor_y()), @intCast(self.width -| digits.items.len -| 1));
|
||||||
for (digits.items) |digit| _ = try self.plane.putstr(digit);
|
for (digits.items) |digit| _ = try self.plane.putstr(digit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1496,6 +1496,8 @@ pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result
|
||||||
const text = editor.get_selection(sel, self.allocator) catch return self.clear_auto_find(editor);
|
const text = editor.get_selection(sel, self.allocator) catch return self.clear_auto_find(editor);
|
||||||
if (text.len == 0)
|
if (text.len == 0)
|
||||||
return self.clear_auto_find(editor);
|
return self.clear_auto_find(editor);
|
||||||
|
if (text.len == 1 and (text[0] == ' '))
|
||||||
|
return self.clear_auto_find(editor);
|
||||||
if (!self.is_last_match_text(text))
|
if (!self.is_last_match_text(text))
|
||||||
tp.self_pid().send(.{ "cmd", "find_query", .{ text, "auto_find" } }) catch return;
|
tp.self_pid().send(.{ "cmd", "find_query", .{ text, "auto_find" } }) catch return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
const fmt = @import("std").fmt;
|
const fmt = @import("std").fmt;
|
||||||
|
const cbor = @import("cbor");
|
||||||
const command = @import("command");
|
const command = @import("command");
|
||||||
|
|
||||||
const tui = @import("../../tui.zig");
|
const tui = @import("../../tui.zig");
|
||||||
|
|
@ -83,10 +84,20 @@ pub const preview = goto;
|
||||||
pub const apply = goto;
|
pub const apply = goto;
|
||||||
pub const cancel = goto;
|
pub const cancel = goto;
|
||||||
|
|
||||||
fn goto(self: *Type, _: command.Context) void {
|
const Mode = enum {
|
||||||
send_goto(if (self.input) |input| input.cursor else self.start.cursor);
|
goto,
|
||||||
|
select,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn goto(self: *Type, ctx: command.Context) void {
|
||||||
|
var mode: Mode = .goto;
|
||||||
|
_ = ctx.args.match(.{cbor.extract(&mode)}) catch {};
|
||||||
|
send_goto(mode, if (self.input) |input| input.cursor else self.start.cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_goto(cursor: Cursor) void {
|
fn send_goto(mode: Mode, cursor: Cursor) void {
|
||||||
command.executeName("goto_line_and_column", command.fmt(.{ cursor.row, cursor.col })) catch {};
|
switch (mode) {
|
||||||
|
.goto => command.executeName("goto_line_and_column", command.fmt(.{ cursor.row, cursor.col })) catch {},
|
||||||
|
.select => command.executeName("select_to_line", command.fmt(.{cursor.row})) catch {},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue