feat: add close_file_without_saving command and keybinding (C-S-w)
This commit is contained in:
parent
438d64268e
commit
dfdbb47367
6 changed files with 19 additions and 1 deletions
|
@ -377,8 +377,16 @@ pub const Editor = struct {
|
|||
}
|
||||
|
||||
fn close(self: *Self) !void {
|
||||
return self.close_internal(false);
|
||||
}
|
||||
|
||||
fn close_dirty(self: *Self) !void {
|
||||
return self.close_internal(true);
|
||||
}
|
||||
|
||||
fn close_internal(self: *Self, allow_dirty_close: bool) !void {
|
||||
const b = if (self.buffer) |p| p else return error.Stop;
|
||||
if (b.is_dirty()) return tp.exit("unsaved changes");
|
||||
if (!allow_dirty_close and b.is_dirty()) return tp.exit("unsaved changes");
|
||||
if (self.buffer) |b_mut| b_mut.deinit();
|
||||
self.buffer = null;
|
||||
self.plane.erase();
|
||||
|
@ -2855,6 +2863,11 @@ pub const Editor = struct {
|
|||
self.close() catch |e| return tp.exit_error(e);
|
||||
}
|
||||
|
||||
pub fn close_file_without_saving(self: *Self, _: command.Context) tp.result {
|
||||
self.cancel_all_selections();
|
||||
self.close_dirty() catch |e| return tp.exit_error(e);
|
||||
}
|
||||
|
||||
pub fn find(self: *Self, ctx: command.Context) tp.result {
|
||||
var query: []const u8 = undefined;
|
||||
if (ctx.args.match(.{tp.extract(&query)}) catch false) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue