refactor(terminal): rename execute action to prepare in action link components

- Updated ActionLinkMenu and useActionLinks to replace the execute function with prepare for better clarity in command handling.
- Modified ActionLinkTooltip to reflect the change in terminology for user instructions.
- Removed unused executeActionCommandRef from XTerminal to streamline the codebase.
This commit is contained in:
Kang committed 2026-07-08 01:30:58 +08:00
1 parent 2fad6df717
commit a6e2985ef6
5 files changed
+12 -15

No files matched your search

+2 -2
View File
@@ -48,11 +48,11 @@ export default function ActionLinkMenu({ state, onClose }: ActionLinkMenuProps)
if (!state) return null;
const { x, y, link, actions, execute } = state;
const { x, y, link, actions, prepare } = state;
const pos = computeMenuPosition(x, y, ref.current);
const handleAction = (actionId: string) => {
execute(actionId);
prepare(actionId);
onClose();
};
@@ -112,6 +112,9 @@ export default function ActionLinkTooltip({ state }: ActionLinkTooltipProps) {
<span className="text-muted-foreground font-sans">{t("terminal.click")}</span>
</div>
<span className="text-muted-foreground/40 shrink-0">→</span>
<span className="text-muted-foreground font-sans shrink-0">
{t("terminal.actionLinkPrepareCommand")}
</span>
<span
className="text-foreground tracking-tight truncate border-b border-foreground/10 pb-[1px]"
title={defaultAction.command}
+1 -7
View File
@@ -259,7 +259,6 @@ export default function XTerminal({
const tRef = useRef(t);
const doFindRef = useRef<(selection?: string) => void>(() => {});
const pasteTextRef = useRef<(text: string, options?: { skipDialog?: boolean }) => void>(() => {});
const executeActionCommandRef = useRef<((command: string) => void) | null>(null);
const disconnectedRef = useRef(false);
const reconnectingRef = useRef(false);
const preservedReconnectContentRef = useRef<string | null>(null);
@@ -724,10 +723,6 @@ export default function XTerminal({
syncSuggestionsWithInputState();
};
executeActionCommandRef.current = (command: string) => {
void executeInputCommand(command).catch(() => {});
};
const isCredentialPromptInputMode = () => {
if (credentialPromptInputUntilRef.current > Date.now()) {
return true;
@@ -2054,7 +2049,6 @@ export default function XTerminal({
clearCredentialPromptInputMode();
shellIntegrationRef.current.enabled = false;
shellIntegrationRef.current.commandRunning = false;
executeActionCommandRef.current = null;
replaceInputCommandRef.current = null;
pasteTextRef.current = () => {};
resetCredentialAutofill();
@@ -2136,7 +2130,7 @@ export default function XTerminal({
terminalInstance,
terminalSettings,
sessionId,
executeActionCommandRef,
replaceInputCommandRef,
performanceMode === "overloaded" || !visible,
);
+5 -5
View File
@@ -30,7 +30,7 @@ export interface MenuState {
y: number;
link: ActionLink;
actions: ResolvedAction[];
execute: (actionId: string) => void;
prepare: (actionId: string) => void;
}
export interface UseActionLinksResult {
@@ -48,7 +48,7 @@ export function useActionLinks(
terminal: Terminal | null,
terminalSettings: AppSettings["terminal"],
_sessionId: string,
executeCommandRef: React.RefObject<((command: string) => void) | null>,
prepareCommandRef: React.RefObject<((command: string) => void) | null>,
suspended = false,
): UseActionLinksResult {
const addonRef = useRef<ActionLinksAddon | null>(null);
@@ -87,13 +87,13 @@ export function useActionLinks(
allowCtrlOrMetaClickExecute: true,
allowAltClickMenu: true,
fallbackAltClickToDefaultAction: true,
executeCommand: (command) => executeCommandRef.current?.(command),
executeCommand: (command) => prepareCommandRef.current?.(command),
showTooltip: ({ event, link }) => {
setTooltipState({ x: event.clientX, y: event.clientY, link });
},
hideTooltip: () => setTooltipState(null),
showMenu: ({ event, link, actions, execute }) => {
setMenuState({ x: event.clientX, y: event.clientY, link, actions, execute });
setMenuState({ x: event.clientX, y: event.clientY, link, actions, prepare: execute });
},
};
@@ -109,7 +109,7 @@ export function useActionLinks(
setTooltipState(null);
setMenuState(null);
};
}, [terminal, enabled, executeCommandRef]);
}, [terminal, enabled, prepareCommandRef]);
// Sync matchers and enabled state when settings change
useEffect(() => {
+1 -1
View File
@@ -22,7 +22,7 @@ function defaultTooltip(ctx: ActionContext, defaultAction?: ActionDefinition): s
const lines = [
`Type: ${ctx.kind}`,
`Value: ${ctx.value}`,
`Ctrl/Cmd + Click to execute default action`,
`Ctrl/Cmd + Click to prepare default command`,
`Alt + Click to view more actions`,
];