Merge branch 'master' into zig-0.14

This commit is contained in:
CJ van den Berg 2025-02-25 21:40:53 +01:00
commit 8f9b2d15f7
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -1974,21 +1974,29 @@ pub const Editor = struct {
return false;
}
fn is_white_space(c: []const u8) bool {
fn is_whitespace(c: []const u8) bool {
return (c.len == 0) or (c[0] == ' ') or (c[0] == '\t');
}
fn is_white_space_at_cursor(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
return cursor.test_at(root, is_white_space, metrics);
fn is_whitespace_or_eol(c: []const u8) bool {
return is_whitespace(c) or c[0] == '\n';
}
fn is_whitespace_at_cursor(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
return cursor.test_at(root, is_whitespace, metrics);
}
fn is_non_whitespace_at_cursor(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
return !cursor.test_at(root, is_whitespace_or_eol, metrics);
}
fn is_word_boundary_left_vim(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
if (is_white_space_at_cursor(root, cursor, metrics)) return false;
if (is_whitespace_at_cursor(root, cursor, metrics)) return false;
var next = cursor.*;
next.move_left(root, metrics) catch return true;
const next_is_white_space = is_white_space_at_cursor(root, &next, metrics);
if (next_is_white_space) return true;
const next_is_whitespace = is_whitespace_at_cursor(root, &next, metrics);
if (next_is_whitespace) return true;
const curr_is_non_word = is_non_word_char_at_cursor(root, cursor, metrics);
const next_is_non_word = is_non_word_char_at_cursor(root, &next, metrics);
@ -2021,12 +2029,12 @@ pub const Editor = struct {
}
fn is_word_boundary_right_vim(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
if (is_white_space_at_cursor(root, cursor, metrics)) return false;
if (is_whitespace_at_cursor(root, cursor, metrics)) return false;
var next = cursor.*;
next.move_right(root, metrics) catch return true;
const next_is_white_space = is_white_space_at_cursor(root, &next, metrics);
if (next_is_white_space) return true;
const next_is_whitespace = is_whitespace_at_cursor(root, &next, metrics);
if (next_is_whitespace) return true;
const curr_is_non_word = is_non_word_char_at_cursor(root, cursor, metrics);
const next_is_non_word = is_non_word_char_at_cursor(root, &next, metrics);
@ -2824,7 +2832,10 @@ pub const Editor = struct {
pub fn join_next_line(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
try self.with_cursors_const(b.root, move_cursor_end);
const root = try self.delete_to(move_cursor_right, b.root, b.allocator);
var root = try self.delete_to(move_cursor_right_until_non_whitespace, b.root, b.allocator);
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
root = try self.insert(root, cursel, " ", b.allocator);
};
try self.update_buf(root);
self.clamp();
}
@ -2935,6 +2946,10 @@ pub const Editor = struct {
try move_cursor_right(root, cursor, metrics);
}
pub fn move_cursor_right_until_non_whitespace(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
move_cursor_right_until(root, cursor, is_non_whitespace_at_cursor, metrics);
}
pub fn move_word_left(self: *Self, _: Context) Result {
const root = try self.buf_root();
self.with_cursors_const(root, move_cursor_word_left) catch {};