refactor: call insert trigger commands when a single trigger char is inserted

This commit is contained in:
CJ van den Berg 2025-12-21 17:03:22 +01:00
parent 10e9348901
commit d711279938
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -2843,6 +2843,7 @@ pub const Editor = struct {
cursor.row, cursor.col, root_ = try root_.insert_chars(cursor.row, cursor.col, s, allocator, self.metrics);
cursor.target = cursor.col;
self.nudge_insert(.{ .begin = begin, .end = cursor.* }, cursel, s.len);
if (s.len == 1) self.run_insert_triggers(s[0]);
return root_;
}
@ -6216,6 +6217,15 @@ pub const Editor = struct {
return false;
}
pub fn run_insert_triggers(self: *Self, char: u8) void {
switch (char) {
'\n', '\t', ' ' => return,
else => {},
}
for (self.insert_triggers.items) |item| if (item.char == char)
tp.self_pid().send(.{ "cmd", item.command, .{[_]u8{char}} }) catch {};
}
pub fn add_completion(self: *Self, row: usize, col: usize, is_incomplete: bool, msg: tp.message) Result {
if (!(row == self.completion_row and col == self.completion_col)) {
self.completions.clearRetainingCapacity();