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
29 changes: 29 additions & 0 deletions ServerDeck/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ function isTerminalViewportNearBottom(terminal: Terminal) {
return activeBuffer.baseY - activeBuffer.viewportY <= 1;
}

function clearDocumentSelection() {
const selection = window.getSelection();
if (!selection || selection.rangeCount === 0) {
return;
}

selection.removeAllRanges();
}

const MAX_TERMINAL_BUFFER_CHUNKS = 800;
const MAX_TERMINAL_BUFFER_CHARS = 400_000;

Expand Down Expand Up @@ -2070,6 +2079,8 @@ export default function App() {
terminal.open(terminalMountNode);
const clearSelectionFrame = window.requestAnimationFrame(() => {
terminal.clearSelection();
clearDocumentSelection();
terminal.focus();
});
terminal.attachCustomKeyEventHandler((event) => {
const sequence = getTerminalControlSequence(event);
Expand All @@ -2095,8 +2106,25 @@ export default function App() {
});
}

const terminalTextarea = terminal.textarea;
const handleTerminalBlur = () => {
window.requestAnimationFrame(() => {
terminal.clearSelection();
clearDocumentSelection();
});
};
terminalTextarea?.addEventListener("blur", handleTerminalBlur);

const disposable = terminal.onData((data) => {
sendActiveTerminalInput(data);

if (data === "\r") {
window.requestAnimationFrame(() => {
terminal.focus();
terminal.clearSelection();
clearDocumentSelection();
});
}
});

let frameId: number | null = null;
Expand Down Expand Up @@ -2131,6 +2159,7 @@ export default function App() {
}
window.cancelAnimationFrame(clearSelectionFrame);
disposable.dispose();
terminalTextarea?.removeEventListener("blur", handleTerminalBlur);
terminal.dispose();
terminalRef.current = null;
fitAddonRef.current = null;
Expand Down
11 changes: 11 additions & 0 deletions ServerDeck/src/components/agent/AgentWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export type ModelOption = {
model: string;
};

function clearDocumentSelection() {
const selection = window.getSelection();
if (!selection || selection.rangeCount === 0) {
return;
}

selection.removeAllRanges();
}

type AgentWorkspaceProps = {
title: string;
description: string;
Expand Down Expand Up @@ -198,6 +207,7 @@ export function AgentWorkspace({
node.focus({ preventScroll: true });
const cursor = node.value.length;
node.setSelectionRange(cursor, cursor);
clearDocumentSelection();
});
}, [activeSessionDetail?.session.id, composerValue, createBusy, latestMessageSignature, sendBusy]);

Expand Down Expand Up @@ -574,6 +584,7 @@ export function AgentWorkspace({
rows={3}
value={composerValue}
onKeyDown={handleComposerKeyDown}
onBlur={() => clearDocumentSelection()}
onChange={(event) => {
if (activeSessionDetail) {
onFollowUpInputChange(event.target.value);
Expand Down