From 3046fb6dd7f32a8c15540f2f58c269d5a0eeaa67 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 4 Oct 2023 07:50:05 -0700 Subject: [PATCH] core: textCallback to send text directly to the terminal --- src/Surface.zig | 9 +++++++++ src/apprt/embedded.zig | 14 +------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 70f4d9405..872e8fe1d 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1020,6 +1020,15 @@ pub fn keyCallback( 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 { // Notify our render thread of the new state _ = self.renderer_thread.mailbox.push(.{ diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index bffc8a95b..28d54286e 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -686,19 +686,7 @@ pub const Surface = struct { return; }; - // For a char callback we just construct a key event with invalid - // 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| { + _ = self.core_surface.textCallback(buf[0..len]) catch |err| { log.err("error in key callback err={}", .{err}); return; };