fix paste outputting "v"

This commit is contained in:
Mitchell Hashimoto
2022-06-26 16:39:48 -07:00
parent fae36f4e65
commit bcc6b7604d
2 changed files with 17 additions and 5 deletions

View File

@ -1,12 +1,9 @@
Bugs: Bugs:
* Paste puts a "v" at the end of the string
Performance: Performance:
* libuv allocates on every read, we should use a read buffer pool * libuv allocates on every read, we should use a read buffer pool
* update cells should only update the changed cells * update cells should only update the changed cells
* terminal data structure is bad!
Correctness: Correctness:

View File

@ -93,6 +93,12 @@ bg_a: f32,
/// Bracketed paste mode /// Bracketed paste mode
bracketed_paste: bool = false, bracketed_paste: bool = false,
/// Set to true for a single GLFW key/char callback cycle to cause the
/// char callback to ignore. GLFW seems to always do key followed by char
/// callbacks so we abuse that here. This is to solve an issue where commands
/// like such as "control-v" will write a "v" even if they're intercepted.
ignore_char: bool = false,
/// Create a new window. This allocates and returns a pointer because we /// Create a new window. This allocates and returns a pointer because we
/// need a stable pointer for user data callbacks. Therefore, a stack-only /// need a stable pointer for user data callbacks. Therefore, a stack-only
/// initialization is not currently possible. /// initialization is not currently possible.
@ -368,6 +374,12 @@ fn charCallback(window: glfw.Window, codepoint: u21) void {
const win = window.getUserPointer(Window) orelse return; const win = window.getUserPointer(Window) orelse return;
// Ignore if requested. See field docs for more information.
if (win.ignore_char) {
win.ignore_char = false;
return;
}
// Write the character to the pty // Write the character to the pty
win.queueWrite(&[1]u8{@intCast(u8, codepoint)}) catch unreachable; win.queueWrite(&[1]u8{@intCast(u8, codepoint)}) catch unreachable;
} }
@ -386,14 +398,17 @@ fn keyCallback(
// Paste // Paste
if (action == .press and mods.super and key == .v) { if (action == .press and mods.super and key == .v) {
const win = window.getUserPointer(Window) orelse return;
// Ignore this character for writing
win.ignore_char = true;
const data = glfw.getClipboardString() catch |err| { const data = glfw.getClipboardString() catch |err| {
log.warn("error reading clipboard: {}", .{err}); log.warn("error reading clipboard: {}", .{err});
return; return;
}; };
if (data.len > 0) { if (data.len > 0) {
const win = window.getUserPointer(Window) orelse return;
if (win.bracketed_paste) win.queueWrite("\x1B[200~") catch unreachable; if (win.bracketed_paste) win.queueWrite("\x1B[200~") catch unreachable;
win.queueWrite(data) catch |err| win.queueWrite(data) catch |err|
log.warn("error pasting clipboard: {}", .{err}); log.warn("error pasting clipboard: {}", .{err});