build: update to zig 0.14.0-dev.3039
This commit is contained in:
parent
1764b3259c
commit
53045123c6
41 changed files with 648 additions and 623 deletions
|
@ -18,7 +18,7 @@ const name = " find";
|
|||
const Commands = command.Collection(cmds);
|
||||
|
||||
allocator: Allocator,
|
||||
input: ArrayList(u8),
|
||||
input_: ArrayList(u8),
|
||||
last_input: ArrayList(u8),
|
||||
start_view: ed.View,
|
||||
start_cursor: ed.Cursor,
|
||||
|
@ -31,7 +31,7 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
|||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.input = ArrayList(u8).init(allocator),
|
||||
.input_ = ArrayList(u8).init(allocator),
|
||||
.last_input = ArrayList(u8).init(allocator),
|
||||
.start_view = editor.view,
|
||||
.start_cursor = editor.get_primary().cursor,
|
||||
|
@ -41,7 +41,7 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
|||
if (editor.get_primary().selection) |sel| ret: {
|
||||
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
||||
defer self.allocator.free(text);
|
||||
try self.input.appendSlice(text);
|
||||
try self.input_.appendSlice(text);
|
||||
}
|
||||
var mode = try keybind.mode("mini/find", allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
|
@ -52,7 +52,7 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
|||
|
||||
pub fn deinit(self: *Self) void {
|
||||
self.commands.deinit();
|
||||
self.input.deinit();
|
||||
self.input_.deinit();
|
||||
self.last_input.deinit();
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
@ -73,24 +73,24 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
|||
fn insert_code_point(self: *Self, c: u32) !void {
|
||||
var buf: [16]u8 = undefined;
|
||||
const bytes = input.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
try self.input.appendSlice(buf[0..bytes]);
|
||||
try self.input_.appendSlice(buf[0..bytes]);
|
||||
}
|
||||
|
||||
fn insert_bytes(self: *Self, bytes: []const u8) !void {
|
||||
try self.input.appendSlice(bytes);
|
||||
try self.input_.appendSlice(bytes);
|
||||
}
|
||||
|
||||
fn flush_input(self: *Self) !void {
|
||||
if (self.input.items.len > 0) {
|
||||
if (eql(u8, self.input.items, self.last_input.items))
|
||||
if (self.input_.items.len > 0) {
|
||||
if (eql(u8, self.input_.items, self.last_input.items))
|
||||
return;
|
||||
self.last_input.clearRetainingCapacity();
|
||||
try self.last_input.appendSlice(self.input.items);
|
||||
try self.last_input.appendSlice(self.input_.items);
|
||||
self.editor.find_operation = .goto_next_match;
|
||||
const primary = self.editor.get_primary();
|
||||
primary.selection = null;
|
||||
primary.cursor = self.start_cursor;
|
||||
try self.editor.find_in_buffer(self.input.items);
|
||||
try self.editor.find_in_buffer(self.input_.items);
|
||||
} else {
|
||||
self.editor.get_primary().selection = null;
|
||||
self.editor.init_matches_update();
|
||||
|
@ -114,9 +114,9 @@ fn find_history_prev(self: *Self) void {
|
|||
if (pos > 0) self.history_pos = pos - 1;
|
||||
} else {
|
||||
self.history_pos = history.items.len - 1;
|
||||
if (self.input.items.len > 0)
|
||||
self.editor.push_find_history(self.editor.allocator.dupe(u8, self.input.items) catch return);
|
||||
if (eql(u8, history.items[self.history_pos.?], self.input.items) and self.history_pos.? > 0)
|
||||
if (self.input_.items.len > 0)
|
||||
self.editor.push_find_history(self.editor.allocator.dupe(u8, self.input_.items) catch return);
|
||||
if (eql(u8, history.items[self.history_pos.?], self.input_.items) and self.history_pos.? > 0)
|
||||
self.history_pos = self.history_pos.? - 1;
|
||||
}
|
||||
self.load_history(self.history_pos.?);
|
||||
|
@ -134,39 +134,40 @@ fn find_history_next(self: *Self) void {
|
|||
|
||||
fn load_history(self: *Self, pos: usize) void {
|
||||
if (self.editor.find_history) |*history| {
|
||||
self.input.clearRetainingCapacity();
|
||||
self.input.appendSlice(history.items[pos]) catch {};
|
||||
self.input_.clearRetainingCapacity();
|
||||
self.input_.appendSlice(history.items[pos]) catch {};
|
||||
}
|
||||
}
|
||||
|
||||
fn update_mini_mode_text(self: *Self) void {
|
||||
if (tui.mini_mode()) |mini_mode| {
|
||||
mini_mode.text = self.input.items;
|
||||
mini_mode.cursor = tui.egc_chunk_width(self.input.items, 0, 8);
|
||||
mini_mode.text = self.input_.items;
|
||||
mini_mode.cursor = tui.egc_chunk_width(self.input_.items, 0, 8);
|
||||
}
|
||||
}
|
||||
|
||||
const cmds = struct {
|
||||
pub const Target = Self;
|
||||
const Ctx = command.Context;
|
||||
const Meta = command.Metadata;
|
||||
const Result = command.Result;
|
||||
|
||||
pub fn mini_mode_reset(self: *Self, _: Ctx) Result {
|
||||
self.input.clearRetainingCapacity();
|
||||
self.input_.clearRetainingCapacity();
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_reset_meta = .{ .description = "Clear input" };
|
||||
pub const mini_mode_reset_meta: Meta = .{ .description = "Clear input" };
|
||||
|
||||
pub fn mini_mode_cancel(self: *Self, _: Ctx) Result {
|
||||
self.cancel();
|
||||
}
|
||||
pub const mini_mode_cancel_meta = .{ .description = "Cancel input" };
|
||||
pub const mini_mode_cancel_meta: Meta = .{ .description = "Cancel input" };
|
||||
|
||||
pub fn mini_mode_select(self: *Self, _: Ctx) Result {
|
||||
self.editor.push_find_history(self.input.items);
|
||||
self.editor.push_find_history(self.input_.items);
|
||||
self.cmd("exit_mini_mode", .{}) catch {};
|
||||
}
|
||||
pub const mini_mode_select_meta = .{ .description = "Select" };
|
||||
pub const mini_mode_select_meta: Meta = .{ .description = "Select" };
|
||||
|
||||
pub fn mini_mode_insert_code_point(self: *Self, ctx: Ctx) Result {
|
||||
var egc: u32 = 0;
|
||||
|
@ -175,7 +176,7 @@ const cmds = struct {
|
|||
self.insert_code_point(egc) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_insert_code_point_meta = .{ .arguments = &.{.integer} };
|
||||
pub const mini_mode_insert_code_point_meta: Meta = .{ .arguments = &.{.integer} };
|
||||
|
||||
pub fn mini_mode_insert_bytes(self: *Self, ctx: Ctx) Result {
|
||||
var bytes: []const u8 = undefined;
|
||||
|
@ -184,28 +185,28 @@ const cmds = struct {
|
|||
self.insert_bytes(bytes) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_insert_bytes_meta = .{ .arguments = &.{.string} };
|
||||
pub const mini_mode_insert_bytes_meta: Meta = .{ .arguments = &.{.string} };
|
||||
|
||||
pub fn mini_mode_delete_backwards(self: *Self, _: Ctx) Result {
|
||||
self.input.resize(self.input.items.len - tui.egc_last(self.input.items).len) catch {};
|
||||
self.input_.resize(self.input_.items.len - tui.egc_last(self.input_.items).len) catch {};
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_delete_backwards_meta = .{ .description = "Delete backwards" };
|
||||
pub const mini_mode_delete_backwards_meta: Meta = .{ .description = "Delete backwards" };
|
||||
|
||||
pub fn mini_mode_history_prev(self: *Self, _: Ctx) Result {
|
||||
self.find_history_prev();
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_history_prev_meta = .{ .description = "History previous" };
|
||||
pub const mini_mode_history_prev_meta: Meta = .{ .description = "History previous" };
|
||||
|
||||
pub fn mini_mode_history_next(self: *Self, _: Ctx) Result {
|
||||
self.find_history_next();
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_history_next_meta = .{ .description = "History next" };
|
||||
pub const mini_mode_history_next_meta: Meta = .{ .description = "History next" };
|
||||
|
||||
pub fn mini_mode_paste(self: *Self, ctx: Ctx) Result {
|
||||
return mini_mode_insert_bytes(self, ctx);
|
||||
}
|
||||
pub const mini_mode_paste_meta = .{ .arguments = &.{.string} };
|
||||
pub const mini_mode_paste_meta: Meta = .{ .arguments = &.{.string} };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue