feat: add support for specifying positions in bytes in goto_line_and_column
This commit is contained in:
parent
0a60f37857
commit
7207b0435e
1 changed files with 29 additions and 0 deletions
|
@ -55,6 +55,8 @@ pub const whitespace = struct {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const PosType = enum { column, byte };
|
||||||
|
|
||||||
pub const Match = struct {
|
pub const Match = struct {
|
||||||
begin: Cursor = Cursor{},
|
begin: Cursor = Cursor{},
|
||||||
end: Cursor = Cursor{},
|
end: Cursor = Cursor{},
|
||||||
|
@ -5410,11 +5412,18 @@ pub const Editor = struct {
|
||||||
var column: usize = 0;
|
var column: usize = 0;
|
||||||
var have_sel: bool = false;
|
var have_sel: bool = false;
|
||||||
var sel: Selection = .{};
|
var sel: Selection = .{};
|
||||||
|
var pos_type: PosType = .column;
|
||||||
if (try ctx.args.match(.{
|
if (try ctx.args.match(.{
|
||||||
tp.extract(&line),
|
tp.extract(&line),
|
||||||
tp.extract(&column),
|
tp.extract(&column),
|
||||||
})) {
|
})) {
|
||||||
// self.logger.print("goto: l:{d} c:{d}", .{ line, column });
|
// self.logger.print("goto: l:{d} c:{d}", .{ line, column });
|
||||||
|
} else if (try ctx.args.match(.{
|
||||||
|
tp.extract(&line),
|
||||||
|
tp.extract(&column),
|
||||||
|
tp.extract(&pos_type),
|
||||||
|
})) {
|
||||||
|
// self.logger.print("goto: l:{d} c:{d}", .{ line, column });
|
||||||
} else if (try ctx.args.match(.{
|
} else if (try ctx.args.match(.{
|
||||||
tp.extract(&line),
|
tp.extract(&line),
|
||||||
tp.extract(&column),
|
tp.extract(&column),
|
||||||
|
@ -5425,9 +5434,29 @@ pub const Editor = struct {
|
||||||
})) {
|
})) {
|
||||||
// self.logger.print("goto: l:{d} c:{d} {any}", .{ line, column, sel });
|
// self.logger.print("goto: l:{d} c:{d} {any}", .{ line, column, sel });
|
||||||
have_sel = true;
|
have_sel = true;
|
||||||
|
} else if (try ctx.args.match(.{
|
||||||
|
tp.extract(&line),
|
||||||
|
tp.extract(&column),
|
||||||
|
tp.extract(&sel.begin.row),
|
||||||
|
tp.extract(&sel.begin.col),
|
||||||
|
tp.extract(&sel.end.row),
|
||||||
|
tp.extract(&sel.end.col),
|
||||||
|
tp.extract(&pos_type),
|
||||||
|
})) {
|
||||||
|
// self.logger.print("goto: l:{d} c:{d} {any} {}", .{ line, column, sel, pos_type });
|
||||||
|
have_sel = true;
|
||||||
} else return error.InvalidGotoLineAndColumnArgument;
|
} else return error.InvalidGotoLineAndColumnArgument;
|
||||||
self.cancel_all_selections();
|
self.cancel_all_selections();
|
||||||
const root = self.buf_root() catch return;
|
const root = self.buf_root() catch return;
|
||||||
|
if (pos_type == .byte) {
|
||||||
|
column = root.pos_to_width(line - 1, column - 1, self.metrics) catch return;
|
||||||
|
column += 1;
|
||||||
|
if (have_sel) {
|
||||||
|
sel.begin.col = root.pos_to_width(sel.begin.row, sel.begin.col, self.metrics) catch return;
|
||||||
|
sel.end.col = root.pos_to_width(sel.end.row, sel.end.col, self.metrics) catch return;
|
||||||
|
}
|
||||||
|
// self.logger.print("goto_byte_pos: l:{d} c:{d} {any} {}", .{ line, column, sel, pos_type });
|
||||||
|
}
|
||||||
const primary = self.get_primary();
|
const primary = self.get_primary();
|
||||||
try primary.cursor.move_to(
|
try primary.cursor.move_to(
|
||||||
root,
|
root,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue