Skip to content

Commit

Permalink
Delay dispatch of DOM events during view updates
Browse files Browse the repository at this point in the history
FIX: Make sure event handlers registered with `domEventHandlers` are not called
during view updates, to avoid triggering nested update errors.

Closes codemirror/dev#1507
  • Loading branch information
marijnh committed Jan 17, 2025
1 parent b20446d commit 22860a1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/input.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {EditorSelection, EditorState, SelectionRange, RangeSet, Annotation, Text, Facet} from "@codemirror/state"
import {EditorView} from "./editorview"
import {EditorView, UpdateState} from "./editorview"
import {ContentView} from "./contentview"
import {LineView} from "./blockview"
import {ViewUpdate, PluginValue, clickAddsSelectionRange, dragMovesSelection as dragBehavior, atomicRanges,
Expand Down Expand Up @@ -84,7 +84,8 @@ export class InputState {
handleEvent(event: Event) {
if (!eventBelongsToEditor(this.view, event) || this.ignoreDuringComposition(event)) return
if (event.type == "keydown" && this.keydown(event as KeyboardEvent)) return
this.runHandlers(event.type, event)
if (this.view.updateState != UpdateState.Idle) Promise.resolve().then(() => this.runHandlers(event.type, event))
else this.runHandlers(event.type, event)
}

runHandlers(type: string, event: Event) {
Expand Down

0 comments on commit 22860a1

Please sign in to comment.