aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Linford <tlinford@users.noreply.github.com>2025-08-20 17:20:59 +0200
committerGitHub <noreply@github.com>2025-08-20 17:20:59 +0200
commit7146995abcff1842ce6eb95abd212f14f5dba432 (patch)
tree75d35b2c13b0cba52d37b29c18852ff301edd1a8
parentchore(repo): update development version (diff)
downloadsl0ppij-7146995abcff1842ce6eb95abd212f14f5dba432.tar.gz
sl0ppij-7146995abcff1842ce6eb95abd212f14f5dba432.tar.xz
sl0ppij-7146995abcff1842ce6eb95abd212f14f5dba432.zip
fix(web): avoid sending single meta keypresses, cleanup (#4376)
* fix(web): avoid sending single meta keypresses, cleanup - extend the logic already used to skip single modifier keypresses to meta - refactor: extract the code into a function, make it simpler and use event.key instead of deprecated event.keyCode - cleanup leftover axum cors config from feature development * update changelog
-rw-r--r--CHANGELOG.md1
-rw-r--r--zellij-client/assets/input.js46
-rw-r--r--zellij-client/src/web_client/mod.rs2
3 files changed, 24 insertions, 25 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5e770246..5f31d71a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased]
+* fix: meta key handling in web client (https://github.com/zellij-org/zellij/pull/4376)
## [0.43.1] - 2025-08-08
* fix: pane rename backspace regression (https://github.com/zellij-org/zellij/pull/4346)
diff --git a/zellij-client/assets/input.js b/zellij-client/assets/input.js
index bba504ef..b4239607 100644
--- a/zellij-client/assets/input.js
+++ b/zellij-client/assets/input.js
@@ -26,29 +26,7 @@ export function setupInputHandlers(term, sendFunction) {
// pass cmd-v onwards so that paste is interpreted by xterm.js
return;
}
-
- let modifiers_count = 0;
- let shift_keycode = 16;
- let alt_keycode = 17;
- let ctrl_keycode = 18;
- if (ev.altKey) {
- modifiers_count += 1;
- }
- if (ev.ctrlKey) {
- modifiers_count += 1;
- }
- if (ev.shiftKey) {
- modifiers_count += 1;
- }
- if (ev.metaKey) {
- modifiers_count += 1;
- }
- if (
- (modifiers_count > 1 || ev.metaKey) &&
- ev.keyCode != shift_keycode &&
- ev.keyCode != alt_keycode &&
- ev.keyCode != ctrl_keycode
- ) {
+ if (hasModifiersToHandle(ev)) {
ev.preventDefault();
encode_kitty_key(ev, sendFunction);
return false;
@@ -132,3 +110,25 @@ export function setupInputHandlers(term, sendFunction) {
sendFunction(buffer);
});
}
+
+/**
+ * Check if a key event has modifiers and is not a modifier key itself
+ * @param {KeyboardEvent} ev - The keyboard event
+ * @returns {boolean} - True if the key has modifiers that need special handling
+ */
+function hasModifiersToHandle(ev) {
+ // Use key property for simpler modifier key detection
+ const MODIFIER_KEYS = ["Shift", "Control", "Alt", "Meta"];
+
+ // Count active modifiers
+ const modifiers_count = [
+ ev.altKey,
+ ev.ctrlKey,
+ ev.shiftKey,
+ ev.metaKey,
+ ].filter(Boolean).length;
+
+ // Check if we have multiple modifiers or meta key, and it's not a modifier key itself
+ const isModifierKey = MODIFIER_KEYS.includes(ev.key);
+ return (modifiers_count > 1 || ev.metaKey) && !isModifierKey;
+}
diff --git a/zellij-client/src/web_client/mod.rs b/zellij-client/src/web_client/mod.rs
index 33776695..d7ef7ec0 100644
--- a/zellij-client/src/web_client/mod.rs
+++ b/zellij-client/src/web_client/mod.rs
@@ -33,7 +33,6 @@ use nix::sys::stat::{umask, Mode};
use interprocess::unnamed_pipe::pipe;
use std::io::{prelude::*, BufRead, BufReader};
use tokio::runtime::Runtime;
-use tower_http::cors::CorsLayer;
use zellij_utils::input::{
config::{watch_config_file_changes, Config},
options::Options,
@@ -259,7 +258,6 @@ pub async fn serve_web_client(
.route("/assets/{*path}", get(get_static_asset))
.route("/command/login", post(login_handler))
.route("/info/version", get(version_handler))
- .layer(CorsLayer::permissive()) // TODO: configure properly
.with_state(state);
match rustls_config {