Skip to content

Commit 2e902f0

Browse files
committed
only listen for scroll events when scrolling is possible
1 parent 327be7f commit 2e902f0

File tree

1 file changed

+8
-5
lines changed
  • extensions/notebook-renderers/src

1 file changed

+8
-5
lines changed

extensions/notebook-renderers/src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,15 @@ function onKeypressHandler(e: KeyboardEvent) {
211211
// if there is a scrollable output, it will be scrolled to the given value if provided or the bottom of the element
212212
function initializeScroll(scrollableElement: HTMLElement, disposables: DisposableStore, scrollTop?: number) {
213213
if (scrollableElement.classList.contains(scrollableClass)) {
214-
scrollableElement.classList.toggle('scrollbar-visible', scrollableElement.scrollHeight > scrollableElement.clientHeight);
214+
const scrollbarVisible = scrollableElement.scrollHeight > scrollableElement.clientHeight;
215+
scrollableElement.classList.toggle('scrollbar-visible', scrollbarVisible);
215216
scrollableElement.scrollTop = scrollTop !== undefined ? scrollTop : scrollableElement.scrollHeight;
216-
scrollableElement.addEventListener('scroll', onScrollHandler);
217-
disposables.push({ dispose: () => scrollableElement.removeEventListener('scroll', onScrollHandler) });
218-
scrollableElement.addEventListener('keydown', onKeypressHandler);
219-
disposables.push({ dispose: () => scrollableElement.removeEventListener('keydown', onKeypressHandler) });
217+
if (scrollbarVisible) {
218+
scrollableElement.addEventListener('scroll', onScrollHandler);
219+
disposables.push({ dispose: () => scrollableElement.removeEventListener('scroll', onScrollHandler) });
220+
scrollableElement.addEventListener('keydown', onKeypressHandler);
221+
disposables.push({ dispose: () => scrollableElement.removeEventListener('keydown', onKeypressHandler) });
222+
}
220223
}
221224
}
222225

0 commit comments

Comments
 (0)