Skip to content

Commit c56c481

Browse files
committed
keep scroll related key events in scrollable region
1 parent 67de6c1 commit c56c481

File tree

1 file changed

+12
-0
lines changed
  • extensions/notebook-renderers/src

1 file changed

+12
-0
lines changed

extensions/notebook-renderers/src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,25 @@ function onScrollHandler(e: globalThis.Event) {
198198
}
199199
}
200200

201+
function onKeypressHandler(e: KeyboardEvent) {
202+
if (e.ctrlKey || e.shiftKey) {
203+
return;
204+
}
205+
if (e.code === 'ArrowDown' || e.code === 'End' || e.code === 'ArrowUp' || e.code === 'Home') {
206+
// These should change the scroll position, not adjust the selected cell in the notebook
207+
e.stopPropagation();
208+
}
209+
}
210+
201211
// if there is a scrollable output, it will be scrolled to the given value if provided or the bottom of the element
202212
function initializeScroll(scrollableElement: HTMLElement, disposables: DisposableStore, scrollTop?: number) {
203213
if (scrollableElement.classList.contains(scrollableClass)) {
204214
scrollableElement.classList.toggle('scrollbar-visible', scrollableElement.scrollHeight > scrollableElement.clientHeight);
205215
scrollableElement.scrollTop = scrollTop !== undefined ? scrollTop : scrollableElement.scrollHeight;
206216
scrollableElement.addEventListener('scroll', onScrollHandler);
207217
disposables.push({ dispose: () => scrollableElement.removeEventListener('scroll', onScrollHandler) });
218+
scrollableElement.addEventListener('keydown', onKeypressHandler);
219+
disposables.push({ dispose: () => scrollableElement.removeEventListener('keydown', onKeypressHandler) });
208220
}
209221
}
210222

0 commit comments

Comments
 (0)