-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
456 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Embed from '../blots/embed'; | ||
import Scroll from '../blots/scroll'; | ||
import Emitter from './emitter'; | ||
|
||
class Composition { | ||
isComposing = false; | ||
|
||
constructor(private scroll: Scroll, private emitter: Emitter) { | ||
scroll.domNode.addEventListener('compositionstart', event => { | ||
if (!this.isComposing) { | ||
this.handleCompositionStart(event); | ||
} | ||
}); | ||
|
||
scroll.domNode.addEventListener('compositionend', event => { | ||
if (this.isComposing) { | ||
this.handleCompositionEnd(event); | ||
} | ||
}); | ||
} | ||
|
||
private handleCompositionStart(event: CompositionEvent) { | ||
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; | ||
} | ||
} | ||
|
||
private handleCompositionEnd(event: CompositionEvent) { | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.