feat: add editor.save_file_as command
This commit is contained in:
parent
c54896a86c
commit
34540bbff0
1 changed files with 15 additions and 0 deletions
|
@ -459,6 +459,14 @@ pub const Editor = struct {
|
||||||
self.last.dirty = false;
|
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 {
|
pub fn push_cursor(self: *Self) !void {
|
||||||
const primary = self.cursels.getLastOrNull() orelse CurSel{} orelse CurSel{};
|
const primary = self.cursels.getLastOrNull() orelse CurSel{} orelse CurSel{};
|
||||||
(try self.cursels.addOne()).* = primary;
|
(try self.cursels.addOne()).* = primary;
|
||||||
|
@ -3014,6 +3022,13 @@ pub const Editor = struct {
|
||||||
try self.save();
|
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 {
|
pub fn close_file(self: *Self, _: Context) Result {
|
||||||
self.cancel_all_selections();
|
self.cancel_all_selections();
|
||||||
try self.close();
|
try self.close();
|
||||||
|
|
Loading…
Add table
Reference in a new issue