fix: enable clipboard support and suppress browser context menu in web terminal

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
centdix
2026-02-21 17:22:43 +00:00
co-authored by Claude Opus 4.5
parent 696b8de1ed
commit c4323e40c1
2 changed files with 25 additions and 0 deletions
+1
View File
@@ -62,6 +62,7 @@ export async function attach(
const cmd = [
`tmux new-session -d -s "${gName}" -t "${tmuxSession}"`,
`tmux set-option -t "${gName}" mouse on`,
`tmux set-option -t "${gName}" set-clipboard on`,
`tmux select-window -t "${gName}:${windowTarget}"`,
`stty rows ${rows} cols ${cols}`,
`exec tmux attach-session -t "${gName}"`,
@@ -32,6 +32,30 @@
term.loadAddon(new WebLinksAddon());
term.open(containerEl);
// Prevent browser context menu so tmux right-click works unobstructed
containerEl.addEventListener("contextmenu", (e) => e.preventDefault());
// Handle OSC 52 sequences from tmux → write to system clipboard
term.parser.registerOscHandler(52, (data) => {
const idx = data.indexOf(";");
if (idx !== -1) {
const b64 = data.slice(idx + 1);
try {
const text = atob(b64);
navigator.clipboard.writeText(text);
} catch {}
}
return true;
});
// Auto-copy on xterm.js selection (e.g. when user Shift+drags to bypass tmux mouse)
term.onSelectionChange(() => {
const sel = term.getSelection();
if (sel) {
navigator.clipboard.writeText(sel);
}
});
requestAnimationFrame(() => fitAddon.fit());
const protocol = location.protocol === "https:" ? "wss:" : "ws:";