Merge branch 'master' into zig-0.14
This commit is contained in:
commit
a959563bc7
11 changed files with 253 additions and 75 deletions
|
@ -2774,6 +2774,49 @@ pub const Editor = struct {
|
|||
}
|
||||
pub const delete_backward_meta: Meta = .{ .description = "Delete previous character" };
|
||||
|
||||
pub fn smart_delete_backward(self: *Self, _: Context) Result {
|
||||
const b = try self.buf_for_update();
|
||||
var all_stop = true;
|
||||
var root = b.root;
|
||||
|
||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||
if (cursel.selection) |_| {
|
||||
root = self.delete_selection(root, cursel, b.allocator) catch continue;
|
||||
all_stop = false;
|
||||
continue;
|
||||
}
|
||||
with_selection_const(root, move_cursor_left, cursel, self.metrics) catch continue;
|
||||
|
||||
if (cursel.selection) |*sel| {
|
||||
const egc_left, _, _ = sel.end.egc_at(root, self.metrics) catch {
|
||||
root = self.delete_selection(root, cursel, b.allocator) catch continue;
|
||||
all_stop = false;
|
||||
continue;
|
||||
};
|
||||
const egc_right, _, _ = sel.begin.egc_at(root, self.metrics) catch {
|
||||
root = self.delete_selection(root, cursel, b.allocator) catch continue;
|
||||
all_stop = false;
|
||||
continue;
|
||||
};
|
||||
|
||||
for (Buffer.unicode.char_pairs) |pair| if (std.mem.eql(u8, egc_left, pair[0]) and std.mem.eql(u8, egc_right, pair[1])) {
|
||||
sel.begin.move_right(root, self.metrics) catch {};
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
root = self.delete_selection(root, cursel, b.allocator) catch continue;
|
||||
all_stop = false;
|
||||
};
|
||||
|
||||
if (all_stop)
|
||||
return error.Stop;
|
||||
|
||||
try self.update_buf(root);
|
||||
self.clamp();
|
||||
}
|
||||
pub const smart_delete_backward_meta = .{ .description = "Delete previous character (smart)" };
|
||||
|
||||
pub fn delete_word_left(self: *Self, _: Context) Result {
|
||||
const b = try self.buf_for_update();
|
||||
const root = try self.delete_to(move_cursor_word_left_space, b.root, b.allocator);
|
||||
|
@ -2995,7 +3038,7 @@ pub const Editor = struct {
|
|||
return error.Stop;
|
||||
try move_cursor_left(root, cursor, metrics);
|
||||
while (true) {
|
||||
const curr_egc, _, _ = root.ecg_at(cursor.row, cursor.col, metrics) catch return error.Stop;
|
||||
const curr_egc, _, _ = root.egc_at(cursor.row, cursor.col, metrics) catch return error.Stop;
|
||||
if (std.mem.eql(u8, curr_egc, egc))
|
||||
return;
|
||||
if (is_eol_left(root, cursor, metrics))
|
||||
|
@ -3010,7 +3053,7 @@ pub const Editor = struct {
|
|||
return error.Stop;
|
||||
try move_cursor_right(root, cursor, metrics);
|
||||
while (true) {
|
||||
const curr_egc, _, _ = root.ecg_at(cursor.row, cursor.col, metrics) catch return error.Stop;
|
||||
const curr_egc, _, _ = root.egc_at(cursor.row, cursor.col, metrics) catch return error.Stop;
|
||||
if (std.mem.eql(u8, curr_egc, egc))
|
||||
return;
|
||||
if (is_eol_right(root, cursor, metrics))
|
||||
|
@ -4070,6 +4113,7 @@ pub const Editor = struct {
|
|||
if (!try ctx.args.match(.{ tp.extract(&chars_left), tp.extract(&chars_right) }))
|
||||
return error.InvalidSmartInsertPairArguments;
|
||||
const b = try self.buf_for_update();
|
||||
var move: enum { left, right } = .left;
|
||||
var root = b.root;
|
||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||
if (cursel.selection) |*sel| {
|
||||
|
@ -4078,16 +4122,60 @@ pub const Editor = struct {
|
|||
var end: CurSel = .{ .cursor = sel.end };
|
||||
root = try self.insert(root, &end, chars_right, b.allocator);
|
||||
sel.end.move_left(root, self.metrics) catch {};
|
||||
} else {
|
||||
root = try self.insert(root, cursel, chars_left, b.allocator);
|
||||
root = try self.insert(root, cursel, chars_right, b.allocator);
|
||||
} else blk: {
|
||||
const egc, _, _ = cursel.cursor.egc_at(root, self.metrics) catch {
|
||||
root = try self.insert(root, cursel, chars_left, b.allocator);
|
||||
root = try self.insert(root, cursel, chars_right, b.allocator);
|
||||
break :blk;
|
||||
};
|
||||
if (std.mem.eql(u8, egc, chars_left)) {
|
||||
move = .right;
|
||||
} else {
|
||||
root = try self.insert(root, cursel, chars_left, b.allocator);
|
||||
root = try self.insert(root, cursel, chars_right, b.allocator);
|
||||
}
|
||||
}
|
||||
switch (move) {
|
||||
.left => cursel.cursor.move_left(root, self.metrics) catch {},
|
||||
.right => cursel.cursor.move_right(root, self.metrics) catch {},
|
||||
}
|
||||
cursel.cursor.move_left(root, self.metrics) catch {};
|
||||
};
|
||||
try self.update_buf(root);
|
||||
self.clamp();
|
||||
}
|
||||
pub const smart_insert_pair_meta: Meta = .{ .arguments = &.{.string} };
|
||||
pub const smart_insert_pair_meta: Meta = .{ .arguments = &.{ .string, .string } };
|
||||
|
||||
pub fn smart_insert_pair_close(self: *Self, ctx: Context) Result {
|
||||
var chars_left: []const u8 = undefined;
|
||||
var chars_right: []const u8 = undefined;
|
||||
if (!try ctx.args.match(.{ tp.extract(&chars_left), tp.extract(&chars_right) }))
|
||||
return error.InvalidSmartInsertPairArguments;
|
||||
const b = try self.buf_for_update();
|
||||
var root = b.root;
|
||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||
if (cursel.selection) |*sel| {
|
||||
var begin: CurSel = .{ .cursor = sel.begin };
|
||||
root = try self.insert(root, &begin, chars_left, b.allocator);
|
||||
var end: CurSel = .{ .cursor = sel.end };
|
||||
root = try self.insert(root, &end, chars_right, b.allocator);
|
||||
sel.begin.move_left(root, self.metrics) catch {};
|
||||
cursel.disable_selection(root, self.metrics);
|
||||
} else blk: {
|
||||
const egc, _, _ = cursel.cursor.egc_at(root, self.metrics) catch {
|
||||
root = try self.insert(root, cursel, chars_right, b.allocator);
|
||||
break :blk;
|
||||
};
|
||||
if (std.mem.eql(u8, egc, chars_right)) {
|
||||
cursel.cursor.move_right(root, self.metrics) catch {};
|
||||
} else {
|
||||
root = try self.insert(root, cursel, chars_right, b.allocator);
|
||||
}
|
||||
}
|
||||
};
|
||||
try self.update_buf(root);
|
||||
self.clamp();
|
||||
}
|
||||
pub const smart_insert_pair_close_meta = .{ .arguments = &.{ .string, .string } };
|
||||
|
||||
pub fn enable_fast_scroll(self: *Self, _: Context) Result {
|
||||
self.fast_scroll = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue