diff --git a/src/keybind/builtin/flow.json b/src/keybind/builtin/flow.json index 3e7aaf8..340793f 100644 --- a/src/keybind/builtin/flow.json +++ b/src/keybind/builtin/flow.json @@ -1,6 +1,7 @@ { "project": { "press": [ + ["ctrl+shift+n", "create_new_file"], ["alt+!", "select_task"], ["ctrl+tab", "next_tab"], ["ctrl+shift+tab", "previous_tab"], diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index cf47dfe..9aee593 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -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))