refactor: lots more writergate fixes - first successful build
This commit is contained in:
parent
5094aa8c85
commit
bf0d4402ea
48 changed files with 404 additions and 413 deletions
|
|
@ -25,7 +25,7 @@ pub fn Create(options: type) type {
|
|||
errdefer allocator.destroy(self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.input = std.ArrayList(u8).init(allocator),
|
||||
.input = .empty,
|
||||
};
|
||||
try self.commands.init(self);
|
||||
if (@hasDecl(options, "restore_state"))
|
||||
|
|
@ -39,7 +39,7 @@ pub fn Create(options: type) type {
|
|||
|
||||
pub fn deinit(self: *Self) void {
|
||||
self.commands.deinit();
|
||||
self.input.deinit();
|
||||
self.input.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ pub fn Create(options: type) type {
|
|||
var text: []const u8 = undefined;
|
||||
|
||||
if (try m.match(.{ "system_clipboard", tp.extract(&text) })) {
|
||||
self.input.appendSlice(text) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
self.input.appendSlice(self.allocator, text) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
}
|
||||
self.update_mini_mode_text();
|
||||
return false;
|
||||
|
|
@ -96,7 +96,7 @@ pub fn Create(options: type) type {
|
|||
return error.InvalidMiniBufferInsertCodePointArgument;
|
||||
var buf: [32]u8 = undefined;
|
||||
const bytes = try input.ucs32_to_utf8(&[_]u32{egc}, &buf);
|
||||
try self.input.appendSlice(buf[0..bytes]);
|
||||
try self.input.appendSlice(self.allocator, buf[0..bytes]);
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_insert_code_point_meta: Meta = .{ .arguments = &.{.integer} };
|
||||
|
|
@ -105,7 +105,7 @@ pub fn Create(options: type) type {
|
|||
var bytes: []const u8 = undefined;
|
||||
if (!try ctx.args.match(.{tp.extract(&bytes)}))
|
||||
return error.InvalidMiniBufferInsertBytesArgument;
|
||||
try self.input.appendSlice(bytes);
|
||||
try self.input.appendSlice(self.allocator, bytes);
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_insert_bytes_meta: Meta = .{ .arguments = &.{.string} };
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ pub fn Create(options: type) type {
|
|||
errdefer allocator.destroy(self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.file_path = std.ArrayList(u8).init(allocator),
|
||||
.query = std.ArrayList(u8).init(allocator),
|
||||
.match = std.ArrayList(u8).init(allocator),
|
||||
.entries = std.ArrayList(Entry).init(allocator),
|
||||
.file_path = .empty,
|
||||
.query = .empty,
|
||||
.match = .empty,
|
||||
.entries = .empty,
|
||||
};
|
||||
try self.commands.init(self);
|
||||
try tui.message_filters().add(MessageFilter.bind(self, receive_path_entry));
|
||||
|
|
@ -68,10 +68,10 @@ pub fn Create(options: type) type {
|
|||
self.commands.deinit();
|
||||
tui.message_filters().remove_ptr(self);
|
||||
self.clear_entries();
|
||||
self.entries.deinit();
|
||||
self.match.deinit();
|
||||
self.query.deinit();
|
||||
self.file_path.deinit();
|
||||
self.entries.deinit(self.allocator);
|
||||
self.match.deinit(self.allocator);
|
||||
self.query.deinit(self.allocator);
|
||||
self.file_path.deinit(self.allocator);
|
||||
self.rendered_mini_buffer.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ pub fn Create(options: type) type {
|
|||
var text: []const u8 = undefined;
|
||||
|
||||
if (try m.match(.{ "system_clipboard", tp.extract(&text) })) {
|
||||
self.file_path.appendSlice(text) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
self.file_path.appendSlice(self.allocator, text) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
}
|
||||
self.update_mini_mode_text();
|
||||
return false;
|
||||
|
|
@ -102,14 +102,14 @@ pub fn Create(options: type) type {
|
|||
self.match.clearRetainingCapacity();
|
||||
self.clear_entries();
|
||||
if (root.is_directory(self.file_path.items)) {
|
||||
try self.query.appendSlice(self.file_path.items);
|
||||
try self.query.appendSlice(self.allocator, self.file_path.items);
|
||||
} else if (self.file_path.items.len > 0) blk: {
|
||||
const basename_begin = std.mem.lastIndexOfScalar(u8, self.file_path.items, std.fs.path.sep) orelse {
|
||||
try self.match.appendSlice(self.file_path.items);
|
||||
try self.match.appendSlice(self.allocator, self.file_path.items);
|
||||
break :blk;
|
||||
};
|
||||
try self.query.appendSlice(self.file_path.items[0 .. basename_begin + 1]);
|
||||
try self.match.appendSlice(self.file_path.items[basename_begin + 1 ..]);
|
||||
try self.query.appendSlice(self.allocator, self.file_path.items[0 .. basename_begin + 1]);
|
||||
try self.match.appendSlice(self.allocator, self.file_path.items[basename_begin + 1 ..]);
|
||||
}
|
||||
// log.logger("file_browser").print("query: '{s}' match: '{s}'", .{ self.query.items, self.match.items });
|
||||
try project_manager.request_path_files(max_complete_paths, self.query.items);
|
||||
|
|
@ -125,7 +125,7 @@ pub fn Create(options: type) type {
|
|||
if (self.match.items.len > 0) {
|
||||
try self.construct_path(self.query.items, self.match.items, .file, 0);
|
||||
} else {
|
||||
try self.file_path.appendSlice(self.query.items);
|
||||
try self.file_path.appendSlice(self.allocator, self.query.items);
|
||||
}
|
||||
self.update_mini_mode_text();
|
||||
return;
|
||||
|
|
@ -177,7 +177,7 @@ pub fn Create(options: type) type {
|
|||
}
|
||||
|
||||
fn add_entry(self: *Self, file_name: []const u8, entry_type: EntryType, file_type: []const u8, icon: []const u8, color: u24) !void {
|
||||
(try self.entries.addOne()).* = .{
|
||||
(try self.entries.addOne(self.allocator)).* = .{
|
||||
.name = try self.allocator.dupe(u8, file_name),
|
||||
.type = entry_type,
|
||||
.file_type = try self.allocator.dupe(u8, file_type),
|
||||
|
|
@ -212,12 +212,12 @@ pub fn Create(options: type) type {
|
|||
fn construct_path(self: *Self, path_: []const u8, entry_name: []const u8, entry_type: EntryType, entry_no: usize) error{OutOfMemory}!void {
|
||||
self.matched_entry = entry_no;
|
||||
const path = project_manager.normalize_file_path(path_);
|
||||
try self.file_path.appendSlice(path);
|
||||
try self.file_path.appendSlice(self.allocator, path);
|
||||
if (path.len > 0 and path[path.len - 1] != std.fs.path.sep)
|
||||
try self.file_path.append(std.fs.path.sep);
|
||||
try self.file_path.appendSlice(entry_name);
|
||||
try self.file_path.append(self.allocator, std.fs.path.sep);
|
||||
try self.file_path.appendSlice(self.allocator, entry_name);
|
||||
if (entry_type == .dir)
|
||||
try self.file_path.append(std.fs.path.sep);
|
||||
try self.file_path.append(self.allocator, std.fs.path.sep);
|
||||
}
|
||||
|
||||
fn match_path(self: *Self) !void {
|
||||
|
|
@ -351,7 +351,7 @@ pub fn Create(options: type) type {
|
|||
self.complete_trigger_count = 0;
|
||||
var buf: [32]u8 = undefined;
|
||||
const bytes = try input.ucs32_to_utf8(&[_]u32{egc}, &buf);
|
||||
try self.file_path.appendSlice(buf[0..bytes]);
|
||||
try self.file_path.appendSlice(self.allocator, buf[0..bytes]);
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_insert_code_point_meta: Meta = .{ .arguments = &.{.integer} };
|
||||
|
|
@ -361,7 +361,7 @@ pub fn Create(options: type) type {
|
|||
if (!try ctx.args.match(.{tp.extract(&bytes)}))
|
||||
return error.InvalidFileBrowserInsertBytesArgument;
|
||||
self.complete_trigger_count = 0;
|
||||
try self.file_path.appendSlice(bytes);
|
||||
try self.file_path.appendSlice(self.allocator, bytes);
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_insert_bytes_meta: Meta = .{ .arguments = &.{.string} };
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
|||
errdefer allocator.destroy(self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.input_ = ArrayList(u8).init(allocator),
|
||||
.last_input = ArrayList(u8).init(allocator),
|
||||
.input_ = .empty,
|
||||
.last_input = .empty,
|
||||
.start_view = editor.view,
|
||||
.start_cursor = editor.get_primary().cursor,
|
||||
.editor = editor,
|
||||
|
|
@ -42,7 +42,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(self.allocator, text);
|
||||
}
|
||||
var mode = try keybind.mode("mini/find", allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
|
|
@ -53,8 +53,8 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
|||
|
||||
pub fn deinit(self: *Self) void {
|
||||
self.commands.deinit();
|
||||
self.input_.deinit();
|
||||
self.last_input.deinit();
|
||||
self.input_.deinit(self.allocator);
|
||||
self.last_input.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
|
|
@ -74,11 +74,11 @@ 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(self.allocator, buf[0..bytes]);
|
||||
}
|
||||
|
||||
fn insert_bytes(self: *Self, bytes: []const u8) !void {
|
||||
try self.input_.appendSlice(bytes);
|
||||
try self.input_.appendSlice(self.allocator, bytes);
|
||||
}
|
||||
|
||||
fn flush_input(self: *Self) !void {
|
||||
|
|
@ -86,7 +86,7 @@ fn flush_input(self: *Self) !void {
|
|||
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.allocator, self.input_.items);
|
||||
self.editor.find_operation = .goto_next_match;
|
||||
const primary = self.editor.get_primary();
|
||||
primary.selection = null;
|
||||
|
|
@ -136,7 +136,7 @@ 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_.appendSlice(self.allocator, history.items[pos]) catch {};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ const cmds = struct {
|
|||
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.allocator, self.input_.items.len - tui.egc_last(self.input_.items).len) catch {};
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
pub const mini_mode_delete_backwards_meta: Meta = .{ .description = "Delete backwards" };
|
||||
|
|
|
|||
|
|
@ -14,18 +14,18 @@ pub fn load_entries(self: *Type) error{ Exit, OutOfMemory }!void {
|
|||
var project_name_buf: [512]u8 = undefined;
|
||||
const project_path = tp.env.get().str("project");
|
||||
const project_name = project_manager.abbreviate_home(&project_name_buf, project_path);
|
||||
try self.file_path.appendSlice(project_name);
|
||||
try self.file_path.append(std.fs.path.sep);
|
||||
try self.file_path.appendSlice(self.allocator, project_name);
|
||||
try self.file_path.append(self.allocator, std.fs.path.sep);
|
||||
const editor = tui.get_active_editor() orelse return;
|
||||
if (editor.file_path) |old_path|
|
||||
if (std.mem.lastIndexOf(u8, old_path, "/")) |pos|
|
||||
try self.file_path.appendSlice(old_path[0 .. pos + 1]);
|
||||
try self.file_path.appendSlice(self.allocator, old_path[0 .. pos + 1]);
|
||||
if (editor.get_primary().selection) |sel| ret: {
|
||||
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
||||
defer self.allocator.free(text);
|
||||
if (!(text.len > 2 and std.mem.eql(u8, text[0..2], "..")))
|
||||
self.file_path.clearRetainingCapacity();
|
||||
try self.file_path.appendSlice(text);
|
||||
try self.file_path.appendSlice(self.allocator, text);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -34,9 +34,9 @@ pub fn name(_: *Type) []const u8 {
|
|||
}
|
||||
|
||||
pub fn select(self: *Type) void {
|
||||
var buf = std.ArrayList(u8).init(self.allocator);
|
||||
defer buf.deinit();
|
||||
const file_path = project_manager.expand_home(&buf, self.file_path.items);
|
||||
var buf: std.ArrayList(u8) = .empty;
|
||||
defer buf.deinit(self.allocator);
|
||||
const file_path = project_manager.expand_home(self.allocator, &buf, self.file_path.items);
|
||||
if (root.is_directory(file_path))
|
||||
tp.self_pid().send(.{ "cmd", "change_project", .{file_path} }) catch {}
|
||||
else if (file_path.len > 0)
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ pub const create = Type.create;
|
|||
|
||||
pub fn load_entries(self: *Type) !void {
|
||||
const editor = tui.get_active_editor() orelse return;
|
||||
try self.file_path.appendSlice(editor.file_path orelse "");
|
||||
try self.file_path.appendSlice(self.allocator, editor.file_path orelse "");
|
||||
if (editor.get_primary().selection) |sel| ret: {
|
||||
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
||||
defer self.allocator.free(text);
|
||||
if (!(text.len > 2 and std.mem.eql(u8, text[0..2], "..")))
|
||||
self.file_path.clearRetainingCapacity();
|
||||
try self.file_path.appendSlice(text);
|
||||
try self.file_path.appendSlice(self.allocator, text);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue