Skip to content

Commit

Permalink
Refactor composition to allow overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jun 30, 2023
1 parent 87f7f41 commit 2f97984
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ class Composition {
isComposing = false;

constructor(private scroll: Scroll, private emitter: Emitter) {
scroll.domNode.addEventListener('compositionstart', event => {
this.setupListeners();
}

private setupListeners() {
this.scroll.domNode.addEventListener('compositionstart', event => {
if (!this.isComposing) {
this.handleCompositionStart(event);
}
});

scroll.domNode.addEventListener('compositionend', event => {
this.scroll.domNode.addEventListener('compositionend', event => {
if (this.isComposing) {
this.handleCompositionEnd(event);
}
Expand Down
1 change: 1 addition & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import './unit/blots/inline';

import './unit/core/editor';
import './unit/core/selection';
import './unit/core/composition';
import './unit/core/quill';

import './unit/formats/color';
Expand Down
17 changes: 17 additions & 0 deletions test/unit/core/composition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Emitter from '../../../core/emitter';
import Composition from '../../../core/composition';
import Scroll from '../../../blots/scroll';

describe('Selection', function () {
it('triggers events on compositionstart', function (done) {
const scroll = this.initialize(Scroll, '<p></p>');
const emitter = new Emitter();
new Composition(scroll, emitter);

emitter.on(Emitter.events.COMPOSITION_BEFORE_START, () => {
done();
});

scroll.domNode.dispatchEvent(new CompositionEvent('compositionstart'));
});
});

0 comments on commit 2f97984

Please sign in to comment.