parent
99664742c3
commit
ada40b989c
2 changed files with 22 additions and 1 deletions
|
@ -22,7 +22,7 @@ restore_last_cursor_position: bool = true,
|
||||||
follow_cursor_on_buffer_switch: bool = false, //scroll cursor into view on buffer switch
|
follow_cursor_on_buffer_switch: bool = false, //scroll cursor into view on buffer switch
|
||||||
default_cursor: []const u8 = "default",
|
default_cursor: []const u8 = "default",
|
||||||
enable_auto_save: bool = false,
|
enable_auto_save: bool = false,
|
||||||
auto_save_file_types: []const []const u8 = &.{},
|
limit_auto_save_file_types: ?[]const []const u8 = null, // null means *all*
|
||||||
|
|
||||||
indent_size: usize = 4,
|
indent_size: usize = 4,
|
||||||
tab_width: usize = 8,
|
tab_width: usize = 8,
|
||||||
|
|
|
@ -353,6 +353,8 @@ pub const Editor = struct {
|
||||||
enable_auto_save: bool,
|
enable_auto_save: bool,
|
||||||
enable_format_on_save: bool,
|
enable_format_on_save: bool,
|
||||||
|
|
||||||
|
restored_state: bool = false,
|
||||||
|
|
||||||
need_save_after_filter: ?struct {
|
need_save_after_filter: ?struct {
|
||||||
then: ?struct {
|
then: ?struct {
|
||||||
cmd: []const u8,
|
cmd: []const u8,
|
||||||
|
@ -396,6 +398,7 @@ pub const Editor = struct {
|
||||||
pub fn extract_state(self: *Self, buf: []const u8, comptime op: enum { none, open_file }) !void {
|
pub fn extract_state(self: *Self, buf: []const u8, comptime op: enum { none, open_file }) !void {
|
||||||
tp.trace(tp.channel.debug, .{ "extract_state", self.file_path });
|
tp.trace(tp.channel.debug, .{ "extract_state", self.file_path });
|
||||||
tp.trace(tp.channel.debug, tp.message{ .buf = buf });
|
tp.trace(tp.channel.debug, tp.message{ .buf = buf });
|
||||||
|
self.restored_state = true;
|
||||||
var file_path: []const u8 = undefined;
|
var file_path: []const u8 = undefined;
|
||||||
var view_cbor: []const u8 = undefined;
|
var view_cbor: []const u8 = undefined;
|
||||||
var cursels_cbor: []const u8 = undefined;
|
var cursels_cbor: []const u8 = undefined;
|
||||||
|
@ -599,6 +602,8 @@ pub const Editor = struct {
|
||||||
file_type_config.guess_file_type(self.file_path, content.items);
|
file_type_config.guess_file_type(self.file_path, content.items);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.maybe_enable_auto_save();
|
||||||
|
|
||||||
const syn = blk: {
|
const syn = blk: {
|
||||||
const frame_ = tracy.initZone(@src(), .{ .name = "create" });
|
const frame_ = tracy.initZone(@src(), .{ .name = "create" });
|
||||||
defer frame_.deinit();
|
defer frame_.deinit();
|
||||||
|
@ -642,6 +647,22 @@ pub const Editor = struct {
|
||||||
try self.send_editor_open(file_path, new_buf.file_exists, ftn, fti, ftc);
|
try self.send_editor_open(file_path, new_buf.file_exists, ftn, fti, ftc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn maybe_enable_auto_save(self: *Self) void {
|
||||||
|
if (self.restored_state) return;
|
||||||
|
self.enable_auto_save = false;
|
||||||
|
if (!tui.config().enable_auto_save) return;
|
||||||
|
const self_file_type = self.file_type orelse return;
|
||||||
|
|
||||||
|
enable: {
|
||||||
|
const file_types = tui.config().limit_auto_save_file_types orelse break :enable;
|
||||||
|
for (file_types) |file_type|
|
||||||
|
if (std.mem.eql(u8, file_type, self_file_type.name))
|
||||||
|
break :enable;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.enable_auto_save = true;
|
||||||
|
}
|
||||||
|
|
||||||
fn close(self: *Self) !void {
|
fn close(self: *Self) !void {
|
||||||
var meta = std.ArrayListUnmanaged(u8).empty;
|
var meta = std.ArrayListUnmanaged(u8).empty;
|
||||||
defer meta.deinit(self.allocator);
|
defer meta.deinit(self.allocator);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue