Skip to content

Commit 2fcc04b

Browse files
authored
fix(chat): phantom scrolling when typing in mention menu (#8127)
https://www.youtube.com/watch?v=V-PnNRUo5Jo ## Test plan - Use the mention menu and notice that we no longer get a fake scroll down as we type
1 parent b6bc63a commit 2fcc04b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

vscode/webviews/chat/Transcript.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ interface TranscriptProps {
7676
welcomeContent?: React.ReactNode
7777
}
7878

79+
function useDebouncedBoolean(value: boolean, delay: number): boolean {
80+
const [debouncedValue, setDebouncedValue] = useState(value)
81+
82+
useEffect(() => {
83+
const handler = setTimeout(() => {
84+
setDebouncedValue(value)
85+
}, delay)
86+
87+
return () => {
88+
clearTimeout(handler)
89+
}
90+
}, [value, delay])
91+
92+
return debouncedValue
93+
}
94+
7995
export const Transcript: FC<TranscriptProps> = props => {
8096
const {
8197
activeChatContext,
@@ -105,6 +121,10 @@ export const Transcript: FC<TranscriptProps> = props => {
105121
const [scrollableContainer, setScrollableContainer] = useState<HTMLDivElement | null>(null)
106122
const [isAtBottom, setIsAtBottom] = useState(false)
107123

124+
// Debounce the isAtBottom state to prevent flickering of the "Skip to end" button
125+
// when the mention menu appears and causes micro-scrolls
126+
const isAtBottomDebounced = useDebouncedBoolean(isAtBottom, 150)
127+
108128
useEffect(() => {
109129
const handleCopyEvent = (event: ClipboardEvent) => {
110130
const selectedText = window.getSelection()?.toString() || ''
@@ -266,7 +286,7 @@ export const Transcript: FC<TranscriptProps> = props => {
266286

267287
{scrollableContainer && <ScrollbarMarkers scrollContainer={scrollableContainer} />}
268288

269-
{!isAtBottom && <ScrollDown onClick={scrollTotheBottom} />}
289+
{!isAtBottomDebounced && <ScrollDown onClick={scrollTotheBottom} />}
270290

271291
<div className="tw-bg-[var(--vscode-input-background)]">
272292
{inputInteractionAtTheBottom &&

0 commit comments

Comments
 (0)