From 102f34090db95de9e24c475fdea34b19031e9a94 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 6 Dec 2024 09:06:56 +0000 Subject: [PATCH 1/2] Do not write bracketed paste keys themselves if the pane has not asked for them. --- server-client.c | 2 +- tmux.h | 7 ++++++- window.c | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server-client.c b/server-client.c index 98fdf1c9..a8911224 100644 --- a/server-client.c +++ b/server-client.c @@ -2581,7 +2581,7 @@ paste_key: if (c->flags & CLIENT_READONLY) goto out; if (event->buf != NULL) - window_pane_paste(wp, event->buf, event->len); + window_pane_paste(wp, key, event->buf, event->len); key = KEYC_NONE; goto out; diff --git a/tmux.h b/tmux.h index c6e5f4d3..bc4df764 100644 --- a/tmux.h +++ b/tmux.h @@ -165,6 +165,10 @@ struct winlink; (((key) & KEYC_MASK_KEY) < KEYC_USER || \ ((key) & KEYC_MASK_KEY) >= KEYC_USER_END)) +/* Is this a paste key? */ +#define KEYC_IS_PASTE(key) \ + ((key) == KEYC_PASTE_START || (key) == KEYC_PASTE_END) + /* Multiple click timeout. */ #define KEYC_CLICK_TIMEOUT 300 @@ -3160,7 +3164,8 @@ void window_pane_reset_mode_all(struct window_pane *); int window_pane_key(struct window_pane *, struct client *, struct session *, struct winlink *, key_code, struct mouse_event *); -void window_pane_paste(struct window_pane *, char *, size_t); +void window_pane_paste(struct window_pane *, key_code, char *, + size_t); int window_pane_visible(struct window_pane *); int window_pane_exited(struct window_pane *); u_int window_pane_search(struct window_pane *, const char *, int, diff --git a/window.c b/window.c index 67e96fcf..35fc370b 100644 --- a/window.c +++ b/window.c @@ -1219,7 +1219,7 @@ window_pane_copy_key(struct window_pane *wp, key_code key) } void -window_pane_paste(struct window_pane *wp, char *buf, size_t len) +window_pane_paste(struct window_pane *wp, key_code key, char *buf, size_t len) { if (!TAILQ_EMPTY(&wp->modes)) return; @@ -1227,6 +1227,9 @@ window_pane_paste(struct window_pane *wp, char *buf, size_t len) if (wp->fd == -1 || wp->flags & PANE_INPUTOFF) return; + if (KEYC_IS_PASTE(key) && (~wp->screen->mode & MODE_BRACKETPASTE)) + return; + log_debug("%s: %.*s", __func__, (int)len, buf); bufferevent_write(wp->event, buf, len); From 5c3cf2f08b0b10cb245a63ec8e0f5f39629e1f6b Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 6 Dec 2024 09:07:40 +0000 Subject: [PATCH 2/2] Preserve modifiers on backspace. --- input-keys.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/input-keys.c b/input-keys.c index 4cad4f50..3fa38049 100644 --- a/input-keys.c +++ b/input-keys.c @@ -588,9 +588,10 @@ input_key(struct screen *s, struct bufferevent *bev, key_code key) newkey = options_get_number(global_options, "backspace"); if (newkey == KEYC_BSPACE) newkey = '\b'; - log_debug("%s: key 0x%llx is backspace -> 0x%llx", __func__, - key, newkey|(key & KEYC_MASK_FLAGS)); - key = newkey|(key & KEYC_MASK_FLAGS); + newkey |= (key & (KEYC_MASK_FLAGS|KEYC_MASK_MODIFIERS)); + log_debug("%s: key 0x%llx is backspace -> 0x%llx", __func__, key, + newkey); + key = newkey; } /* Is this backtab? */ @@ -645,8 +646,7 @@ input_key(struct screen *s, struct bufferevent *bev, key_code key) if (ike != NULL) { log_debug("%s: found key 0x%llx: \"%s\"", __func__, key, ike->data); - if ((key == KEYC_PASTE_START || key == KEYC_PASTE_END) && - (~s->mode & MODE_BRACKETPASTE)) + if (KEYC_IS_PASTE(key) && (~s->mode & MODE_BRACKETPASTE)) return (0); if ((key & KEYC_META) && (~key & KEYC_IMPLIED_META)) input_key_write(__func__, bev, "\033", 1);