diff --git a/pkg/interface/src/views/components/VirtualScroller.tsx b/pkg/interface/src/views/components/VirtualScroller.tsx index c253a8b81..92a85cb8e 100644 --- a/pkg/interface/src/views/components/VirtualScroller.tsx +++ b/pkg/interface/src/views/components/VirtualScroller.tsx @@ -58,6 +58,7 @@ export default class VirtualScroller extends PureComponent { + return new Map([ + ['ArrowUp', this.state.averageHeight], + ['ArrowDown', this.state.averageHeight * -1], + ['PageUp', this.window.offsetHeight], + ['PageDown', this.window.offsetHeight * -1], + ['Home', this.window.scrollHeight], + ['End', this.window.scrollHeight * -1], + ['Space', this.window.offsetHeight * -1] + ]); + } + invertedKeyHandler(event): void | false { - if (event.code === 'ArrowUp' || event.code === 'ArrowDown') { + const map = this.scrollKeyMap(); + if (map.has(event.code) && document.body.isSameNode(document.activeElement)) { event.preventDefault(); event.stopImmediatePropagation(); - if (event.code === 'ArrowUp') { - this.window.scrollBy(0, 30); - } else if (event.code === 'ArrowDown') { - this.window.scrollBy(0, -30); + let distance = map.get(event.code); + if (event.code === 'Space' && event.shiftKey) { + distance = distance * -1; } + this.window.scrollBy(0, distance); return false; } } componentWillUnmount() { - window.removeEventListener('keydown', this.invertedKeyHandler, true); + window.removeEventListener('keydown', this.invertedKeyHandler); } setWindow(element) { - if (this.window) return; + if (!element) return; + if (this.window) { + if (this.window.isSameNode(element)) { + return; + } else { + window.removeEventListener('keydown', this.invertedKeyHandler); + } + } + this.window = element; if (this.props.origin === 'bottom') { element.addEventListener('wheel', (event) => {