refactor: explicity publish internal helix functions for unittests only
We don't want internal functions in the mode specific extention modules becoming shared code. To avoid this, mark the functions as private and publish only through a structure marked clearly as for testing only. If these functions are useful as shared code they can be moved to the editor module or else where.
This commit is contained in:
parent
a6f5ffcdc5
commit
c7b46856bb
2 changed files with 20 additions and 10 deletions
|
@ -454,7 +454,7 @@ const cmds_ = struct {
|
|||
pub const paste_after_meta: Meta = .{ .description = "Paste from clipboard after selection" };
|
||||
};
|
||||
|
||||
pub fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
try Editor.move_cursor_left(root, cursor, metrics);
|
||||
|
||||
// Consume " "
|
||||
|
@ -479,7 +479,7 @@ pub fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics:
|
|||
|
||||
fn move_noop(_: Buffer.Root, _: *Cursor, _: Buffer.Metrics) error{Stop}!void {}
|
||||
|
||||
pub fn move_cursor_word_right_end_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
fn move_cursor_word_right_end_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
try Editor.move_cursor_right(root, cursor, metrics);
|
||||
Editor.move_cursor_right_until(root, cursor, Editor.is_word_boundary_right_vim, metrics);
|
||||
try cursor.move_right(root, metrics);
|
||||
|
@ -535,7 +535,7 @@ fn is_long_word_boundary_left(root: Buffer.Root, cursor: *const Cursor, metrics:
|
|||
return curr_is_non_word != next_is_non_word;
|
||||
}
|
||||
|
||||
pub fn move_cursor_long_word_left(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
fn move_cursor_long_word_left(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
try Editor.move_cursor_left(root, cursor, metrics);
|
||||
|
||||
// Consume " "
|
||||
|
@ -571,7 +571,7 @@ fn is_word_boundary_right(root: Buffer.Root, cursor: *const Cursor, metrics: Buf
|
|||
return curr_is_non_word != next_is_non_word;
|
||||
}
|
||||
|
||||
pub fn move_cursor_long_word_right(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
fn move_cursor_long_word_right(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
try cursor.move_right(root, metrics);
|
||||
Editor.move_cursor_right_until(root, cursor, is_long_word_boundary_left, metrics);
|
||||
}
|
||||
|
@ -589,8 +589,18 @@ fn is_long_word_boundary_right(root: Buffer.Root, cursor: *const Cursor, metrics
|
|||
return curr_is_non_word != next_is_non_word;
|
||||
}
|
||||
|
||||
pub fn move_cursor_long_word_right_end(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
fn move_cursor_long_word_right_end(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
// try Editor.move_cursor_right(root, cursor, metrics);
|
||||
Editor.move_cursor_right_until(root, cursor, is_long_word_boundary_right, metrics);
|
||||
try cursor.move_right(root, metrics);
|
||||
}
|
||||
|
||||
const private = @This();
|
||||
// exports for unittests
|
||||
pub const test_internal = struct {
|
||||
pub const move_cursor_long_word_right = private.move_cursor_long_word_right;
|
||||
pub const move_cursor_long_word_left = private.move_cursor_long_word_left;
|
||||
pub const move_cursor_long_word_right_end = private.move_cursor_long_word_right_end;
|
||||
pub const move_cursor_word_left_helix = private.move_cursor_word_left_helix;
|
||||
pub const move_cursor_word_right_end_helix = private.move_cursor_word_right_end_helix;
|
||||
};
|
|
@ -12,22 +12,22 @@ fn apply_movements(movements: []const u8, root: Buffer.Root, cursor: *Cursor, th
|
|||
for (movements) |move| {
|
||||
switch (move) {
|
||||
'W' => {
|
||||
try helix.move_cursor_long_word_right(root, cursor, the_metrics);
|
||||
try helix.test_internal.move_cursor_long_word_right(root, cursor, the_metrics);
|
||||
},
|
||||
'B' => {
|
||||
try helix.move_cursor_long_word_left(root, cursor, the_metrics);
|
||||
try helix.test_internal.move_cursor_long_word_left(root, cursor, the_metrics);
|
||||
},
|
||||
'E' => {
|
||||
try helix.move_cursor_long_word_right_end(root, cursor, the_metrics);
|
||||
try helix.test_internal.move_cursor_long_word_right_end(root, cursor, the_metrics);
|
||||
},
|
||||
'w' => {
|
||||
try Editor.move_cursor_word_right_vim(root, cursor, the_metrics);
|
||||
},
|
||||
'b' => {
|
||||
try helix.move_cursor_word_left_helix(root, cursor, the_metrics);
|
||||
try helix.test_internal.move_cursor_word_left_helix(root, cursor, the_metrics);
|
||||
},
|
||||
'e' => {
|
||||
try helix.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 => {},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue