Compare commits
No commits in common. "1ac34340b4a8e0f1f96f569a4818520d0a09bbd9" and "0bef3ce2e18296b9d4364df53c239e2c71d34211" have entirely different histories.
1ac34340b4
...
0bef3ce2e1
4 changed files with 118 additions and 138 deletions
|
|
@ -68,12 +68,9 @@
|
||||||
|
|
||||||
["F", "move_to_char", "select_to_char_left_helix"],
|
["F", "move_to_char", "select_to_char_left_helix"],
|
||||||
["T", "move_to_char", "select_till_char_left_helix"],
|
["T", "move_to_char", "select_till_char_left_helix"],
|
||||||
["B", "move_prev_long_word_start"],
|
|
||||||
["b", "move_prev_word_start"],
|
|
||||||
["e", "move_next_word_end"],
|
|
||||||
["w", "move_next_word_start"],
|
|
||||||
["E", "move_next_long_word_end"],
|
|
||||||
["W", "move_next_long_word_start"],
|
["W", "move_next_long_word_start"],
|
||||||
|
["B", "move_prev_long_word_start"],
|
||||||
|
["E", "move_next_long_word_end"],
|
||||||
["t", "move_to_char", "select_till_char_right_helix"],
|
["t", "move_to_char", "select_till_char_right_helix"],
|
||||||
["f", "move_to_char", "select_to_char_right_helix"],
|
["f", "move_to_char", "select_to_char_right_helix"],
|
||||||
|
|
||||||
|
|
@ -126,8 +123,13 @@
|
||||||
["kp_home", "move_begin"],
|
["kp_home", "move_begin"],
|
||||||
["kp_end", "move_end"],
|
["kp_end", "move_end"],
|
||||||
|
|
||||||
|
["w","move_next_word_start"],
|
||||||
|
["b","move_prev_word_start"],
|
||||||
|
["e","move_next_word_end"],
|
||||||
|
|
||||||
["v", "enter_mode", "select"],
|
["v", "enter_mode", "select"],
|
||||||
|
|
||||||
|
|
||||||
["G", "goto_line"],
|
["G", "goto_line"],
|
||||||
["g g", "goto_line_vim"],
|
["g g", "goto_line_vim"],
|
||||||
["g e", "move_buffer_end"],
|
["g e", "move_buffer_end"],
|
||||||
|
|
@ -276,6 +278,9 @@
|
||||||
"init_command": ["enable_selection"],
|
"init_command": ["enable_selection"],
|
||||||
"press": [
|
"press": [
|
||||||
|
|
||||||
|
["b", "select_word_left"],
|
||||||
|
["w", "select_word_right"],
|
||||||
|
|
||||||
["ctrl+b", "select_page_up"],
|
["ctrl+b", "select_page_up"],
|
||||||
["ctrl+f", "select_page_down"],
|
["ctrl+f", "select_page_down"],
|
||||||
["ctrl+u", "select_half_page_up"],
|
["ctrl+u", "select_half_page_up"],
|
||||||
|
|
@ -350,12 +355,9 @@
|
||||||
|
|
||||||
["F", "move_to_char", "extend_to_char_left_helix"],
|
["F", "move_to_char", "extend_to_char_left_helix"],
|
||||||
["T", "move_to_char", "extend_till_char_left_helix"],
|
["T", "move_to_char", "extend_till_char_left_helix"],
|
||||||
["B", "extend_prev_long_word_start"],
|
|
||||||
["b", "extend_prev_word_start"],
|
|
||||||
["e", "extend_next_word_end"],
|
|
||||||
["w", "extend_next_word_start"],
|
|
||||||
["E", "extend_next_long_word_end"],
|
|
||||||
["W", "extend_next_long_word_start"],
|
["W", "extend_next_long_word_start"],
|
||||||
|
["B", "extend_prev_long_word_start"],
|
||||||
|
["E", "extend_next_long_word_end"],
|
||||||
["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"],
|
||||||
|
|
||||||
|
|
@ -420,6 +422,11 @@
|
||||||
["end", "extend_to_line_end"],
|
["end", "extend_to_line_end"],
|
||||||
["kp_home", "extend_to_line_start"],
|
["kp_home", "extend_to_line_start"],
|
||||||
["kp_end", "extend_to_line_end"],
|
["kp_end", "extend_to_line_end"],
|
||||||
|
|
||||||
|
["w", "extend_next_word_start"],
|
||||||
|
["b", "extend_pre_word_start"],
|
||||||
|
["e", "extend_next_word_end"],
|
||||||
|
|
||||||
["v", "enter_mode", "normal"],
|
["v", "enter_mode", "normal"],
|
||||||
|
|
||||||
["g g", "goto_line_vim"],
|
["g g", "goto_line_vim"],
|
||||||
|
|
|
||||||
|
|
@ -1904,7 +1904,7 @@ pub const Editor = struct {
|
||||||
self.collapse_cursors();
|
self.collapse_cursors();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_cursors_const_repeat(self: *Self, root: Buffer.Root, move: cursor_operator_const, ctx: Context) error{Stop}!void {
|
fn with_cursors_const_repeat(self: *Self, root: Buffer.Root, move: cursor_operator_const, ctx: Context) error{Stop}!void {
|
||||||
var repeat: usize = 1;
|
var repeat: usize = 1;
|
||||||
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
||||||
while (repeat > 0) : (repeat -= 1) {
|
while (repeat > 0) : (repeat -= 1) {
|
||||||
|
|
@ -2138,7 +2138,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const cursor_predicate = *const fn (root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) bool;
|
const cursor_predicate = *const fn (root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) bool;
|
||||||
pub const cursor_operator_const = *const fn (root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void;
|
const cursor_operator_const = *const fn (root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void;
|
||||||
const cursor_operator_const_arg = *const fn (root: Buffer.Root, cursor: *Cursor, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void;
|
const cursor_operator_const_arg = *const fn (root: Buffer.Root, cursor: *Cursor, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void;
|
||||||
pub const cursel_operator_mut_once_arg = *const fn (root: Buffer.Root, cursel: *CurSel, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void;
|
pub const cursel_operator_mut_once_arg = *const fn (root: Buffer.Root, cursel: *CurSel, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void;
|
||||||
const cursor_view_operator_const = *const fn (root: Buffer.Root, cursor: *Cursor, view: *const View, metrics: Buffer.Metrics) error{Stop}!void;
|
const cursor_view_operator_const = *const fn (root: Buffer.Root, cursor: *Cursor, view: *const View, metrics: Buffer.Metrics) error{Stop}!void;
|
||||||
|
|
@ -3232,7 +3232,7 @@ pub const Editor = struct {
|
||||||
move_cursor_left_until(root, cursor, is_word_boundary_left, metrics);
|
move_cursor_left_until(root, cursor, is_word_boundary_left, metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_cursor_word_left_vim(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
fn move_cursor_word_left_vim(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||||
try move_cursor_left(root, cursor, metrics);
|
try move_cursor_left(root, cursor, metrics);
|
||||||
move_cursor_left_until(root, cursor, is_word_boundary_left_vim, metrics);
|
move_cursor_left_until(root, cursor, is_word_boundary_left_vim, metrics);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -220,65 +220,89 @@ const cmds_ = struct {
|
||||||
pub const extend_line_below_meta: Meta = .{ .arguments = &.{.integer}, .description = "Select current line, if already selected, extend to next line" };
|
pub const extend_line_below_meta: Meta = .{ .arguments = &.{.integer}, .description = "Select current line, if already selected, extend to next line" };
|
||||||
|
|
||||||
pub fn move_next_word_start(_: *void, ctx: Ctx) Result {
|
pub fn move_next_word_start(_: *void, ctx: Ctx) Result {
|
||||||
try move_to_word(ctx, Editor.move_cursor_word_right_vim);
|
const mv = tui.mainview() orelse return;
|
||||||
|
const ed = mv.get_active_editor() orelse return;
|
||||||
|
const root = try ed.buf_root();
|
||||||
|
|
||||||
|
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
|
cursel.selection = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
ed.with_selections_const_repeat(root, Editor.move_cursor_word_right_vim, ctx) catch {};
|
||||||
|
ed.clamp();
|
||||||
}
|
}
|
||||||
pub const move_next_word_start_meta: Meta = .{ .description = "Move next word start", .arguments = &.{.integer} };
|
pub const move_next_word_start_meta: Meta = .{ .description = "Move next word start", .arguments = &.{.integer} };
|
||||||
|
|
||||||
pub fn extend_next_word_start(_: *void, ctx: Ctx) Result {
|
|
||||||
try extend_to_word(ctx, Editor.move_cursor_word_right_vim);
|
|
||||||
}
|
|
||||||
pub const extend_next_word_start_meta: Meta = .{ .description = "Extend next word start", .arguments = &.{.integer} };
|
|
||||||
|
|
||||||
pub fn move_next_long_word_start(_: *void, ctx: Ctx) Result {
|
pub fn move_next_long_word_start(_: *void, ctx: Ctx) Result {
|
||||||
try move_to_word(ctx, move_cursor_long_word_right);
|
const mv = tui.mainview() orelse return;
|
||||||
|
const ed = mv.get_active_editor() orelse return;
|
||||||
|
const root = try ed.buf_root();
|
||||||
|
|
||||||
|
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
|
cursel.selection = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
ed.with_selections_const_repeat(root, move_cursor_long_word_right, ctx) catch {};
|
||||||
|
ed.clamp();
|
||||||
}
|
}
|
||||||
pub const move_next_long_word_start_meta: Meta = .{ .description = "Move next long word start", .arguments = &.{.integer} };
|
pub const move_next_long_word_start_meta: Meta = .{ .description = "Move next long word start", .arguments = &.{.integer} };
|
||||||
|
|
||||||
pub fn extend_next_long_word_start(_: *void, ctx: Ctx) Result {
|
|
||||||
try extend_to_word(ctx, move_cursor_long_word_right);
|
|
||||||
}
|
|
||||||
pub const extend_next_long_word_start_meta: Meta = .{ .description = "Extend next long word start", .arguments = &.{.integer} };
|
|
||||||
|
|
||||||
pub fn move_prev_word_start(_: *void, ctx: Ctx) Result {
|
pub fn move_prev_word_start(_: *void, ctx: Ctx) Result {
|
||||||
try move_to_word(ctx, move_cursor_word_left_helix);
|
const mv = tui.mainview() orelse return;
|
||||||
|
const ed = mv.get_active_editor() orelse return;
|
||||||
|
const root = try ed.buf_root();
|
||||||
|
|
||||||
|
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
|
cursel.selection = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
ed.with_selections_const_repeat(root, move_cursor_word_left_helix, ctx) catch {};
|
||||||
|
ed.clamp();
|
||||||
}
|
}
|
||||||
pub const move_prev_word_start_meta: Meta = .{ .description = "Move previous word start", .arguments = &.{.integer} };
|
pub const move_prev_word_start_meta: Meta = .{ .description = "Move previous word start", .arguments = &.{.integer} };
|
||||||
|
|
||||||
pub fn extend_prev_word_start(_: *void, ctx: Ctx) Result {
|
|
||||||
try extend_to_word(ctx, move_cursor_word_left_helix);
|
|
||||||
}
|
|
||||||
pub const extend_prev_word_start_meta: Meta = .{ .description = "Extend previous word start", .arguments = &.{.integer} };
|
|
||||||
|
|
||||||
pub fn move_prev_long_word_start(_: *void, ctx: Ctx) Result {
|
pub fn move_prev_long_word_start(_: *void, ctx: Ctx) Result {
|
||||||
try move_to_word(ctx, move_cursor_long_word_left);
|
const mv = tui.mainview() orelse return;
|
||||||
|
const ed = mv.get_active_editor() orelse return;
|
||||||
|
const root = try ed.buf_root();
|
||||||
|
|
||||||
|
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
|
cursel.selection = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
ed.with_selections_const_repeat(root, move_cursor_long_word_left, ctx) catch {};
|
||||||
|
ed.clamp();
|
||||||
}
|
}
|
||||||
pub const move_prev_long_word_start_meta: Meta = .{ .description = "Move previous long word start", .arguments = &.{.integer} };
|
pub const move_prev_long_word_start_meta: Meta = .{ .description = "Move previous long word start", .arguments = &.{.integer} };
|
||||||
|
|
||||||
pub fn extend_prev_long_word_start(_: *void, ctx: Ctx) Result {
|
|
||||||
try extend_to_word(ctx, move_cursor_long_word_left);
|
|
||||||
}
|
|
||||||
pub const extend_prev_long_word_start_meta: Meta = .{ .description = "Extend previous word start", .arguments = &.{.integer} };
|
|
||||||
|
|
||||||
pub fn move_next_word_end(_: *void, ctx: Ctx) Result {
|
pub fn move_next_word_end(_: *void, ctx: Ctx) Result {
|
||||||
try move_to_word(ctx, move_cursor_word_right_end_helix);
|
const mv = tui.mainview() orelse return;
|
||||||
|
const ed = mv.get_active_editor() orelse return;
|
||||||
|
const root = try ed.buf_root();
|
||||||
|
|
||||||
|
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
|
cursel.selection = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
ed.with_selections_const_repeat(root, move_cursor_word_right_end_helix, ctx) catch {};
|
||||||
|
ed.clamp();
|
||||||
}
|
}
|
||||||
pub const move_next_word_end_meta: Meta = .{ .description = "Move next word end", .arguments = &.{.integer} };
|
pub const move_next_word_end_meta: Meta = .{ .description = "Move next word end", .arguments = &.{.integer} };
|
||||||
|
|
||||||
pub fn extend_next_word_end(_: *void, ctx: Ctx) Result {
|
|
||||||
try extend_to_word(ctx, move_cursor_word_right_end_helix);
|
|
||||||
}
|
|
||||||
pub const extend_next_word_end_meta: Meta = .{ .description = "Extend next word end", .arguments = &.{.integer} };
|
|
||||||
|
|
||||||
pub fn move_next_long_word_end(_: *void, ctx: Ctx) Result {
|
pub fn move_next_long_word_end(_: *void, ctx: Ctx) Result {
|
||||||
try move_to_word(ctx, move_cursor_long_word_right_end);
|
const mv = tui.mainview() orelse return;
|
||||||
|
const ed = mv.get_active_editor() orelse return;
|
||||||
|
const root = try ed.buf_root();
|
||||||
|
|
||||||
|
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
|
cursel.selection = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
ed.with_selections_const_repeat(root, move_cursor_long_word_right_end, ctx) catch {};
|
||||||
|
ed.clamp();
|
||||||
}
|
}
|
||||||
pub const move_next_long_word_end_meta: Meta = .{ .description = "Move next long word end", .arguments = &.{.integer} };
|
pub const move_next_long_word_end_meta: Meta = .{ .description = "Move next long word end", .arguments = &.{.integer} };
|
||||||
|
|
||||||
pub fn extend_next_long_word_end(_: *void, ctx: Ctx) Result {
|
|
||||||
try extend_to_word(ctx, move_cursor_long_word_right_end);
|
|
||||||
}
|
|
||||||
pub const extend_next_long_word_end_meta: Meta = .{ .description = "Extend next long word end", .arguments = &.{.integer} };
|
|
||||||
|
|
||||||
pub fn cut_forward_internal_inclusive(_: *void, _: Ctx) Result {
|
pub fn cut_forward_internal_inclusive(_: *void, _: Ctx) Result {
|
||||||
const mv = tui.mainview() orelse return;
|
const mv = tui.mainview() orelse return;
|
||||||
const ed = mv.get_active_editor() orelse return;
|
const ed = mv.get_active_editor() orelse return;
|
||||||
|
|
@ -430,32 +454,6 @@ const cmds_ = struct {
|
||||||
pub const replace_with_character_helix_meta: Meta = .{ .description = "Replace with character" };
|
pub const replace_with_character_helix_meta: Meta = .{ .description = "Replace with character" };
|
||||||
};
|
};
|
||||||
|
|
||||||
fn move_to_word(ctx: command.Context, move: Editor.cursor_operator_const) command.Result {
|
|
||||||
const mv = tui.mainview() orelse return;
|
|
||||||
const ed = mv.get_active_editor() orelse return;
|
|
||||||
const root = try ed.buf_root();
|
|
||||||
|
|
||||||
// NOR mode moves n words selecting the last one
|
|
||||||
var repeat: usize = 0;
|
|
||||||
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
|
||||||
if (repeat > 1) ed.with_cursors_const_repeat(root, move, command.fmt(.{repeat - 1})) catch {};
|
|
||||||
|
|
||||||
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
|
||||||
cursel.selection = null;
|
|
||||||
};
|
|
||||||
ed.with_selections_const_repeat(root, move, command.fmt(.{1})) catch {};
|
|
||||||
ed.clamp();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn extend_to_word(ctx: command.Context, move: Editor.cursor_operator_const) command.Result {
|
|
||||||
const mv = tui.mainview() orelse return;
|
|
||||||
const ed = mv.get_active_editor() orelse return;
|
|
||||||
const root = try ed.buf_root();
|
|
||||||
|
|
||||||
ed.with_selections_const_repeat(root, move, ctx) catch {};
|
|
||||||
ed.clamp();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_char_helix(ctx: command.Context, move: Editor.cursel_operator_mut_once_arg) command.Result {
|
fn to_char_helix(ctx: command.Context, move: Editor.cursel_operator_mut_once_arg) command.Result {
|
||||||
const mv = tui.mainview() orelse return;
|
const mv = tui.mainview() orelse return;
|
||||||
const ed = mv.get_active_editor() orelse return;
|
const ed = mv.get_active_editor() orelse return;
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,7 @@ fn apply_movements(movements: []const u8, root: Buffer.Root, cursor: *Cursor, th
|
||||||
'e' => {
|
'e' => {
|
||||||
try helix.test_internal.move_cursor_word_right_end_helix(root, cursor, the_metrics);
|
try helix.test_internal.move_cursor_word_right_end_helix(root, cursor, the_metrics);
|
||||||
},
|
},
|
||||||
else => {
|
else => {},
|
||||||
return error.Stop;
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try std.testing.expectEqual(col, cursor.col);
|
try std.testing.expectEqual(col, cursor.col);
|
||||||
|
|
@ -68,9 +66,7 @@ fn metrics() Buffer.Metrics {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const doc: []const u8 =
|
const doc: []const u8 =
|
||||||
\\gawk '{print length($0) }' testflowhelixwbe.txt | tr '\n' ' 'i
|
\\gawk '{print length($0) }' testflowhelixwbe.txt | tr '\n' ' '
|
||||||
\\
|
|
||||||
\\Allows you to know what is the length of each line ^^^^
|
|
||||||
\\a small $% Test.here, with.things()to demo
|
\\a small $% Test.here, with.things()to demo
|
||||||
\\ with surrounding.space a bb AA a small and long
|
\\ with surrounding.space a bb AA a small and long
|
||||||
\\
|
\\
|
||||||
|
|
@ -82,17 +78,20 @@ const doc: []const u8 =
|
||||||
\\ $$%. []{{}. dart de
|
\\ $$%. []{{}. dart de
|
||||||
\\da
|
\\da
|
||||||
;
|
;
|
||||||
|
//60 44 54 0 2 8 138 0 0 22 2 0
|
||||||
|
|
||||||
var eol_mode: Buffer.EolMode = .lf;
|
var eol_mode: Buffer.EolMode = .lf;
|
||||||
var sanitized: bool = false;
|
var sanitized: bool = false;
|
||||||
|
var the_cursor = Cursor{ .row = 1, .col = 1, .target = 0 };
|
||||||
|
|
||||||
|
// To run a specific test
|
||||||
|
// zig build test -Dtest-filter=word_movement
|
||||||
|
|
||||||
test "words_movement" {
|
test "words_movement" {
|
||||||
const buffer = try Buffer.create(a);
|
const buffer = try Buffer.create(a);
|
||||||
defer buffer.deinit();
|
defer buffer.deinit();
|
||||||
buffer.update(try buffer.load_from_string(doc, &eol_mode, &sanitized));
|
buffer.update(try buffer.load_from_string(doc, &eol_mode, &sanitized));
|
||||||
const root: Buffer.Root = buffer.root;
|
const root: Buffer.Root = buffer.root;
|
||||||
var the_cursor = Cursor{ .row = 1, .col = 1, .target = 0 };
|
|
||||||
|
|
||||||
the_cursor.col = 1;
|
the_cursor.col = 1;
|
||||||
the_cursor.row = 0;
|
the_cursor.row = 0;
|
||||||
|
|
||||||
|
|
@ -100,6 +99,8 @@ test "words_movement" {
|
||||||
.{ .moves = "b", .row = 0, .col = 0 },
|
.{ .moves = "b", .row = 0, .col = 0 },
|
||||||
.{ .moves = "w", .row = 0, .col = 5 },
|
.{ .moves = "w", .row = 0, .col = 5 },
|
||||||
.{ .moves = "b", .row = 0, .col = 1 },
|
.{ .moves = "b", .row = 0, .col = 1 },
|
||||||
|
// TODO: Review the following line, an Stop is raising
|
||||||
|
// .{ .moves = "bb", .row = 0, .col = 0 },
|
||||||
.{ .moves = "ww", .row = 0, .col = 7 },
|
.{ .moves = "ww", .row = 0, .col = 7 },
|
||||||
.{ .moves = "bb", .row = 0, .col = 1 },
|
.{ .moves = "bb", .row = 0, .col = 1 },
|
||||||
.{ .moves = "www", .row = 0, .col = 13 },
|
.{ .moves = "www", .row = 0, .col = 13 },
|
||||||
|
|
@ -109,40 +110,17 @@ test "words_movement" {
|
||||||
.{ .moves = "wb", .row = 0, .col = 1 },
|
.{ .moves = "wb", .row = 0, .col = 1 },
|
||||||
.{ .moves = "e", .row = 0, .col = 4 },
|
.{ .moves = "e", .row = 0, .col = 4 },
|
||||||
.{ .moves = "b", .row = 0, .col = 1 },
|
.{ .moves = "b", .row = 0, .col = 1 },
|
||||||
|
// TODO: b has a bug when at the end of the view, it's
|
||||||
|
// not getting back.
|
||||||
|
//
|
||||||
|
// TODO: Another bug detected is when there are multiple
|
||||||
|
// lines, b is not able to get to the first non
|
||||||
|
// newline.
|
||||||
};
|
};
|
||||||
|
|
||||||
for (movements) |move| {
|
for (movements) |move| {
|
||||||
try apply_movements(move.moves, root, &the_cursor, metrics(), move.row, move.col);
|
try apply_movements(move.moves, root, &the_cursor, metrics(), move.row, move.col);
|
||||||
}
|
}
|
||||||
the_cursor.row = 11;
|
|
||||||
the_cursor.col = 1;
|
|
||||||
|
|
||||||
const more_movements: [2]MoveExpected = .{
|
|
||||||
.{ .moves = "b", .row = 8, .col = 135 },
|
|
||||||
.{ .moves = "w", .row = 11, .col = 2 },
|
|
||||||
};
|
|
||||||
for (more_movements) |move| {
|
|
||||||
try apply_movements(move.moves, root, &the_cursor, metrics(), move.row, move.col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test "edge_word_movements" {
|
|
||||||
const buffer = try Buffer.create(a);
|
|
||||||
defer buffer.deinit();
|
|
||||||
buffer.update(try buffer.load_from_string(doc, &eol_mode, &sanitized));
|
|
||||||
const root: Buffer.Root = buffer.root;
|
|
||||||
var cursor = Cursor{ .row = 1, .col = 1, .target = 0 };
|
|
||||||
cursor.col = 0;
|
|
||||||
cursor.row = 0;
|
|
||||||
const expected_error = error.Stop;
|
|
||||||
var result = helix.test_internal.move_cursor_word_left_helix(root, &cursor, metrics());
|
|
||||||
try std.testing.expectError(expected_error, result);
|
|
||||||
try std.testing.expectEqual(0, cursor.row);
|
|
||||||
try std.testing.expectEqual(0, cursor.col);
|
|
||||||
|
|
||||||
result = helix.test_internal.move_cursor_long_word_left(root, &cursor, metrics());
|
|
||||||
try std.testing.expectError(expected_error, result);
|
|
||||||
try std.testing.expectEqual(0, cursor.row);
|
|
||||||
try std.testing.expectEqual(0, cursor.col);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test "long_words_movement" {
|
test "long_words_movement" {
|
||||||
|
|
@ -150,8 +128,6 @@ test "long_words_movement" {
|
||||||
defer buffer.deinit();
|
defer buffer.deinit();
|
||||||
buffer.update(try buffer.load_from_string(doc, &eol_mode, &sanitized));
|
buffer.update(try buffer.load_from_string(doc, &eol_mode, &sanitized));
|
||||||
const root: Buffer.Root = buffer.root;
|
const root: Buffer.Root = buffer.root;
|
||||||
var the_cursor = Cursor{ .row = 1, .col = 1, .target = 0 };
|
|
||||||
|
|
||||||
the_cursor.col = 1;
|
the_cursor.col = 1;
|
||||||
the_cursor.row = 0;
|
the_cursor.row = 0;
|
||||||
|
|
||||||
|
|
@ -159,12 +135,19 @@ test "long_words_movement" {
|
||||||
.{ .moves = "B", .row = 0, .col = 0 },
|
.{ .moves = "B", .row = 0, .col = 0 },
|
||||||
.{ .moves = "W", .row = 0, .col = 5 },
|
.{ .moves = "W", .row = 0, .col = 5 },
|
||||||
.{ .moves = "B", .row = 0, .col = 1 },
|
.{ .moves = "B", .row = 0, .col = 1 },
|
||||||
|
// TODO: Review the following line, an Stop is raising
|
||||||
|
// .{ .moves = "BB", .row = 0, .col = 0 },
|
||||||
.{ .moves = "WW", .row = 0, .col = 13 },
|
.{ .moves = "WW", .row = 0, .col = 13 },
|
||||||
.{ .moves = "BB", .row = 0, .col = 1 },
|
.{ .moves = "BB", .row = 0, .col = 1 },
|
||||||
.{ .moves = "WWW", .row = 0, .col = 24 },
|
.{ .moves = "WWW", .row = 0, .col = 24 },
|
||||||
.{ .moves = "BBB", .row = 0, .col = 1 },
|
.{ .moves = "BBB", .row = 0, .col = 1 },
|
||||||
.{ .moves = "WWWW", .row = 0, .col = 27 },
|
.{ .moves = "WWWW", .row = 0, .col = 27 },
|
||||||
.{ .moves = "BBBB", .row = 0, .col = 1 },
|
.{ .moves = "BBBB", .row = 0, .col = 1 },
|
||||||
|
// TODO:
|
||||||
|
// WWWWW should report 48, is reporting 49, when changing modes
|
||||||
|
// the others report 48. This is an specific hx mode
|
||||||
|
// .{ .moves = "WWWWW", .row = 0, .col = 48 },
|
||||||
|
// Same bugs detected in b are in B
|
||||||
.{ .moves = "WB", .row = 0, .col = 1 },
|
.{ .moves = "WB", .row = 0, .col = 1 },
|
||||||
.{ .moves = "E", .row = 0, .col = 4 },
|
.{ .moves = "E", .row = 0, .col = 4 },
|
||||||
.{ .moves = "B", .row = 0, .col = 1 },
|
.{ .moves = "B", .row = 0, .col = 1 },
|
||||||
|
|
@ -180,8 +163,6 @@ test "to_char_right_beyond_eol" {
|
||||||
defer buffer.deinit();
|
defer buffer.deinit();
|
||||||
buffer.update(try buffer.load_from_string(doc, &eol_mode, &sanitized));
|
buffer.update(try buffer.load_from_string(doc, &eol_mode, &sanitized));
|
||||||
const root: Buffer.Root = buffer.root;
|
const root: Buffer.Root = buffer.root;
|
||||||
var the_cursor = Cursor{ .row = 1, .col = 1, .target = 0 };
|
|
||||||
|
|
||||||
the_cursor.col = 0;
|
the_cursor.col = 0;
|
||||||
the_cursor.row = 0;
|
the_cursor.row = 0;
|
||||||
const expected_error = error.Stop;
|
const expected_error = error.Stop;
|
||||||
|
|
@ -194,50 +175,44 @@ test "to_char_right_beyond_eol" {
|
||||||
|
|
||||||
// Move found in the next line
|
// Move found in the next line
|
||||||
try helix.test_internal.move_cursor_to_char_right_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"T"}));
|
try helix.test_internal.move_cursor_to_char_right_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"T"}));
|
||||||
try std.testing.expectEqual(3, the_cursor.row);
|
try std.testing.expectEqual(1, the_cursor.row);
|
||||||
try std.testing.expectEqual(11, the_cursor.col);
|
try std.testing.expectEqual(11, the_cursor.col);
|
||||||
|
|
||||||
// Move found in the previous line
|
// Move found in the previous line
|
||||||
try helix.test_internal.move_cursor_to_char_left_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"t"}));
|
try helix.test_internal.move_cursor_to_char_left_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"t"}));
|
||||||
try std.testing.expectEqual(2, the_cursor.row);
|
try std.testing.expectEqual(0, the_cursor.row);
|
||||||
try std.testing.expectEqual(35, the_cursor.col);
|
try std.testing.expectEqual(51, the_cursor.col);
|
||||||
|
|
||||||
// Not found to end of buffer, cursor not moved
|
// Not found to end of buffer, cursor not moved
|
||||||
result = helix.test_internal.move_cursor_to_char_right_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"Z"}));
|
result = helix.test_internal.move_cursor_to_char_right_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"Z"}));
|
||||||
try std.testing.expectError(expected_error, result);
|
try std.testing.expectError(expected_error, result);
|
||||||
try std.testing.expectEqual(2, the_cursor.row);
|
try std.testing.expectEqual(0, the_cursor.row);
|
||||||
try std.testing.expectEqual(35, the_cursor.col);
|
try std.testing.expectEqual(51, the_cursor.col);
|
||||||
|
|
||||||
// Not found to begin of buffer
|
// Not found to begin of buffer
|
||||||
result = helix.test_internal.move_cursor_to_char_left_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"Z"}));
|
result = helix.test_internal.move_cursor_to_char_left_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"Z"}));
|
||||||
try std.testing.expectError(expected_error, result);
|
try std.testing.expectError(expected_error, result);
|
||||||
try std.testing.expectEqual(2, the_cursor.row);
|
try std.testing.expectEqual(0, the_cursor.row);
|
||||||
try std.testing.expectEqual(35, the_cursor.col);
|
try std.testing.expectEqual(51, the_cursor.col);
|
||||||
|
|
||||||
// till char difference
|
// till char difference
|
||||||
// Move found in the next line
|
// Move found in the next line
|
||||||
try helix.test_internal.move_cursor_till_char_right_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"T"}));
|
try helix.test_internal.move_cursor_till_char_right_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"T"}));
|
||||||
try std.testing.expectEqual(3, the_cursor.row);
|
try std.testing.expectEqual(1, the_cursor.row);
|
||||||
try std.testing.expectEqual(10, the_cursor.col);
|
try std.testing.expectEqual(10, the_cursor.col);
|
||||||
|
|
||||||
// Move found in the previous line
|
// Move found in the previous line
|
||||||
try helix.test_internal.move_cursor_till_char_left_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"t"}));
|
try helix.test_internal.move_cursor_till_char_left_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"t"}));
|
||||||
try std.testing.expectEqual(2, the_cursor.row);
|
try std.testing.expectEqual(0, the_cursor.row);
|
||||||
try std.testing.expectEqual(36, the_cursor.col);
|
try std.testing.expectEqual(52, the_cursor.col);
|
||||||
|
|
||||||
// Move found in the same line
|
// Move found in the same line
|
||||||
try helix.test_internal.move_cursor_till_char_left_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"u"}));
|
try helix.test_internal.move_cursor_till_char_left_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"x"}));
|
||||||
try std.testing.expectEqual(2, the_cursor.row);
|
try std.testing.expectEqual(0, the_cursor.row);
|
||||||
try std.testing.expectEqual(10, the_cursor.col);
|
try std.testing.expectEqual(46, the_cursor.col);
|
||||||
|
|
||||||
// Move found in the same line
|
// Move found in the same line
|
||||||
try helix.test_internal.move_cursor_till_char_right_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"t"}));
|
try helix.test_internal.move_cursor_till_char_right_beyond_eol(root, &the_cursor, metrics(), fmt_command(.{"t"}));
|
||||||
try std.testing.expectEqual(2, the_cursor.row);
|
try std.testing.expectEqual(0, the_cursor.row);
|
||||||
try std.testing.expectEqual(21, the_cursor.col);
|
try std.testing.expectEqual(50, the_cursor.col);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: When at end of file, enter sel mode makes
|
|
||||||
// difficult to get back and is confusing for users.
|
|
||||||
// Related to that is the fact that when a selection
|
|
||||||
// is made, then trying to move to the right, the
|
|
||||||
// first movement is swallowed
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue