Compare commits

..

No commits in common. "01cbdf8545bb9ef9b01b119f90a3cd0ee069b897" and "281b9e47a1c33f309703bc587540ebcba9b53386" have entirely different histories.

2 changed files with 30 additions and 47 deletions

View file

@ -6552,15 +6552,7 @@ pub const Editor = struct {
}
pub fn run_triggers(self: *Self, cursel: *const CurSel, char: u8, event: TriggerEvent) void {
var mode = tui.config().completion_trigger;
if (mode == .every_keystroke) {
const update_completion = "update_completion";
const in_completion = command.get_id(update_completion) != null;
mode = if (in_completion) .automatic else .every_keystroke;
}
switch (mode) {
switch (tui.config().completion_trigger) {
.manual => return,
.every_keystroke => return self.run_triggers_every_keystroke(cursel, char, event),
.automatic => {},
@ -6609,14 +6601,11 @@ pub const Editor = struct {
pub fn add_completion_done(self: *Self) anyerror!bool {
self.completions.deinit(self.allocator);
self.completions = if (self.completions_request) |*request| request.* else .empty;
self.completions_request = .done;
if (command.log_execute) {
var iter: []const u8 = self.completions.data.items;
var count: usize = 0;
while (iter.len > 0) : (count += 1) try cbor.skipValue(&iter);
self.logger.print("completions: {d}", .{count});
self.completions = .empty;
if (self.completions_request) |*request| {
self.completions.deinit(self.allocator);
self.completions = request.*;
self.completions_request = .done;
}
var open_completions = self.completions.data.items.len > 0;

View file

@ -44,6 +44,7 @@ var max_description: usize = 0;
pub fn init(self: *Type) error{ Stop, OutOfMemory }!void {
try self.value.commands.init(self);
self.value.editor = tui.get_active_editor() orelse return error.Stop;
self.value.cursor = self.value.editor.get_primary().cursor;
self.value.view = self.value.editor.view;
}
@ -51,7 +52,6 @@ pub fn load_entries(self: *Type) !usize {
max_description = 0;
var max_label_len: usize = 0;
self.value.cursor = self.value.editor.get_primary().cursor;
self.value.query = null;
var iter: []const u8 = self.value.editor.completions.data.items;
while (iter.len > 0) {
@ -102,8 +102,25 @@ pub fn handle_event(self: *Type, _: tp.pid_ref, m: tp.message) tp.result {
try m.match(.{ "E", "close" }))
{
const cursor = self.value.editor.get_primary().cursor;
if (!maybe_cancel(self, cursor))
maybe_update_query(self, cursor) catch |e| self.logger.err(module_name, e);
if (self.value.cursor.row != cursor.row or
self.value.cursor.col > cursor.col or
!self.value.view.eql(self.value.editor.view))
{
tp.self_pid().send(.{ "cmd", "palette_menu_cancel" }) catch |e| self.logger.err(module_name, e);
} else {
const query = get_query_text_nostore(self, cursor, self.allocator) catch |e| switch (e) {
error.Stop => return,
else => |e_| {
self.logger.err(module_name, e_);
return;
},
};
defer self.allocator.free(query);
if (self.value.last_query) |last| {
if (!std.mem.eql(u8, query, last))
update_query(self, cursor) catch |e| self.logger.err(module_name, e);
} else update_query(self, cursor) catch |e| self.logger.err(module_name, e);
}
}
}
@ -126,35 +143,13 @@ fn get_query_text(self: *Type, cursor: ed.Cursor, allocator: std.mem.Allocator)
return query;
}
fn maybe_cancel(self: *Type, cursor: Buffer.Cursor) bool {
if (self.value.cursor.row != cursor.row or
self.value.cursor.col > cursor.col or
!self.value.view.eql(self.value.editor.view))
{
tp.self_pid().send(.{ "cmd", "palette_menu_cancel" }) catch |e| self.logger.err(module_name, e);
return true;
}
return false;
}
fn maybe_update_query(self: *Type, cursor: Buffer.Cursor) error{OutOfMemory}!void {
const query = get_query_text_nostore(self, cursor, self.allocator) catch |e| switch (e) {
error.Stop => return,
else => |e_| return e_,
};
defer self.allocator.free(query);
if (self.value.last_query) |last| {
if (!std.mem.eql(u8, query, last))
try update_query_text(self, cursor);
} else try update_query_text(self, cursor);
}
fn update_query_text(self: *Type, cursor: ed.Cursor) error{OutOfMemory}!void {
fn update_query(self: *Type, cursor: ed.Cursor) error{OutOfMemory}!void {
const query = get_query_text(self, cursor, self.allocator) catch |e| switch (e) {
error.Stop => return,
else => |e_| return e_,
};
Type.update_query(self, query) catch return;
self.update_query(query) catch return;
tp.self_pid().send(.{ "cmd", "completion" }) catch |e| self.logger.err(module_name, e);
return;
}
@ -374,8 +369,7 @@ const cmds = struct {
}
clear_entries(self);
self.longest_hint = try load_entries(self);
try update_query_text(self, self.value.editor.get_primary().cursor);
_ = try load_entries(self);
}
pub const update_completion_meta: Meta = .{};
};