You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
import Embed from '../blots/embed.js'; |
|
import Emitter from './emitter.js'; |
|
class Composition { |
|
isComposing = false; |
|
constructor(scroll, emitter) { |
|
this.scroll = scroll; |
|
this.emitter = emitter; |
|
this.setupListeners(); |
|
} |
|
setupListeners() { |
|
this.scroll.domNode.addEventListener('compositionstart', event => { |
|
if (!this.isComposing) { |
|
this.handleCompositionStart(event); |
|
} |
|
}); |
|
this.scroll.domNode.addEventListener('compositionend', event => { |
|
if (this.isComposing) { |
|
// Webkit makes DOM changes after compositionend, so we use microtask to |
|
// ensure the order. |
|
// https://bugs.webkit.org/show_bug.cgi?id=31902 |
|
queueMicrotask(() => { |
|
this.handleCompositionEnd(event); |
|
}); |
|
} |
|
}); |
|
} |
|
handleCompositionStart(event) { |
|
const blot = event.target instanceof Node ? this.scroll.find(event.target, true) : null; |
|
if (blot && !(blot instanceof Embed)) { |
|
this.emitter.emit(Emitter.events.COMPOSITION_BEFORE_START, event); |
|
this.scroll.batchStart(); |
|
this.emitter.emit(Emitter.events.COMPOSITION_START, event); |
|
this.isComposing = true; |
|
} |
|
} |
|
handleCompositionEnd(event) { |
|
this.emitter.emit(Emitter.events.COMPOSITION_BEFORE_END, event); |
|
this.scroll.batchEnd(); |
|
this.emitter.emit(Emitter.events.COMPOSITION_END, event); |
|
this.isComposing = false; |
|
} |
|
} |
|
export default Composition; |
|
//# sourceMappingURL=composition.js.map
|