fix(terminal): an OSC 52 copy hands focus back to the terminal (#611 merge-time fix)

When navigator.clipboard is missing (plain HTTP, install.sh's LAN option) or
refuses the write (an unfocused window), _copyText falls back to a hidden
textarea whose select() takes focus, and removing it left focus on <body>:
the next keystrokes after Claude Code's /copy went nowhere. The handler now
restores the element focused before the copy, as Auto Copy does.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-10-13 18:16:56 +02:00
1 parent f3d7a86c16
commit f073742cf7
3 files changed
+34 -3

No files matched your search

+8
View File
@@ -5104,7 +5104,15 @@ Object.assign(CodemanApp.prototype, {
const now = Date.now();
if (this._lastOsc52?.text === text && now - this._lastOsc52.at < OSC52_DEDUPE_MS) return true;
this._lastOsc52 = { text, at: now };
// _copyText's execCommand fallback (plain HTTP, or a refused Clipboard API
// write) focuses a temporary textarea; hand focus back as Auto Copy does.
const focusedBefore = document.activeElement;
this._copyText(text).then((ok) => {
if (focusedBefore && focusedBefore !== document.activeElement && focusedBefore.isConnected) {
try {
focusedBefore.focus();
} catch {}
}
if (ok) this.showToast(`Copied to clipboard (${text.length} chars)`, 'success');
else if (document.hasFocus?.()) this._showClipboardFallback?.(text);
});