feat: add support for byte offsets in file links to navigate command
This commit is contained in:
parent
7228a604b0
commit
2461717f11
1 changed files with 14 additions and 5 deletions
|
@ -150,10 +150,10 @@ pub fn receive(self: *Self, from_: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} else if (try m.match(.{ "navigate_complete", tp.extract(&same_file), tp.extract(&path), tp.extract(&goto_args), tp.extract(&line), tp.extract(&column) })) {
|
} else if (try m.match(.{ "navigate_complete", tp.extract(&same_file), tp.extract(&path), tp.extract(&goto_args), tp.extract(&line), tp.extract(&column) })) {
|
||||||
cmds.navigate_complete(self, same_file, path, goto_args, line, column) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
cmds.navigate_complete(self, same_file, path, goto_args, line, column, null) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
return true;
|
return true;
|
||||||
} else if (try m.match(.{ "navigate_complete", tp.extract(&same_file), tp.extract(&path), tp.extract(&goto_args), tp.null_, tp.null_ })) {
|
} else if (try m.match(.{ "navigate_complete", tp.extract(&same_file), tp.extract(&path), tp.extract(&goto_args), tp.null_, tp.null_ })) {
|
||||||
cmds.navigate_complete(self, same_file, path, goto_args, null, null) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
cmds.navigate_complete(self, same_file, path, goto_args, null, null, null) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return if (try self.floating_views.send(from_, m)) true else self.widgets.send(from_, m);
|
return if (try self.floating_views.send(from_, m)) true else self.widgets.send(from_, m);
|
||||||
|
@ -349,6 +349,7 @@ const cmds = struct {
|
||||||
var file_name: []const u8 = undefined;
|
var file_name: []const u8 = undefined;
|
||||||
var line: ?i64 = null;
|
var line: ?i64 = null;
|
||||||
var column: ?i64 = null;
|
var column: ?i64 = null;
|
||||||
|
var offset: ?i64 = null;
|
||||||
var goto_args: []const u8 = &.{};
|
var goto_args: []const u8 = &.{};
|
||||||
|
|
||||||
var iter = ctx.args.buf;
|
var iter = ctx.args.buf;
|
||||||
|
@ -370,6 +371,9 @@ const cmds = struct {
|
||||||
} else if (std.mem.eql(u8, field_name, "goto")) {
|
} else if (std.mem.eql(u8, field_name, "goto")) {
|
||||||
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&goto_args)))
|
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&goto_args)))
|
||||||
return error.InvalidNavigateGotoArgument;
|
return error.InvalidNavigateGotoArgument;
|
||||||
|
} else if (std.mem.eql(u8, field_name, "offset")) {
|
||||||
|
if (!try cbor.matchValue(&iter, cbor.extract(&offset)))
|
||||||
|
return error.InvalidNavigateOffsetArgument;
|
||||||
} else {
|
} else {
|
||||||
try cbor.skipValue(&iter);
|
try cbor.skipValue(&iter);
|
||||||
}
|
}
|
||||||
|
@ -392,7 +396,8 @@ const cmds = struct {
|
||||||
if (tui.config().restore_last_cursor_position and
|
if (tui.config().restore_last_cursor_position and
|
||||||
!same_file and
|
!same_file and
|
||||||
!have_editor_metadata and
|
!have_editor_metadata and
|
||||||
line == null)
|
line == null and
|
||||||
|
offset == null)
|
||||||
{
|
{
|
||||||
const ctx_: struct {
|
const ctx_: struct {
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
|
@ -424,11 +429,11 @@ const cmds = struct {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmds.navigate_complete(self, same_file, f, goto_args, line, column);
|
return cmds.navigate_complete(self, same_file, f, goto_args, line, column, offset);
|
||||||
}
|
}
|
||||||
pub const navigate_meta: Meta = .{ .arguments = &.{.object} };
|
pub const navigate_meta: Meta = .{ .arguments = &.{.object} };
|
||||||
|
|
||||||
fn navigate_complete(self: *Self, same_file: bool, f: []const u8, goto_args: []const u8, line: ?i64, column: ?i64) Result {
|
fn navigate_complete(self: *Self, same_file: bool, f: []const u8, goto_args: []const u8, line: ?i64, column: ?i64, offset: ?i64) Result {
|
||||||
if (!same_file) {
|
if (!same_file) {
|
||||||
if (self.get_active_editor()) |editor| {
|
if (self.get_active_editor()) |editor| {
|
||||||
editor.send_editor_jump_source() catch {};
|
editor.send_editor_jump_source() catch {};
|
||||||
|
@ -444,6 +449,10 @@ const cmds = struct {
|
||||||
try command.executeName("scroll_view_center", .{});
|
try command.executeName("scroll_view_center", .{});
|
||||||
if (column) |col|
|
if (column) |col|
|
||||||
try command.executeName("goto_column", command.fmt(.{col}));
|
try command.executeName("goto_column", command.fmt(.{col}));
|
||||||
|
} else if (offset) |o| {
|
||||||
|
try command.executeName("goto_byte_offset", command.fmt(.{o}));
|
||||||
|
if (!same_file)
|
||||||
|
try command.executeName("scroll_view_center", .{});
|
||||||
}
|
}
|
||||||
tui.need_render();
|
tui.need_render();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue