mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
sync intermediate text updates (#1174)
* sync intermediate text updates * fix initial render text position * batch updates * tweak onChange subscription
This commit is contained in:
parent
0c9459e9e5
commit
4912a29e75
4 changed files with 168 additions and 120 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue