core: textCallback to send text directly to the terminal

This commit is contained in:
Mitchell Hashimoto
2023-10-04 07:50:05 -07:00
parent e471228f6b
commit 3046fb6dd7
2 changed files with 10 additions and 13 deletions

View File

@ -1020,6 +1020,15 @@ pub fn keyCallback(
return true; return true;
} }
/// Sends text as-is to the terminal without triggering any keyboard
/// protocol. This will treat the input text as if it was pasted
/// from the clipboard so the same logic will be applied. Namely,
/// if bracketed mode is on this will do a bracketed paste. Otherwise,
/// this will filter newlines to '\r'.
pub fn textCallback(self: *Surface, text: []const u8) !void {
try self.completeClipboardPaste(text);
}
pub fn focusCallback(self: *Surface, focused: bool) !void { pub fn focusCallback(self: *Surface, focused: bool) !void {
// Notify our render thread of the new state // Notify our render thread of the new state
_ = self.renderer_thread.mailbox.push(.{ _ = self.renderer_thread.mailbox.push(.{

View File

@ -686,19 +686,7 @@ pub const Surface = struct {
return; return;
}; };
// For a char callback we just construct a key event with invalid _ = self.core_surface.textCallback(buf[0..len]) catch |err| {
// keys but with text. This should result in the text being sent
// as-is.
_ = self.core_surface.keyCallback(.{
.action = .press,
.key = .invalid,
.physical_key = .invalid,
.mods = .{},
.consumed_mods = .{},
.composing = false,
.utf8 = buf[0..len],
.unshifted_codepoint = 0,
}) catch |err| {
log.err("error in key callback err={}", .{err}); log.err("error in key callback err={}", .{err});
return; return;
}; };