Compare commits
5 commits
672d92424d
...
4cb0f7df02
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cb0f7df02 | |||
| 6bb6141ef3 | |||
| b9b49c4164 | |||
| 0974935ced | |||
| 693ed91b12 |
3 changed files with 46 additions and 14 deletions
|
|
@ -325,6 +325,7 @@ pub const Editor = struct {
|
||||||
chunks: usize = 0,
|
chunks: usize = 0,
|
||||||
eol_mode: Buffer.EolMode = .lf,
|
eol_mode: Buffer.EolMode = .lf,
|
||||||
utf8_sanitized: bool = false,
|
utf8_sanitized: bool = false,
|
||||||
|
no_changes: bool = false,
|
||||||
} = null,
|
} = null,
|
||||||
matches: Match.List = .empty,
|
matches: Match.List = .empty,
|
||||||
match_token: usize = 0,
|
match_token: usize = 0,
|
||||||
|
|
@ -721,7 +722,7 @@ pub const Editor = struct {
|
||||||
buffer.file_type_icon = fti;
|
buffer.file_type_icon = fti;
|
||||||
buffer.file_type_color = ftc;
|
buffer.file_type_color = ftc;
|
||||||
}
|
}
|
||||||
const auto_save = if (self.buffer) |b| b.is_auto_save() else false;
|
const auto_save = if (self.buffer) |b| b.is_auto_save() and !b.is_ephemeral() else false;
|
||||||
|
|
||||||
if (buffer_meta) |meta| {
|
if (buffer_meta) |meta| {
|
||||||
const frame_ = tracy.initZone(@src(), .{ .name = "extract_state" });
|
const frame_ = tracy.initZone(@src(), .{ .name = "extract_state" });
|
||||||
|
|
@ -803,7 +804,7 @@ pub const Editor = struct {
|
||||||
if (self.file_path) |file_path| {
|
if (self.file_path) |file_path| {
|
||||||
if (self.buffer) |b_mut| try b_mut.store_to_file_and_clean(file_path);
|
if (self.buffer) |b_mut| try b_mut.store_to_file_and_clean(file_path);
|
||||||
} else return error.SaveNoFileName;
|
} else return error.SaveNoFileName;
|
||||||
try self.send_editor_save(self.file_path.?, b.is_auto_save());
|
try self.send_editor_save(self.file_path.?, b.is_auto_save() and !b.is_ephemeral());
|
||||||
self.last.dirty = false;
|
self.last.dirty = false;
|
||||||
self.update_event() catch {};
|
self.update_event() catch {};
|
||||||
}
|
}
|
||||||
|
|
@ -1849,7 +1850,7 @@ pub const Editor = struct {
|
||||||
_ = try self.handlers.msg(.{ "E", "update", token_from(new_root), token_from(old_root), @intFromEnum(eol_mode) });
|
_ = 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)
|
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 {};
|
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.buffer) |b| if (b.is_auto_save())
|
if (self.buffer) |b| if (b.is_auto_save() and !b.is_ephemeral())
|
||||||
tp.self_pid().send(.{ "cmd", "save_file", .{} }) catch {};
|
tp.self_pid().send(.{ "cmd", "save_file", .{} }) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6277,24 +6278,45 @@ pub const Editor = struct {
|
||||||
if (state.before_root != root) return error.Stop;
|
if (state.before_root != root) return error.Stop;
|
||||||
defer self.filter_deinit();
|
defer self.filter_deinit();
|
||||||
const primary = self.get_primary();
|
const primary = self.get_primary();
|
||||||
self.cancel_all_selections();
|
|
||||||
self.cancel_all_matches();
|
|
||||||
if (state.whole_file) |buf| {
|
if (state.whole_file) |buf| {
|
||||||
state.work_root = try b.load_from_string(buf.items, &state.eol_mode, &state.utf8_sanitized);
|
if (buf.items.len == 0) {
|
||||||
state.bytes = buf.items.len;
|
self.logger.print_err("filter", "empty filter result", .{});
|
||||||
state.chunks = 1;
|
return;
|
||||||
primary.cursor = state.old_primary.cursor;
|
}
|
||||||
|
const old_hash = blk: {
|
||||||
|
var content: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
|
defer content.deinit();
|
||||||
|
try root.store(&content.writer, try self.buf_eol_mode());
|
||||||
|
break :blk std.hash.XxHash3.hash(0, content.written());
|
||||||
|
};
|
||||||
|
const new_hash = std.hash.XxHash3.hash(0, buf.items);
|
||||||
|
if (old_hash == new_hash) {
|
||||||
|
state.no_changes = true;
|
||||||
|
} else {
|
||||||
|
self.cancel_all_selections();
|
||||||
|
self.cancel_all_matches();
|
||||||
|
state.work_root = try b.load_from_string(buf.items, &state.eol_mode, &state.utf8_sanitized);
|
||||||
|
state.bytes = buf.items.len;
|
||||||
|
state.chunks = 1;
|
||||||
|
primary.cursor = state.old_primary.cursor;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
self.cancel_all_selections();
|
||||||
|
self.cancel_all_matches();
|
||||||
const sel = primary.enable_selection(root, self.metrics);
|
const sel = primary.enable_selection(root, self.metrics);
|
||||||
sel.begin = state.begin;
|
sel.begin = state.begin;
|
||||||
sel.end = state.pos.cursor;
|
sel.end = state.pos.cursor;
|
||||||
if (state.old_primary_reversed) sel.reverse();
|
if (state.old_primary_reversed) sel.reverse();
|
||||||
primary.cursor = sel.end;
|
primary.cursor = sel.end;
|
||||||
}
|
}
|
||||||
try self.update_buf_and_eol_mode(state.work_root, state.eol_mode, state.utf8_sanitized);
|
|
||||||
primary.cursor.clamp_to_buffer(state.work_root, self.metrics);
|
|
||||||
self.logger.print("filter: done (bytes:{d} chunks:{d})", .{ state.bytes, state.chunks });
|
self.logger.print("filter: done (bytes:{d} chunks:{d})", .{ state.bytes, state.chunks });
|
||||||
self.reset_syntax();
|
if (state.no_changes) {
|
||||||
|
self.logger.print("filter: no changes", .{});
|
||||||
|
} else {
|
||||||
|
try self.update_buf_and_eol_mode(state.work_root, state.eol_mode, state.utf8_sanitized);
|
||||||
|
primary.cursor.clamp_to_buffer(state.work_root, self.metrics);
|
||||||
|
self.reset_syntax();
|
||||||
|
}
|
||||||
self.clamp();
|
self.clamp();
|
||||||
self.need_render();
|
self.need_render();
|
||||||
if (self.need_save_after_filter) |info| {
|
if (self.need_save_after_filter) |info| {
|
||||||
|
|
@ -6489,7 +6511,7 @@ pub const Editor = struct {
|
||||||
buffer.file_type_color = ftc;
|
buffer.file_type_color = ftc;
|
||||||
}
|
}
|
||||||
const file_exists = if (self.buffer) |b| b.file_exists else false;
|
const file_exists = if (self.buffer) |b| b.file_exists else false;
|
||||||
const auto_save = if (self.buffer) |b| b.is_auto_save() else false;
|
const auto_save = if (self.buffer) |b| b.is_auto_save() and !b.is_ephemeral() else false;
|
||||||
try self.send_editor_open(self.file_path orelse "", file_exists, ftn, fti, ftc, auto_save);
|
try self.send_editor_open(self.file_path orelse "", file_exists, ftn, fti, ftc, auto_save);
|
||||||
self.logger.print("file type {s}", .{file_type});
|
self.logger.print("file type {s}", .{file_type});
|
||||||
}
|
}
|
||||||
|
|
@ -6500,7 +6522,7 @@ pub const Editor = struct {
|
||||||
const fti = if (self.file_type) |ft| ft.icon orelse file_type_config.default.icon else file_type_config.default.icon;
|
const fti = if (self.file_type) |ft| ft.icon orelse file_type_config.default.icon else file_type_config.default.icon;
|
||||||
const ftc = if (self.file_type) |ft| ft.color orelse file_type_config.default.color else file_type_config.default.color;
|
const ftc = if (self.file_type) |ft| ft.color orelse file_type_config.default.color else file_type_config.default.color;
|
||||||
const file_exists = if (self.buffer) |b| b.file_exists else false;
|
const file_exists = if (self.buffer) |b| b.file_exists else false;
|
||||||
const auto_save = if (self.buffer) |b| b.is_auto_save() else false;
|
const auto_save = if (self.buffer) |b| b.is_auto_save() and !b.is_ephemeral() else false;
|
||||||
try self.send_editor_open(self.file_path orelse "", file_exists, ftn, fti, ftc, auto_save);
|
try self.send_editor_open(self.file_path orelse "", file_exists, ftn, fti, ftc, auto_save);
|
||||||
self.last = .{};
|
self.last = .{};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,10 @@ fn get_replace_selection(replace: Buffer.Selection) ?Buffer.Selection {
|
||||||
replace;
|
replace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn complete(palette: *Type, _: ?*Type.ButtonType) !void {
|
||||||
|
palette.menu.activate_selected();
|
||||||
|
}
|
||||||
|
|
||||||
fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void {
|
fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void {
|
||||||
const values = get_values(button.opts.label);
|
const values = get_values(button.opts.label);
|
||||||
const editor = tui.get_active_editor() orelse return;
|
const editor = tui.get_active_editor() orelse return;
|
||||||
|
|
|
||||||
|
|
@ -554,6 +554,12 @@ pub fn Create(options: type) type {
|
||||||
.icon = "",
|
.icon = "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn palette_menu_complete(self: *Self, _: Ctx) Result {
|
||||||
|
if (@hasDecl(options, "complete"))
|
||||||
|
options.complete(self, self.menu.get_selected()) catch {};
|
||||||
|
}
|
||||||
|
pub const palette_menu_complete_meta: Meta = .{};
|
||||||
|
|
||||||
pub fn palette_menu_activate(self: *Self, _: Ctx) Result {
|
pub fn palette_menu_activate(self: *Self, _: Ctx) Result {
|
||||||
self.menu.activate_selected();
|
self.menu.activate_selected();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue