fix: restore ArrowUp caret movement and clean up virtual list lints

ArrowUp in chat input now moves caret instead of recalling history when the field has text
Removed manual cache-busting workaround and eslint-disable in favor of idiomatic onChange state sync
This commit is contained in:
Bohdan Triapitsyn
2026-06-12 23:40:08 +03:00
parent 563a4cf9b7
commit 1235e4db71
2 changed files with 13 additions and 9 deletions
@@ -2335,12 +2335,11 @@ const ChatInputComponent: React.FC<ChatInputProps> = ({ onOpenSettings, scrollTo
}
// Handle ArrowUp/ArrowDown for message history navigation
// ArrowUp: only when cursor at start (position 0) or input is empty
// ArrowUp: only when input is empty (so pressing Up at start of text just moves cursor)
// ArrowDown: also works when cursor at end (to cycle forward through history)
const isAnyAutocompleteOpen = showCommandAutocomplete || showSkillAutocomplete || showSnippetAutocomplete || showFileMention;
const cursorAtStart = textareaRef.current?.selectionStart === 0 && textareaRef.current?.selectionEnd === 0;
const cursorAtEnd = textareaRef.current?.selectionStart === message.length && textareaRef.current?.selectionEnd === message.length;
const canNavigateHistoryUp = !isAnyAutocompleteOpen && (message.length === 0 || cursorAtStart);
const canNavigateHistoryUp = !isAnyAutocompleteOpen && message.length === 0;
const canNavigateHistoryDown = !isAnyAutocompleteOpen && (message.length === 0 || cursorAtEnd);
// Markdown-aware auto-pairing (source mode), normal input only.
@@ -1372,7 +1372,7 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
scrollEl.scrollTop += prependedHeight;
});
const [virtualVersion, bumpVirtualVersion] = React.useReducer((v: number) => v + 1, 0);
const [historyVirtualRows, setHistoryVirtualRows] = React.useState<VirtualItem[]>(EMPTY_VIRTUAL_ROWS);
const historyVirtualizer = useVirtualizer({
count: historyEntries.length,
@@ -1383,7 +1383,9 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
useAnimationFrameWithResizeObserver: true,
overscan: MESSAGE_LIST_OVERSCAN,
enabled: shouldVirtualizeHistory,
onChange: bumpVirtualVersion,
onChange: () => {
setHistoryVirtualRows(historyVirtualizer.getVirtualItems());
},
});
React.useLayoutEffect(() => {
@@ -1438,10 +1440,13 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
};
}, []);
const historyVirtualRows = React.useMemo(
() => (shouldVirtualizeHistory ? historyVirtualizer.getVirtualItems() : EMPTY_VIRTUAL_ROWS),
[historyVirtualizer, shouldVirtualizeHistory, virtualVersion],
);
// Sync virtual rows on initial mount and when virtualization toggles.
// Ongoing updates are handled by the virtualizer's onChange callback.
React.useLayoutEffect(() => {
setHistoryVirtualRows(
shouldVirtualizeHistory ? historyVirtualizer.getVirtualItems() : EMPTY_VIRTUAL_ROWS,
);
}, [shouldVirtualizeHistory, historyVirtualizer]);
const allEntries = React.useMemo(() => {
return trailingStreamingEntry ? [...historyEntries, trailingStreamingEntry] : historyEntries;