Compare commits
No commits in common. "276f7214566b6e47fa157f1a2f39511cd423482c" and "06788c4243568021becc11db1b6e62e752b90478" have entirely different histories.
276f721456
...
06788c4243
2 changed files with 24 additions and 32 deletions
|
|
@ -2612,11 +2612,11 @@ pub const Editor = struct {
|
||||||
return try copy_selection(root, sel.*, text_allocator, self.metrics);
|
return try copy_selection(root, sel.*, text_allocator, self.metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cut_selection(self: *Self, root: Buffer.Root, cursel: *CurSel, text_allocator: Allocator) !struct { []const u8, Buffer.Root } {
|
pub fn cut_selection(self: *Self, root: Buffer.Root, cursel: *CurSel) !struct { []const u8, Buffer.Root } {
|
||||||
return if (cursel.selection) |sel| ret: {
|
return if (cursel.selection) |sel| ret: {
|
||||||
var old_selection: Selection = sel;
|
var old_selection: Selection = sel;
|
||||||
old_selection.normalize();
|
old_selection.normalize();
|
||||||
const cut_text = try copy_selection(root, sel, text_allocator, self.metrics);
|
const cut_text = try copy_selection(root, sel, self.allocator, self.metrics);
|
||||||
if (cut_text.len > 100) {
|
if (cut_text.len > 100) {
|
||||||
self.logger.print("cut:{f}...", .{std.ascii.hexEscape(cut_text[0..100], .lower)});
|
self.logger.print("cut:{f}...", .{std.ascii.hexEscape(cut_text[0..100], .lower)});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2652,43 +2652,41 @@ pub const Editor = struct {
|
||||||
return root_;
|
return root_;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cut_to(self: *Self, move: cursor_operator_const, root_: Buffer.Root, text_allocator: Allocator) !struct { []const u8, Buffer.Root } {
|
pub fn cut_to(self: *Self, move: cursor_operator_const, root_: Buffer.Root) !struct { []const u8, Buffer.Root } {
|
||||||
var all_stop = true;
|
var all_stop = true;
|
||||||
var root = root_;
|
var root = root_;
|
||||||
|
|
||||||
var text = std.ArrayListUnmanaged(u8).empty;
|
var text = std.ArrayListUnmanaged(u8).empty;
|
||||||
defer text.deinit(text_allocator);
|
defer text.deinit(self.allocator);
|
||||||
var first = true;
|
var first = true;
|
||||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
if (cursel.selection) |_| {
|
if (cursel.selection) |_| {
|
||||||
const cut_text, root = self.cut_selection(root, cursel, text_allocator) catch continue;
|
const cut_text, root = self.cut_selection(root, cursel) catch continue;
|
||||||
defer text_allocator.free(cut_text);
|
|
||||||
all_stop = false;
|
all_stop = false;
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
try text.appendSlice(text_allocator, "\n");
|
try text.appendSlice(self.allocator, "\n");
|
||||||
}
|
}
|
||||||
try text.appendSlice(text_allocator, cut_text);
|
try text.appendSlice(self.allocator, cut_text);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
with_selection_const(root, move, cursel, self.metrics) catch continue;
|
with_selection_const(root, move, cursel, self.metrics) catch continue;
|
||||||
const cut_text, root = self.cut_selection(root, cursel, text_allocator) catch continue;
|
const cut_text, root = self.cut_selection(root, cursel) catch continue;
|
||||||
defer text_allocator.free(cut_text);
|
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
try text.appendSlice(text_allocator, "\n");
|
try text.appendSlice(self.allocator, "\n");
|
||||||
}
|
}
|
||||||
try text.appendSlice(text_allocator, cut_text);
|
try text.appendSlice(self.allocator, cut_text);
|
||||||
all_stop = false;
|
all_stop = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (all_stop)
|
if (all_stop)
|
||||||
return error.Stop;
|
return error.Stop;
|
||||||
return .{ try text.toOwnedSlice(text_allocator), root };
|
return .{ try text.toOwnedSlice(self.allocator), root };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cut_internal_vim(self: *Self, _: Context) Result {
|
pub fn cut_internal_vim(self: *Self, _: Context) Result {
|
||||||
|
|
@ -2707,8 +2705,7 @@ pub const Editor = struct {
|
||||||
};
|
};
|
||||||
var first = true;
|
var first = true;
|
||||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
const cut_text, root = try self.cut_selection(root, cursel, self.allocator);
|
const cut_text, root = try self.cut_selection(root, cursel);
|
||||||
defer self.allocator.free(cut_text);
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2743,8 +2740,7 @@ pub const Editor = struct {
|
||||||
var text = std.ArrayListUnmanaged(u8).empty;
|
var text = std.ArrayListUnmanaged(u8).empty;
|
||||||
defer text.deinit(self.allocator);
|
defer text.deinit(self.allocator);
|
||||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
const cut_text, root = try self.cut_selection(root, cursel, self.allocator);
|
const cut_text, root = try self.cut_selection(root, cursel);
|
||||||
defer self.allocator.free(cut_text);
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2774,8 +2770,6 @@ pub const Editor = struct {
|
||||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
if (cursel.selection) |sel| {
|
if (cursel.selection) |sel| {
|
||||||
const copy_text = try copy_selection(root, sel, self.allocator, self.metrics);
|
const copy_text = try copy_selection(root, sel, self.allocator, self.metrics);
|
||||||
defer self.allocator.free(copy_text);
|
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2872,7 +2866,6 @@ pub const Editor = struct {
|
||||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
if (cursel.selection) |sel| {
|
if (cursel.selection) |sel| {
|
||||||
const copy_text = try copy_selection(root, sel, self.allocator, self.metrics);
|
const copy_text = try copy_selection(root, sel, self.allocator, self.metrics);
|
||||||
defer self.allocator.free(copy_text);
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2908,7 +2901,6 @@ pub const Editor = struct {
|
||||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
if (cursel.selection) |sel| {
|
if (cursel.selection) |sel| {
|
||||||
const copy_text = try copy_selection(root, sel, self.allocator, self.metrics);
|
const copy_text = try copy_selection(root, sel, self.allocator, self.metrics);
|
||||||
defer self.allocator.free(copy_text);
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -3018,7 +3010,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
pub fn cut_forward_internal(self: *Self, _: Context) Result {
|
pub fn cut_forward_internal(self: *Self, _: Context) Result {
|
||||||
const b = try self.buf_for_update();
|
const b = try self.buf_for_update();
|
||||||
const text, const root = try self.cut_to(move_cursor_right, b.root, self.allocator);
|
const text, const root = try self.cut_to(move_cursor_right, b.root);
|
||||||
self.set_clipboard_internal(text);
|
self.set_clipboard_internal(text);
|
||||||
try self.update_buf(root);
|
try self.update_buf(root);
|
||||||
self.clamp();
|
self.clamp();
|
||||||
|
|
@ -3102,7 +3094,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
pub fn cut_buffer_end(self: *Self, _: Context) Result {
|
pub fn cut_buffer_end(self: *Self, _: Context) Result {
|
||||||
const b = try self.buf_for_update();
|
const b = try self.buf_for_update();
|
||||||
const text, const root = try self.cut_to(move_cursor_buffer_end, b.root, self.allocator);
|
const text, const root = try self.cut_to(move_cursor_buffer_end, b.root);
|
||||||
self.set_clipboard_internal(text);
|
self.set_clipboard_internal(text);
|
||||||
try self.update_buf(root);
|
try self.update_buf(root);
|
||||||
self.clamp();
|
self.clamp();
|
||||||
|
|
@ -3111,7 +3103,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
pub fn cut_buffer_begin(self: *Self, _: Context) Result {
|
pub fn cut_buffer_begin(self: *Self, _: Context) Result {
|
||||||
const b = try self.buf_for_update();
|
const b = try self.buf_for_update();
|
||||||
const text, const root = try self.cut_to(move_cursor_buffer_begin, b.root, self.allocator);
|
const text, const root = try self.cut_to(move_cursor_buffer_begin, b.root);
|
||||||
self.set_clipboard_internal(text);
|
self.set_clipboard_internal(text);
|
||||||
try self.update_buf(root);
|
try self.update_buf(root);
|
||||||
self.clamp();
|
self.clamp();
|
||||||
|
|
@ -3120,7 +3112,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
pub fn cut_word_left_vim(self: *Self, _: Context) Result {
|
pub fn cut_word_left_vim(self: *Self, _: Context) Result {
|
||||||
const b = try self.buf_for_update();
|
const b = try self.buf_for_update();
|
||||||
const text, const root = try self.cut_to(move_cursor_word_left_vim, b.root, self.allocator);
|
const text, const root = try self.cut_to(move_cursor_word_left_vim, b.root);
|
||||||
self.set_clipboard_internal(text);
|
self.set_clipboard_internal(text);
|
||||||
try self.update_buf(root);
|
try self.update_buf(root);
|
||||||
self.clamp();
|
self.clamp();
|
||||||
|
|
@ -3137,7 +3129,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
pub fn cut_word_right_vim(self: *Self, _: Context) Result {
|
pub fn cut_word_right_vim(self: *Self, _: Context) Result {
|
||||||
const b = try self.buf_for_update();
|
const b = try self.buf_for_update();
|
||||||
const text, const root = try self.cut_to(move_cursor_word_right_vim, b.root, self.allocator);
|
const text, const root = try self.cut_to(move_cursor_word_right_vim, b.root);
|
||||||
self.set_clipboard_internal(text);
|
self.set_clipboard_internal(text);
|
||||||
try self.update_buf(root);
|
try self.update_buf(root);
|
||||||
self.clamp();
|
self.clamp();
|
||||||
|
|
@ -3162,7 +3154,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
pub fn cut_to_end_vim(self: *Self, _: Context) Result {
|
pub fn cut_to_end_vim(self: *Self, _: Context) Result {
|
||||||
const b = try self.buf_for_update();
|
const b = try self.buf_for_update();
|
||||||
const text, const root = try self.cut_to(move_cursor_end_vim, b.root, self.allocator);
|
const text, const root = try self.cut_to(move_cursor_end_vim, b.root);
|
||||||
self.set_clipboard_internal(text);
|
self.set_clipboard_internal(text);
|
||||||
try self.update_buf(root);
|
try self.update_buf(root);
|
||||||
self.clamp();
|
self.clamp();
|
||||||
|
|
@ -5046,8 +5038,8 @@ pub const Editor = struct {
|
||||||
pub fn find_word_at_cursor(self: *Self, ctx: Context) Result {
|
pub fn find_word_at_cursor(self: *Self, ctx: Context) Result {
|
||||||
_ = ctx;
|
_ = ctx;
|
||||||
const query: []const u8 = try self.copy_word_at_cursor(self.allocator);
|
const query: []const u8 = try self.copy_word_at_cursor(self.allocator);
|
||||||
defer self.allocator.free(query);
|
|
||||||
try self.find_in_buffer(query);
|
try self.find_in_buffer(query);
|
||||||
|
self.allocator.free(query);
|
||||||
}
|
}
|
||||||
pub const find_word_at_cursor_meta: Meta = .{ .description = "Search for the word under the cursor" };
|
pub const find_word_at_cursor_meta: Meta = .{ .description = "Search for the word under the cursor" };
|
||||||
|
|
||||||
|
|
@ -5946,7 +5938,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
pub const to_upper_meta: Meta = .{ .description = "Convert selection or word to upper case" };
|
pub const to_upper_meta: Meta = .{ .description = "Convert selection or word to upper case" };
|
||||||
|
|
||||||
fn to_lower_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, buffer_allocator: Allocator) error{Stop}!Buffer.Root {
|
fn to_lower_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
|
||||||
var root = root_;
|
var root = root_;
|
||||||
const saved = cursel.*;
|
const saved = cursel.*;
|
||||||
const sel = if (cursel.selection) |*sel| sel else ret: {
|
const sel = if (cursel.selection) |*sel| sel else ret: {
|
||||||
|
|
@ -5961,8 +5953,8 @@ pub const Editor = struct {
|
||||||
defer sfa_allocator.free(cut_text);
|
defer sfa_allocator.free(cut_text);
|
||||||
const ucased = Buffer.unicode.get_letter_casing().toLowerStr(sfa_allocator, cut_text) catch return error.Stop;
|
const ucased = Buffer.unicode.get_letter_casing().toLowerStr(sfa_allocator, cut_text) catch return error.Stop;
|
||||||
defer sfa_allocator.free(ucased);
|
defer sfa_allocator.free(ucased);
|
||||||
root = try self.delete_selection(root, cursel, buffer_allocator);
|
root = try self.delete_selection(root, cursel, allocator);
|
||||||
root = self.insert(root, cursel, ucased, buffer_allocator) catch return error.Stop;
|
root = self.insert(root, cursel, ucased, allocator) catch return error.Stop;
|
||||||
cursel.* = saved;
|
cursel.* = saved;
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ const cmds_ = struct {
|
||||||
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;
|
||||||
const b = try ed.buf_for_update();
|
const b = try ed.buf_for_update();
|
||||||
const text, const root = try ed.cut_to(move_noop, b.root, ed.allocator);
|
const text, const root = try ed.cut_to(move_noop, b.root);
|
||||||
ed.set_clipboard_internal(text);
|
ed.set_clipboard_internal(text);
|
||||||
try ed.update_buf(root);
|
try ed.update_buf(root);
|
||||||
ed.clamp();
|
ed.clamp();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue