feat(buffer): restore previous file type when switching buffers
This commit is contained in:
parent
f627a59f4d
commit
02ba05c500
2 changed files with 27 additions and 18 deletions
|
@ -50,6 +50,10 @@ curr_history: ?*UndoNode = null,
|
|||
mtime: i64,
|
||||
utime: i64,
|
||||
|
||||
file_type_name: ?[]const u8 = null,
|
||||
file_type_icon: ?[]const u8 = null,
|
||||
file_type_color: ?u24 = null,
|
||||
|
||||
pub const EolMode = enum { lf, crlf };
|
||||
pub const EolModeTag = @typeInfo(EolMode).Enum.tag_type;
|
||||
|
||||
|
|
|
@ -541,13 +541,14 @@ pub const Editor = struct {
|
|||
return self.open_buffer(file_path, try self.buffer_manager.open_scratch(file_path, content), file_type);
|
||||
}
|
||||
|
||||
fn open_buffer(self: *Self, file_path: []const u8, new_buf: *Buffer, file_type: ?[]const u8) !void {
|
||||
fn open_buffer(self: *Self, file_path: []const u8, new_buf: *Buffer, file_type_: ?[]const u8) !void {
|
||||
errdefer self.buffer_manager.retire(new_buf, null);
|
||||
self.cancel_all_selections();
|
||||
self.get_primary().reset();
|
||||
self.file_path = try self.allocator.dupe(u8, file_path);
|
||||
if (self.buffer) |_| try self.close();
|
||||
self.buffer = new_buf;
|
||||
const file_type = file_type_ orelse new_buf.file_type_name;
|
||||
|
||||
if (new_buf.root.lines() > root_mod.max_syntax_lines) {
|
||||
self.logger.print("large file threshold {d} lines < file size {d} lines", .{
|
||||
|
@ -583,6 +584,11 @@ pub const Editor = struct {
|
|||
const ftn = if (self.syntax) |syn| syn.file_type.name else "text";
|
||||
const fti = if (self.syntax) |syn| syn.file_type.icon else "🖹";
|
||||
const ftc = if (self.syntax) |syn| syn.file_type.color else 0x000000;
|
||||
if (self.buffer) |buffer| {
|
||||
buffer.file_type_name = ftn;
|
||||
buffer.file_type_icon = fti;
|
||||
buffer.file_type_color = ftc;
|
||||
}
|
||||
|
||||
if (self.buffer) |buffer| if (buffer.get_meta()) |meta|
|
||||
try self.extract_state(meta, .none);
|
||||
|
@ -2870,7 +2876,6 @@ pub const Editor = struct {
|
|||
}
|
||||
pub const move_word_left_vim_meta = .{ .description = "Move cursor left by word (vim)" };
|
||||
|
||||
|
||||
pub fn move_word_right(self: *Self, _: Context) Result {
|
||||
const root = try self.buf_root();
|
||||
self.with_cursors_const(root, move_cursor_word_right) catch {};
|
||||
|
|
Loading…
Add table
Reference in a new issue