Compare commits
No commits in common. "aee7c30c655a7f2dfef86f3c60c1d453910d7070" and "a98d4e02a7cc580a6a70bf79ade01d481525e0d2" have entirely different histories.
aee7c30c65
...
a98d4e02a7
6 changed files with 22 additions and 121 deletions
|
|
@ -44,7 +44,6 @@ file_utf8_sanitized: bool = false,
|
|||
hidden: bool = false,
|
||||
ephemeral: bool = false,
|
||||
meta: ?[]const u8 = null,
|
||||
lsp_version: usize = 1,
|
||||
|
||||
undo_history: ?*UndoNode = null,
|
||||
redo_history: ?*UndoNode = null,
|
||||
|
|
|
|||
|
|
@ -271,6 +271,7 @@ pub const Editor = struct {
|
|||
file_path: ?[]const u8,
|
||||
buffer: ?*Buffer,
|
||||
buffer_manager: *Buffer.Manager,
|
||||
lsp_version: usize = 1,
|
||||
pause_undo: bool = false,
|
||||
pause_undo_root: ?Buffer.Root = null,
|
||||
|
||||
|
|
@ -330,7 +331,6 @@ pub const Editor = struct {
|
|||
dirty: bool = false,
|
||||
eol_mode: Buffer.EolMode = .lf,
|
||||
utf8_sanitized: bool = false,
|
||||
indent_mode: IndentMode = .spaces,
|
||||
} = .{},
|
||||
|
||||
file_type: ?file_type_config = null,
|
||||
|
|
@ -642,7 +642,7 @@ pub const Editor = struct {
|
|||
project_manager.did_open(
|
||||
file_path,
|
||||
ft,
|
||||
new_buf.lsp_version,
|
||||
self.lsp_version,
|
||||
try content.toOwnedSlice(std.heap.c_allocator),
|
||||
new_buf.is_ephemeral(),
|
||||
) catch |e|
|
||||
|
|
@ -1644,12 +1644,11 @@ pub const Editor = struct {
|
|||
|
||||
if (token_from(self.last.root) != token_from(root)) {
|
||||
try self.send_editor_update(self.last.root, root, eol_mode);
|
||||
if (self.buffer) |buf|
|
||||
buf.lsp_version += 1;
|
||||
self.lsp_version += 1;
|
||||
}
|
||||
|
||||
if (self.last.eol_mode != eol_mode or self.last.utf8_sanitized != utf8_sanitized or self.last.indent_mode != self.indent_mode)
|
||||
try self.send_editor_eol_mode(eol_mode, utf8_sanitized, self.indent_mode);
|
||||
if (self.last.eol_mode != eol_mode or self.last.utf8_sanitized != utf8_sanitized)
|
||||
try self.send_editor_eol_mode(eol_mode, utf8_sanitized);
|
||||
|
||||
if (self.last.dirty != dirty)
|
||||
try self.send_editor_dirty(dirty);
|
||||
|
|
@ -1770,14 +1769,14 @@ pub const Editor = struct {
|
|||
|
||||
fn send_editor_update(self: *const Self, old_root: ?Buffer.Root, new_root: ?Buffer.Root, eol_mode: Buffer.EolMode) !void {
|
||||
_ = try self.handlers.msg(.{ "E", "update", token_from(new_root), token_from(old_root), @intFromEnum(eol_mode) });
|
||||
if (self.buffer) |buffer| if (self.syntax) |_| if (self.file_path) |file_path| if (old_root != null and new_root != null)
|
||||
project_manager.did_change(file_path, buffer.lsp_version, try text_from_root(new_root, eol_mode), try text_from_root(old_root, eol_mode), eol_mode) catch {};
|
||||
if (self.syntax) |_| if (self.file_path) |file_path| if (old_root != null and new_root != null)
|
||||
project_manager.did_change(file_path, self.lsp_version, try text_from_root(new_root, eol_mode), try text_from_root(old_root, eol_mode), eol_mode) catch {};
|
||||
if (self.enable_auto_save)
|
||||
tp.self_pid().send(.{ "cmd", "save_file", .{} }) catch {};
|
||||
}
|
||||
|
||||
fn send_editor_eol_mode(self: *const Self, eol_mode: Buffer.EolMode, utf8_sanitized: bool, indent_mode: IndentMode) !void {
|
||||
_ = try self.handlers.msg(.{ "E", "eol_mode", eol_mode, utf8_sanitized, indent_mode });
|
||||
fn send_editor_eol_mode(self: *const Self, eol_mode: Buffer.EolMode, utf8_sanitized: bool) !void {
|
||||
_ = try self.handlers.msg(.{ "E", "eol_mode", @intFromEnum(eol_mode), utf8_sanitized });
|
||||
}
|
||||
|
||||
fn clamp_abs(self: *Self, abs: bool) void {
|
||||
|
|
@ -5987,11 +5986,11 @@ pub const Editor = struct {
|
|||
const root = try self.buf_root();
|
||||
try root.store(content.writer(std.heap.c_allocator), try self.buf_eol_mode());
|
||||
|
||||
if (self.buffer) |buffer| if (self.file_path) |file_path|
|
||||
if (self.file_path) |file_path|
|
||||
project_manager.did_open(
|
||||
file_path,
|
||||
ft,
|
||||
buffer.lsp_version,
|
||||
self.lsp_version,
|
||||
try content.toOwnedSlice(std.heap.c_allocator),
|
||||
if (self.buffer) |p| p.is_ephemeral() else true,
|
||||
) catch |e|
|
||||
|
|
|
|||
|
|
@ -1303,10 +1303,6 @@ pub fn write_restore_info(self: *Self) void {
|
|||
const buffer_manager = tui.get_buffer_manager() orelse @panic("tabs no buffer manager");
|
||||
buffer_manager.write_state(writer) catch return;
|
||||
|
||||
if (self.widgets.get("tabs")) |tabs_widget|
|
||||
if (tabs_widget.dynamic_cast(@import("status/tabs.zig").TabBar)) |tabs|
|
||||
tabs.write_state(writer) catch return;
|
||||
|
||||
const file_name = root.get_restore_file_name() catch return;
|
||||
var file = std.fs.createFileAbsolute(file_name, .{ .truncate = true }) catch return;
|
||||
defer file.close();
|
||||
|
|
@ -1328,19 +1324,6 @@ fn read_restore_info(self: *Self) !void {
|
|||
if (!try cbor.matchValue(&iter, cbor.extract(&editor_file_path))) return error.Stop;
|
||||
try self.buffer_manager.extract_state(&iter);
|
||||
|
||||
if (self.widgets.get("tabs")) |tabs_widget|
|
||||
if (tabs_widget.dynamic_cast(@import("status/tabs.zig").TabBar)) |tabs|
|
||||
tabs.extract_state(&iter) catch |e| {
|
||||
const logger = log.logger("mainview");
|
||||
defer logger.deinit();
|
||||
logger.print_err("mainview", "failed to restore tabs: {}", .{e});
|
||||
};
|
||||
|
||||
const buffers = try self.buffer_manager.list_unordered(self.allocator);
|
||||
defer self.allocator.free(buffers);
|
||||
for (buffers) |buffer| if (!buffer.is_ephemeral())
|
||||
send_buffer_did_open(self.allocator, buffer) catch {};
|
||||
|
||||
if (editor_file_path) |file_path| {
|
||||
try tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_path } });
|
||||
} else {
|
||||
|
|
@ -1348,21 +1331,6 @@ fn read_restore_info(self: *Self) !void {
|
|||
}
|
||||
}
|
||||
|
||||
fn send_buffer_did_open(allocator: std.mem.Allocator, buffer: *Buffer) !void {
|
||||
const ft = try file_type_config.get(buffer.file_type_name orelse return) orelse return;
|
||||
var content = std.ArrayListUnmanaged(u8).empty;
|
||||
defer content.deinit(allocator);
|
||||
try buffer.root.store(content.writer(allocator), buffer.file_eol_mode);
|
||||
|
||||
try project_manager.did_open(
|
||||
buffer.get_file_path(),
|
||||
ft,
|
||||
buffer.lsp_version,
|
||||
try content.toOwnedSlice(allocator),
|
||||
buffer.is_ephemeral(),
|
||||
);
|
||||
}
|
||||
|
||||
fn get_next_mru_buffer(self: *Self) ?[]const u8 {
|
||||
const buffers = self.buffer_manager.list_most_recently_used(self.allocator) catch return null;
|
||||
defer self.allocator.free(buffers);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ const std = @import("std");
|
|||
const Allocator = std.mem.Allocator;
|
||||
const tp = @import("thespian");
|
||||
const tracy = @import("tracy");
|
||||
const config = @import("config");
|
||||
const Buffer = @import("Buffer");
|
||||
const root = @import("root");
|
||||
const project_manager = @import("project_manager");
|
||||
|
|
@ -36,7 +35,6 @@ detailed: bool = false,
|
|||
file: bool = false,
|
||||
eol_mode: Buffer.EolMode = .lf,
|
||||
utf8_sanitized: bool = false,
|
||||
indent_mode: config.IndentMode = .spaces,
|
||||
|
||||
const project_icon = "";
|
||||
const Self = @This();
|
||||
|
|
@ -157,19 +155,15 @@ fn render_detailed(self: *Self, plane: *Plane, theme: *const Widget.Theme) void
|
|||
_ = plane.print("{s} ({s})", .{ self.name, project_name }) catch {};
|
||||
} else {
|
||||
const eol_mode = switch (self.eol_mode) {
|
||||
.lf => "[↩ = ␊]",
|
||||
.crlf => "[↩ = ␍␊]",
|
||||
};
|
||||
const indent_mode = switch (self.indent_mode) {
|
||||
.spaces, .auto => "[⭾ = ␠]",
|
||||
.tabs => "[⭾ = ␉]",
|
||||
.lf => " [↩ = ␊]",
|
||||
.crlf => " [↩ = ␍␊]",
|
||||
};
|
||||
|
||||
_ = plane.putstr(if (!self.file_exists) "" else if (self.file_dirty) "" else "") catch {};
|
||||
_ = plane.print(" {s}:{d}:{d}", .{ self.name, self.line + 1, self.column + 1 }) catch {};
|
||||
_ = plane.print(" of {d} lines", .{self.lines}) catch {};
|
||||
if (self.file_type.len > 0)
|
||||
_ = plane.print(" ({s}) {s}{s}", .{ self.file_type, eol_mode, indent_mode }) catch {};
|
||||
_ = plane.print(" ({s}){s}", .{ self.file_type, eol_mode }) catch {};
|
||||
|
||||
if (self.utf8_sanitized) {
|
||||
plane.set_style(.{ .fg = theme.editor_error.fg.? });
|
||||
|
|
@ -220,12 +214,13 @@ fn process_event(self: *Self, m: tp.message) error{Exit}!bool {
|
|||
var file_type: []const u8 = undefined;
|
||||
var file_icon: []const u8 = undefined;
|
||||
var file_dirty: bool = undefined;
|
||||
var eol_mode: Buffer.EolModeTag = @intFromEnum(Buffer.EolMode.lf);
|
||||
if (try m.match(.{ tp.any, "pos", tp.extract(&self.lines), tp.extract(&self.line), tp.extract(&self.column) }))
|
||||
return false;
|
||||
if (try m.match(.{ tp.any, "dirty", tp.extract(&file_dirty) })) {
|
||||
self.file_dirty = file_dirty;
|
||||
} else if (try m.match(.{ tp.any, "eol_mode", tp.extract(&self.eol_mode), tp.extract(&self.utf8_sanitized), tp.extract(&self.indent_mode) })) {
|
||||
//
|
||||
} else if (try m.match(.{ tp.any, "eol_mode", tp.extract(&eol_mode), tp.extract(&self.utf8_sanitized) })) {
|
||||
self.eol_mode = @enumFromInt(eol_mode);
|
||||
} else if (try m.match(.{ tp.any, "save", tp.extract(&file_path) })) {
|
||||
@memcpy(self.name_buf[0..file_path.len], file_path);
|
||||
self.name = self.name_buf[0..file_path.len];
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ const std = @import("std");
|
|||
const Allocator = std.mem.Allocator;
|
||||
const tp = @import("thespian");
|
||||
const Buffer = @import("Buffer");
|
||||
const config = @import("config");
|
||||
|
||||
const Plane = @import("renderer").Plane;
|
||||
const command = @import("command");
|
||||
|
|
@ -23,7 +22,6 @@ buf: [256]u8 = undefined,
|
|||
rendered: [:0]const u8 = "",
|
||||
eol_mode: Buffer.EolMode = .lf,
|
||||
utf8_sanitized: bool = false,
|
||||
indent_mode: config.IndentMode = .spaces,
|
||||
padding: ?usize,
|
||||
leader: ?Leader,
|
||||
style: ?DigitStyle,
|
||||
|
|
@ -92,11 +90,7 @@ fn format(self: *Self) void {
|
|||
.lf => "",
|
||||
.crlf => " [␍␊]",
|
||||
};
|
||||
const indent_mode = switch (self.indent_mode) {
|
||||
.spaces, .auto => "",
|
||||
.tabs => " [⭾]",
|
||||
};
|
||||
std.fmt.format(writer, "{s}{s} Ln ", .{ eol_mode, indent_mode }) catch {};
|
||||
std.fmt.format(writer, "{s} Ln ", .{eol_mode}) catch {};
|
||||
self.format_count(writer, self.line + 1, self.padding orelse 0) catch {};
|
||||
std.fmt.format(writer, ", Col ", .{}) catch {};
|
||||
self.format_count(writer, self.column + 1, self.padding orelse 0) catch {};
|
||||
|
|
@ -121,9 +115,11 @@ fn format_count(self: *Self, writer: anytype, value: usize, width: usize) !void
|
|||
}
|
||||
|
||||
pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
var eol_mode: Buffer.EolModeTag = @intFromEnum(Buffer.EolMode.lf);
|
||||
if (try m.match(.{ "E", "pos", tp.extract(&self.lines), tp.extract(&self.line), tp.extract(&self.column) })) {
|
||||
self.format();
|
||||
} else if (try m.match(.{ "E", "eol_mode", tp.extract(&self.eol_mode), tp.extract(&self.utf8_sanitized), tp.extract(&self.indent_mode) })) {
|
||||
} else if (try m.match(.{ "E", "eol_mode", tp.extract(&eol_mode), tp.extract(&self.utf8_sanitized) })) {
|
||||
self.eol_mode = @enumFromInt(eol_mode);
|
||||
self.format();
|
||||
} else if (try m.match(.{ "E", "open", tp.more })) {
|
||||
self.eol_mode = .lf;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
const std = @import("std");
|
||||
const cbor = @import("cbor");
|
||||
const tp = @import("thespian");
|
||||
const root = @import("root");
|
||||
|
||||
|
|
@ -65,7 +64,7 @@ pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Event
|
|||
return Widget.to(self);
|
||||
}
|
||||
|
||||
pub const TabBar = struct {
|
||||
const TabBar = struct {
|
||||
allocator: std.mem.Allocator,
|
||||
plane: Plane,
|
||||
widget_list: *WidgetList,
|
||||
|
|
@ -268,45 +267,6 @@ pub const TabBar = struct {
|
|||
if (buffer_manager.buffer_from_ref(tab.buffer_ref)) |buffer|
|
||||
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = buffer.get_file_path() } }) catch {};
|
||||
}
|
||||
|
||||
pub fn write_state(self: *const Self, writer: Buffer.MetaWriter) error{OutOfMemory}!void {
|
||||
try cbor.writeArrayHeader(writer, self.tabs.len);
|
||||
for (self.tabs) |tab| try cbor.writeValue(writer, ref_to_name(tab.buffer_ref));
|
||||
}
|
||||
|
||||
fn ref_to_name(buffer_ref: usize) ?[]const u8 {
|
||||
const buffer_manager = tui.get_buffer_manager() orelse @panic("tabs no buffer manager");
|
||||
return if (buffer_manager.buffer_from_ref(buffer_ref)) |buffer| buffer.get_file_path() else null;
|
||||
}
|
||||
|
||||
pub fn extract_state(self: *Self, iter: *[]const u8) !void {
|
||||
var iter2 = iter.*;
|
||||
self.allocator.free(self.tabs);
|
||||
self.tabs = &.{};
|
||||
|
||||
var result: std.ArrayListUnmanaged(TabBarTab) = .{};
|
||||
errdefer result.deinit(self.allocator);
|
||||
|
||||
var count = cbor.decodeArrayHeader(&iter2) catch return error.MatchTabArrayFailed;
|
||||
while (count > 0) : (count -= 1) {
|
||||
var buffer_name: ?[]const u8 = undefined;
|
||||
if (!(cbor.matchValue(&iter2, cbor.extract(&buffer_name)) catch false)) return error.MatchTabBufferNameFailed;
|
||||
if (buffer_name) |name| if (name_to_ref(name)) |buffer_ref| {
|
||||
(try result.addOne(self.allocator)).* = .{
|
||||
.buffer_ref = buffer_ref,
|
||||
.widget = try Tab.create(self, buffer_ref, &self.tab_style, self.event_handler),
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
self.tabs = try result.toOwnedSlice(self.allocator);
|
||||
iter.* = iter2;
|
||||
}
|
||||
|
||||
fn name_to_ref(buffer_name: []const u8) ?usize {
|
||||
const buffer_manager = tui.get_buffer_manager() orelse @panic("tabs no buffer manager");
|
||||
return if (buffer_manager.get_buffer_for_file(buffer_name)) |buffer| buffer_manager.buffer_to_ref(buffer) else null;
|
||||
}
|
||||
};
|
||||
|
||||
const Tab = struct {
|
||||
|
|
@ -497,22 +457,6 @@ const Tab = struct {
|
|||
const basename = if (basename_begin) |begin| file_path[begin + 1 ..] else file_path;
|
||||
return basename;
|
||||
}
|
||||
|
||||
fn write_state(self: *const @This(), writer: Buffer.MetaWriter) error{OutOfMemory}!void {
|
||||
try cbor.writeArrayHeader(writer, 9);
|
||||
try cbor.writeValue(writer, self.get_file_path());
|
||||
try cbor.writeValue(writer, self.file_exists);
|
||||
try cbor.writeValue(writer, self.file_eol_mode);
|
||||
try cbor.writeValue(writer, self.hidden);
|
||||
try cbor.writeValue(writer, self.ephemeral);
|
||||
try cbor.writeValue(writer, self.meta);
|
||||
try cbor.writeValue(writer, self.file_type_name);
|
||||
}
|
||||
|
||||
fn extract_state(self: *@This(), iter: *[]const u8) !void {
|
||||
_ = self;
|
||||
_ = iter;
|
||||
}
|
||||
};
|
||||
|
||||
const spacer = struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue