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) {
|
||||
|
|
|
@ -119,6 +119,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
|||
'D' => self.cmd("dupe_down", .{}),
|
||||
'Z' => self.cmd("redo", .{}),
|
||||
'Q' => self.cmd("quit_without_saving", .{}),
|
||||
'W' => self.cmd("close_file_without_saving", .{}),
|
||||
'R' => self.cmd("restart", .{}),
|
||||
'F' => self.cmd("enter_find_in_files_mode", .{}),
|
||||
'L' => self.cmd_async("add_cursor_all_matches"),
|
||||
|
|
|
@ -122,6 +122,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
|||
'D' => self.cmd("dupe_down", .{}),
|
||||
'Z' => self.cmd("redo", .{}),
|
||||
'Q' => self.cmd("quit_without_saving", .{}),
|
||||
'W' => self.cmd("close_file_without_saving", .{}),
|
||||
'R' => self.cmd("restart", .{}),
|
||||
'F' => self.cmd("enter_find_in_files_mode", .{}),
|
||||
'L' => self.cmd_async("add_cursor_all_matches"),
|
||||
|
|
|
@ -125,6 +125,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
|||
'D' => self.cmd("dupe_down", .{}),
|
||||
'Z' => self.cmd("redo", .{}),
|
||||
'Q' => self.cmd("quit_without_saving", .{}),
|
||||
'W' => self.cmd("close_file_without_saving", .{}),
|
||||
'R' => self.cmd("restart", .{}),
|
||||
'F' => self.cmd("enter_find_in_files_mode", .{}),
|
||||
'L' => self.cmd_async("add_cursor_all_matches"),
|
||||
|
|
|
@ -125,6 +125,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
|||
'D' => self.cmd("dupe_down", .{}),
|
||||
'Z' => self.cmd("redo", .{}),
|
||||
'Q' => self.cmd("quit_without_saving", .{}),
|
||||
'W' => self.cmd("close_file_without_saving", .{}),
|
||||
'R' => self.cmd("restart", .{}),
|
||||
'F' => self.cmd("enter_find_in_files_mode", .{}),
|
||||
'L' => self.cmd_async("add_cursor_all_matches"),
|
||||
|
|
|
@ -232,6 +232,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
|||
},
|
||||
nc.mod.CTRL | nc.mod.SHIFT => switch (keynormal) {
|
||||
'Q' => self.cmd("quit_without_saving", .{}),
|
||||
'W' => self.cmd("close_file_without_saving", .{}),
|
||||
'R' => self.cmd("restart", .{}),
|
||||
'L' => self.cmd_async("toggle_logview"),
|
||||
'I' => self.cmd_async("toggle_inputview"),
|
||||
|
|
Loading…
Add table
Reference in a new issue