feat: make goto in flow select mode select to line
This commit is contained in:
parent
a9ee5321ac
commit
0dcf63bd38
3 changed files with 32 additions and 4 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"],
|
||||||
|
|
|
||||||
|
|
@ -3432,6 +3432,13 @@ 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_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 +5747,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;
|
||||||
|
|
|
||||||
|
|
@ -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