Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,23 @@ export default function App() {

window.addEventListener("beforeunload", () => flushPersistedState());

// Shift+ArrowUp / Shift+ArrowDown: cycle tabs. Registered in the capture
// phase so it fires before xterm's textarea handler — otherwise xterm
// swallows the event (translates it to a PTY escape sequence) and the tab
// bar only responds after the user clicks the sidebar to move focus.
// Skipped when focus is in a real text input / passthrough mode so the key
// can still extend selection / be forwarded to the remote agent.
// Shift+ArrowUp/Down and Ctrl+PageUp/PageDown: cycle tabs. Registered in
// the capture phase so it fires before xterm's textarea handler —
// otherwise xterm swallows the event (translates it to a PTY escape
// sequence) and the tab bar only responds after the user clicks the
// sidebar to move focus. Skipped when focus is in a real text input /
// passthrough mode so the key can still extend selection / be forwarded
// to the remote agent.
window.addEventListener(
"keydown",
(e) => {
if (!e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) return;
if (e.key !== "ArrowUp" && e.key !== "ArrowDown") return;
const shiftCombo =
e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey &&
(e.key === "ArrowUp" || e.key === "ArrowDown");
const ctrlCombo =
e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey &&
(e.key === "PageUp" || e.key === "PageDown");
if (!shiftCombo && !ctrlCombo) return;
if (isActiveTabPassthrough()) return;
// xterm's own input is a hidden <textarea>, so we can't blanket-skip
// text inputs — instead, allow if focus is inside an .xterm container,
Expand All @@ -143,8 +149,9 @@ export default function App() {
if (list.length < 2) return;
e.preventDefault();
e.stopPropagation();
const goPrev = e.key === "ArrowUp" || e.key === "PageUp";
const idx = list.findIndex((t) => t.id === activeTabId());
const next = e.key === "ArrowUp"
const next = goPrev
? (idx - 1 + list.length) % list.length
: (idx + 1) % list.length;
setActiveTab(list[next].id);
Expand Down
11 changes: 4 additions & 7 deletions src/components/SideTerminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,13 @@ function SideTerminalView(props: { sessionId: string; parentTabId: string }) {
};
host.addEventListener("mouseup", onMouseUp);

// Middle-click paste (X11-style): write clipboard text straight to the PTY.
// Middle-click: just suppress the browser's auto-scroll affordance.
// WebKitGTK already does X11-style primary-selection paste into the
// focused textarea, which xterm forwards via onData — doing our own
// clipboard.readText + sshWrite here would paste twice.
const onMouseDown = (e: MouseEvent) => {
if (e.button !== 1) return;
e.preventDefault();
navigator.clipboard
.readText()
.then((text) => {
if (text) api.sshWrite(props.sessionId, text).catch(console.error);
})
.catch((err) => console.warn("clipboard read failed", err));
};
host.addEventListener("mousedown", onMouseDown);

Expand Down
15 changes: 4 additions & 11 deletions src/components/Terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,13 @@ export function TerminalView(props: Props) {
host.addEventListener("mouseup", onMouseUp);
onCleanup(() => host.removeEventListener("mouseup", onMouseUp));

// Middle-click pastes plain text from the OS clipboard (X11-style). We
// intercept on mousedown to suppress the browser's auto-scroll affordance,
// then write the text directly to the PTY.
// Middle-click: just suppress the browser's auto-scroll affordance.
// WebKitGTK already does X11-style primary-selection paste into the
// focused textarea, which xterm forwards via onData — doing our own
// clipboard.readText + sshWrite here would paste twice.
const onMouseDown = (e: MouseEvent) => {
if (e.button !== 1) return;
e.preventDefault();
navigator.clipboard
.readText()
.then((text) => {
if (!text) return;
const sid = props.tab.sessionId;
if (sid) api.sshWrite(sid, text).catch(console.error);
})
.catch((err) => console.warn("clipboard read failed", err));
};
host.addEventListener("mousedown", onMouseDown);
onCleanup(() => host.removeEventListener("mousedown", onMouseDown));
Expand Down
Loading