sync intermediate text updates (#1174)

* sync intermediate text updates

* fix initial render text position

* batch updates

* tweak onChange subscription
This commit is contained in:
David Luzar 2020-04-03 14:16:14 +02:00 committed by GitHub
parent 0c9459e9e5
commit 4912a29e75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 168 additions and 120 deletions

View file

@ -21,6 +21,7 @@ type TextWysiwygParams = {
opacity: number;
zoom: number;
angle: number;
onChange?: (text: string) => void;
onSubmit: (text: string) => void;
onCancel: () => void;
};
@ -34,6 +35,7 @@ export function textWysiwyg({
opacity,
zoom,
angle,
onChange,
onSubmit,
onCancel,
}: TextWysiwygParams) {
@ -96,6 +98,12 @@ export function textWysiwyg({
}
};
if (onChange) {
editable.oninput = () => {
onChange(trimText(editable.innerText));
};
}
editable.onkeydown = (ev) => {
if (ev.key === KEYS.ESCAPE) {
ev.preventDefault();
@ -121,9 +129,6 @@ export function textWysiwyg({
}
function cleanup() {
editable.onblur = null;
editable.onkeydown = null;
editable.onpaste = null;
window.removeEventListener("wheel", stopEvent, true);
document.body.removeChild(editable);
}