keep scroll related key events in scrollable region

This commit is contained in:
aamunger 2023-04-24 09:01:08 -07:00
parent 67de6c1d53
commit c56c481890
No known key found for this signature in database
GPG key ID: F2CA0C6303FC6B74

View file

@ -198,6 +198,16 @@ function onScrollHandler(e: globalThis.Event) {
}
}
function onKeypressHandler(e: KeyboardEvent) {
if (e.ctrlKey || e.shiftKey) {
return;
}
if (e.code === 'ArrowDown' || e.code === 'End' || e.code === 'ArrowUp' || e.code === 'Home') {
// These should change the scroll position, not adjust the selected cell in the notebook
e.stopPropagation();
}
}
// if there is a scrollable output, it will be scrolled to the given value if provided or the bottom of the element
function initializeScroll(scrollableElement: HTMLElement, disposables: DisposableStore, scrollTop?: number) {
if (scrollableElement.classList.contains(scrollableClass)) {
@ -205,6 +215,8 @@ function initializeScroll(scrollableElement: HTMLElement, disposables: Disposabl
scrollableElement.scrollTop = scrollTop !== undefined ? scrollTop : scrollableElement.scrollHeight;
scrollableElement.addEventListener('scroll', onScrollHandler);
disposables.push({ dispose: () => scrollableElement.removeEventListener('scroll', onScrollHandler) });
scrollableElement.addEventListener('keydown', onKeypressHandler);
disposables.push({ dispose: () => scrollableElement.removeEventListener('keydown', onKeypressHandler) });
}
}