feat: add create_new_file command

closes #93
This commit is contained in:
CJ van den Berg 2025-01-27 19:08:42 +01:00
parent 9e1b9920ba
commit 404ba8bb0e
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 20 additions and 0 deletions

View file

@ -1,6 +1,7 @@
{
"project": {
"press": [
["ctrl+shift+n", "create_new_file"],
["alt+!", "select_task"],
["ctrl+tab", "next_tab"],
["ctrl+shift+tab", "previous_tab"],

View file

@ -393,6 +393,25 @@ const cmds = struct {
}
pub const create_scratch_buffer_meta = .{ .arguments = &.{ .string, .string } };
pub fn create_new_file(self: *Self, _: Ctx) Result {
var n: usize = 1;
var found_unique = false;
var name = std.ArrayList(u8).init(self.allocator);
defer name.deinit();
while (!found_unique) {
name.clearRetainingCapacity();
try name.writer().print("Untitled-{d}", .{n});
if (self.buffer_manager.get_buffer_for_file(name.items)) |_| {
n += 1;
} else {
found_unique = true;
}
}
try command.executeName("create_scratch_buffer", command.fmt(.{name.items}));
try command.executeName("change_file_type", .{});
}
pub const create_new_file_meta = .{ .description = "Create: New File…" };
pub fn delete_buffer(self: *Self, ctx: Ctx) Result {
var file_path: []const u8 = undefined;
if (!(ctx.args.match(.{tp.extract(&file_path)}) catch false))