Skip to content

Commit de997c6

Browse files
committed
feat: enhance cursor handling in PromptInput component to fix IME composition anchoring
1 parent 2e9dfbc commit de997c6

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/ui/views/PromptInput.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ import { readClipboardImageAsync } from "../core/clipboard";
4646
import { useTerminalInput, usePasteHandling, useHistoryNavigation } from "../hooks";
4747
import type { InputKey } from "../hooks";
4848
import {
49+
getPromptCursorPlacement,
4950
useHiddenTerminalCursor,
5051
useTerminalExtendedKeys,
5152
useBracketedPaste,
53+
usePromptTerminalCursor,
5254
useTerminalFocusReporting,
5355
} from "../hooks";
5456
import SlashCommandMenu, { isSkillSelected } from "./SlashCommandMenu";
@@ -198,10 +200,20 @@ export const PromptInput = React.memo(function PromptInput({
198200
? `${loadingText}${processOrPasteHint}`
199201
: `esc to interrupt · ctrl+c to cancel input${processOrPasteHint}`
200202
: `enter send · shift+enter newline · @ files · ctrl+v image · / commands · ctrl+d exit${processOrPasteHint}`;
203+
const showFooterText = useMemo(
204+
() => showMenu || showSkillsDropdown || openRawModelDropdown || showModelDropdown || showFileMentionMenu,
205+
[showMenu, showSkillsDropdown, showModelDropdown, openRawModelDropdown, showFileMentionMenu]
206+
);
207+
const cursorPlacement = useMemo(
208+
() => getPromptCursorPlacement(buffer, screenWidth, 2, footerText),
209+
[buffer, footerText, screenWidth]
210+
);
211+
const usePositionedCursor = !disabled && hasTerminalFocus && !showFooterText;
201212
useTerminalFocusReporting(stdout, !disabled);
202213
useTerminalExtendedKeys(stdout, !disabled);
203214
useBracketedPaste(stdout, !disabled);
204-
useHiddenTerminalCursor(stdout, !disabled);
215+
usePromptTerminalCursor(stdout, cursorPlacement, usePositionedCursor);
216+
useHiddenTerminalCursor(stdout, !disabled && !usePositionedCursor);
205217

206218
const refreshFileMentionItems = React.useCallback(() => {
207219
setFileMentionItems(scanFileMentionItems(projectRoot));
@@ -714,11 +726,6 @@ export const PromptInput = React.memo(function PromptInput({
714726
clearUndoRedoStacks();
715727
}
716728

717-
const showFooterText = useMemo(
718-
() => showMenu || showSkillsDropdown || openRawModelDropdown || showModelDropdown || showFileMentionMenu,
719-
[showMenu, showSkillsDropdown, showModelDropdown, openRawModelDropdown, showFileMentionMenu]
720-
);
721-
722729
const matchedCommand = slashToken ? findExactSlashCommand(slashItems, slashToken) : null;
723730
const inlineHint = matchedCommand?.args ? ` ${matchedCommand.args.join(ARGS_SEPARATOR)}` : "";
724731

0 commit comments

Comments
 (0)