Skip to content

Commit

Permalink
Make sure clicks on the scroll element get routed to mouse handler
Browse files Browse the repository at this point in the history
FIX: Fix a regression where clicking below the content element in an editor with
its own height didn't focus the editor.
  • Loading branch information
marijnh committed Dec 8, 2022
1 parent 25ca9a6 commit 6db9fac
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/input.ts
Expand Up @@ -57,17 +57,23 @@ export class InputState {
}

constructor(view: EditorView) {
let handleEvent = (handler: (view: EditorView, event: Event) => void, event: Event) => {
if (this.ignoreDuringComposition(event)) return
if (event.type == "keydown" && this.keydown(view, event as KeyboardEvent)) return
if (this.mustFlushObserver(event)) view.observer.forceFlush()
if (this.runCustomHandlers(event.type, view, event)) event.preventDefault()
else handler(view, event)
}
for (let type in handlers) {
let handler = handlers[type]
view.contentDOM.addEventListener(type, (event: Event) => {
if (!eventBelongsToEditor(view, event) || this.ignoreDuringComposition(event)) return
if (type == "keydown" && this.keydown(view, event as KeyboardEvent)) return
if (this.mustFlushObserver(event)) view.observer.forceFlush()
if (this.runCustomHandlers(type, view, event)) event.preventDefault()
else handler(view, event)
view.contentDOM.addEventListener(type, event => {
if (eventBelongsToEditor(view, event)) handleEvent(handler, event)
}, handlerOptions[type])
this.registeredEvents.push(type)
}
view.scrollDOM.addEventListener("mousedown", (event: Event) => {
if (event.target == view.scrollDOM) handleEvent(handlers.mousedown, event)
})
if (browser.chrome && browser.chrome_version == 102) { // FIXME remove at some point
// On Chrome 102, viewport updates somehow stop wheel-based
// scrolling. Turning off pointer events during the scroll seems
Expand Down

0 comments on commit 6db9fac

Please sign in to comment.