Fix iPad modifier handling for mobile keybar

This commit is contained in:
GitHub Copilot
2026-02-01 01:36:35 +00:00
parent e99ac51495
commit 7849e53edd
2 changed files with 43 additions and 60 deletions
File diff suppressed because one or more lines are too long
+20 -37
View File
@@ -676,14 +676,8 @@ class WebTerminal {
this.element.appendChild(textarea); this.element.appendChild(textarea);
this.mobileInput = textarea; this.mobileInput = textarea;
// Handle special keys via beforeinput to intercept before browser modifies textarea const applyMobileModifiers = (text: string): string => {
textarea.addEventListener("beforeinput", (e) => { let toSend = text;
if (
e.inputType === "insertText"
&& e.data
&& (this.ctrlActive || this.shiftActive || this.pendingCtrl || this.pendingShift)
) {
let toSend = e.data;
if ((this.shiftActive || this.pendingShift) && toSend.length === 1) { if ((this.shiftActive || this.pendingShift) && toSend.length === 1) {
toSend = toSend.toUpperCase(); toSend = toSend.toUpperCase();
} }
@@ -693,13 +687,28 @@ class WebTerminal {
toSend = String.fromCharCode(code - 64); toSend = String.fromCharCode(code - 64);
} }
} }
return toSend;
};
const handleMobileInput = (text: string, e?: Event) => {
if (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
this.send(["stdin", toSend]); }
if (!text) {
return;
}
this.send(["stdin", applyMobileModifiers(text)]);
textarea.value = ""; textarea.value = "";
this.deactivateModifiers(); this.deactivateModifiers();
this.pendingCtrl = false; this.pendingCtrl = false;
this.pendingShift = false; this.pendingShift = false;
};
// Handle special keys via beforeinput to intercept before browser modifies textarea
textarea.addEventListener("beforeinput", (e) => {
if (e.inputType === "insertText" && e.data) {
handleMobileInput(e.data, e);
return; return;
} }
@@ -716,39 +725,13 @@ class WebTerminal {
break; break;
} }
if (seq) { if (seq) {
e.preventDefault(); handleMobileInput(seq, e);
e.stopPropagation();
this.send(["stdin", seq]);
// Clear modifiers after sending special keys from soft keyboard
this.deactivateModifiers();
} }
}); });
// Handle input from mobile keyboard (regular text only, special keys handled above) // Handle input from mobile keyboard (regular text only, special keys handled above)
textarea.addEventListener("input", () => { textarea.addEventListener("input", () => {
const value = textarea.value; handleMobileInput(textarea.value);
if (value) {
let toSend = value;
// Apply Shift modifier (uppercase letters)
if (this.shiftActive || this.pendingShift) {
toSend = value.toUpperCase();
}
// Apply Ctrl modifier if active (convert letters to control codes)
if (this.ctrlActive || this.pendingCtrl) {
const firstChar = toSend[0] ?? "";
const code = firstChar.toUpperCase().charCodeAt(0);
if (code >= 65 && code <= 90) {
toSend = String.fromCharCode(code - 64); // Ctrl+A = 0x01, Ctrl+D = 0x04, etc.
} else {
toSend = firstChar;
}
}
this.send(["stdin", toSend]);
textarea.value = "";
this.deactivateModifiers();
this.pendingCtrl = false;
this.pendingShift = false;
}
}); });
// Handle special navigation keys via keydown (not covered by beforeinput) // Handle special navigation keys via keydown (not covered by beforeinput)