Files
NapCatQQ/.pnpm-store/v3/files/35/82a6161b989a1e1499b9276ac2e5dfd96b391cd3a7b90ff857bd5a67ae4cf4ba2b6e86b65163b233c4a8b53017533d9fcace925b731034c71739b8fc0c18a8
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

44 lines
1.4 KiB
Plaintext

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