refactor: fix completion updates
This commit is contained in:
parent
b314a4c8c0
commit
d4eb0d046c
4 changed files with 9 additions and 4 deletions
|
|
@ -6601,15 +6601,18 @@ pub const Editor = struct {
|
||||||
self.completions_request = .done;
|
self.completions_request = .done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var open_completions = self.completions.data.items.len > 0;
|
||||||
const update_completion = "update_completion";
|
const update_completion = "update_completion";
|
||||||
if (command.get_id(update_completion)) |cmd_id|
|
if (command.get_id(update_completion)) |cmd_id| {
|
||||||
try command.execute(cmd_id, update_completion, .{});
|
try command.execute(cmd_id, update_completion, .{});
|
||||||
|
open_completions = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (self.completions_refresh_pending) {
|
if (self.completions_refresh_pending) {
|
||||||
self.completions_refresh_pending = false;
|
self.completions_refresh_pending = false;
|
||||||
try self.completion(.{});
|
try self.completion(.{});
|
||||||
}
|
}
|
||||||
return self.completions.data.items.len > 0;
|
return open_completions;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_completion_replacement_selection(self: *Self, insert_: ?Selection, replace_: ?Selection) ?Selection {
|
pub fn get_completion_replacement_selection(self: *Self, insert_: ?Selection, replace_: ?Selection) ?Selection {
|
||||||
|
|
|
||||||
|
|
@ -1198,8 +1198,8 @@ const cmds = struct {
|
||||||
var file_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
var file_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||||
file_path = project_manager.normalize_file_path(file_path, &file_path_buf);
|
file_path = project_manager.normalize_file_path(file_path, &file_path_buf);
|
||||||
if (self.get_active_editor()) |editor| if (std.mem.eql(u8, file_path, editor.file_path orelse "")) {
|
if (self.get_active_editor()) |editor| if (std.mem.eql(u8, file_path, editor.file_path orelse "")) {
|
||||||
const have_completions = try editor.add_completion_done();
|
const open_completions = try editor.add_completion_done();
|
||||||
if (have_completions) {
|
if (open_completions) {
|
||||||
switch (tui.config().completion_style) {
|
switch (tui.config().completion_style) {
|
||||||
.palette => try tui.open_overlay(@import("mode/overlay/completion_palette.zig").Type),
|
.palette => try tui.open_overlay(@import("mode/overlay/completion_palette.zig").Type),
|
||||||
.dropdown => try tui.open_overlay(@import("mode/overlay/completion_dropdown.zig").Type),
|
.dropdown => try tui.open_overlay(@import("mode/overlay/completion_dropdown.zig").Type),
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,7 @@ fn update_query(self: *Type, cursor: ed.Cursor) error{OutOfMemory}!void {
|
||||||
else => |e_| return e_,
|
else => |e_| return e_,
|
||||||
};
|
};
|
||||||
defer self.allocator.free(query);
|
defer self.allocator.free(query);
|
||||||
|
self.update_query(query) catch return;
|
||||||
tp.self_pid().send(.{ "cmd", "completion" }) catch |e| self.logger.err(module_name, e);
|
tp.self_pid().send(.{ "cmd", "completion" }) catch |e| self.logger.err(module_name, e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,7 @@ pub fn Create(options: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_query(self: *Self, query: []const u8) !void {
|
pub fn update_query(self: *Self, query: []const u8) !void {
|
||||||
|
self.query.clearRetainingCapacity();
|
||||||
try self.query.appendSlice(self.allocator, query);
|
try self.query.appendSlice(self.allocator, query);
|
||||||
return self.start_query(0);
|
return self.start_query(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue