Skip to content

Commit e9e5ee1

Browse files
Copilotalexr00
andcommitted
Fix flickering at threshold with hysteresis
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent a88fb0b commit e9e5ee1

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/@types/vscode.proposed.chatSessionsProvider.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ declare module 'vscode' {
9595
*/
9696
description?: string | MarkdownString;
9797

98+
/**
99+
* An optional badge that provides additional context about the chat session.
100+
*/
101+
badge?: string | MarkdownString;
102+
98103
/**
99104
* An optional status indicating the current state of the session.
100105
*/

webviews/editorWebview/overview.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const useMediaQuery = (query: string) => {
3030
};
3131

3232
const STICKY_THRESHOLD = 80;
33+
const STICKY_THRESHOLD_BUFFER = 10;
3334

3435
export const Overview = (pr: PullRequest) => {
3536
const isSingleColumnLayout = useMediaQuery('(max-width: 768px)');
@@ -41,8 +42,15 @@ export const Overview = (pr: PullRequest) => {
4142
const handleScroll = () => {
4243
if (!ticking) {
4344
window.requestAnimationFrame(() => {
44-
const scrolled = window.scrollY > STICKY_THRESHOLD;
45-
setIsSticky(scrolled);
45+
const scrollY = window.scrollY;
46+
// Use hysteresis to prevent flickering at the threshold
47+
// When not sticky, activate when scrollY > threshold
48+
// When sticky, deactivate when scrollY < (threshold - buffer)
49+
if (!isSticky && scrollY > STICKY_THRESHOLD) {
50+
setIsSticky(true);
51+
} else if (isSticky && scrollY < STICKY_THRESHOLD - STICKY_THRESHOLD_BUFFER) {
52+
setIsSticky(false);
53+
}
4654
ticking = false;
4755
});
4856
ticking = true;
@@ -51,7 +59,7 @@ export const Overview = (pr: PullRequest) => {
5159

5260
window.addEventListener('scroll', handleScroll, { passive: true });
5361
return () => window.removeEventListener('scroll', handleScroll);
54-
}, []);
62+
}, [isSticky]);
5563

5664
return <>
5765
<div id="title" className={`title ${isSticky ? 'sticky' : ''}`}>

0 commit comments

Comments
 (0)