feat: MobaXTerm-style clipboard — select to copy, right-click to paste
All checks were successful
Build & Sign Wraith / Build Windows + Sign (push) Successful in 1m3s
All checks were successful
Build & Sign Wraith / Build Windows + Sign (push) Successful in 1m3s
Highlight text auto-copies to clipboard via onSelectionChange. Right-click on terminal pastes from clipboard by writing to SSH stdin. Disables xterm.js default right-click word-select behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b7742b0247
commit
2ae628c858
@ -66,6 +66,7 @@ export function useTerminal(sessionId: string): UseTerminalReturn {
|
|||||||
scrollback: 10000,
|
scrollback: 10000,
|
||||||
allowProposedApi: true,
|
allowProposedApi: true,
|
||||||
convertEol: true,
|
convertEol: true,
|
||||||
|
rightClickSelectsWord: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
terminal.loadAddon(fitAddon);
|
terminal.loadAddon(fitAddon);
|
||||||
@ -86,6 +87,24 @@ export function useTerminal(sessionId: string): UseTerminalReturn {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// MobaXTerm-style clipboard: highlight to copy, right-click to paste
|
||||||
|
const selectionDisposable = terminal.onSelectionChange(() => {
|
||||||
|
const sel = terminal.getSelection();
|
||||||
|
if (sel) {
|
||||||
|
navigator.clipboard.writeText(sel).catch(() => {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleRightClickPaste(e: MouseEvent): void {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
navigator.clipboard.readText().then((text) => {
|
||||||
|
if (text) {
|
||||||
|
Call.ByName(`${SSH}.Write`, sessionId, text).catch(() => {});
|
||||||
|
}
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
// Listen for SSH output events from the Go backend (base64 encoded)
|
// Listen for SSH output events from the Go backend (base64 encoded)
|
||||||
let cleanupEvent: (() => void) | null = null;
|
let cleanupEvent: (() => void) | null = null;
|
||||||
|
|
||||||
@ -121,6 +140,9 @@ export function useTerminal(sessionId: string): UseTerminalReturn {
|
|||||||
terminal.open(container);
|
terminal.open(container);
|
||||||
fitAddon.fit();
|
fitAddon.fit();
|
||||||
|
|
||||||
|
// Right-click paste on the terminal's DOM element
|
||||||
|
terminal.element?.addEventListener("contextmenu", handleRightClickPaste);
|
||||||
|
|
||||||
// Subscribe to SSH output events for this session
|
// Subscribe to SSH output events for this session
|
||||||
// Wails v3 Events.On callback receives a CustomEvent object with .data property
|
// Wails v3 Events.On callback receives a CustomEvent object with .data property
|
||||||
cleanupEvent = Events.On(`ssh:data:${sessionId}`, (event: any) => {
|
cleanupEvent = Events.On(`ssh:data:${sessionId}`, (event: any) => {
|
||||||
@ -175,6 +197,8 @@ export function useTerminal(sessionId: string): UseTerminalReturn {
|
|||||||
terminal.write(pendingData);
|
terminal.write(pendingData);
|
||||||
pendingData = "";
|
pendingData = "";
|
||||||
}
|
}
|
||||||
|
terminal.element?.removeEventListener("contextmenu", handleRightClickPaste);
|
||||||
|
selectionDisposable.dispose();
|
||||||
if (cleanupEvent) {
|
if (cleanupEvent) {
|
||||||
cleanupEvent();
|
cleanupEvent();
|
||||||
cleanupEvent = null;
|
cleanupEvent = null;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user