feat: add editor.save_file_as command

This commit is contained in:
CJ van den Berg 2024-08-30 20:17:48 +02:00
parent c54896a86c
commit 34540bbff0
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -459,6 +459,14 @@ pub const Editor = struct {
self.last.dirty = false;
}
fn save_as(self: *Self, file_path: []const u8) !void {
if (self.buffer) |b_mut| try b_mut.store_to_file_and_clean(file_path);
if (self.file_path) |old_file_path| self.a.free(old_file_path);
self.file_path = try self.a.dupe(u8, file_path);
try self.send_editor_save(self.file_path.?);
self.last.dirty = false;
}
pub fn push_cursor(self: *Self) !void {
const primary = self.cursels.getLastOrNull() orelse CurSel{} orelse CurSel{};
(try self.cursels.addOne()).* = primary;
@ -3014,6 +3022,13 @@ pub const Editor = struct {
try self.save();
}
pub fn save_file_as(self: *Self, ctx: Context) Result {
var file_path: []const u8 = undefined;
if (ctx.args.match(.{tp.extract(&file_path)}) catch false) {
try self.save_as(file_path);
} else return error.InvalidArgument;
}
pub fn close_file(self: *Self, _: Context) Result {
self.cancel_all_selections();
try self.close();