From 3439da164d1b36b00d540181cf43b6eef98d3aef Mon Sep 17 00:00:00 2001 From: dwelle Date: Thu, 27 May 2021 18:30:33 +0200 Subject: [PATCH] fix: manually confirm active wysiwyg on pointerdown --- src/components/App.tsx | 11 ++++++++++- src/element/textWysiwyg.test.tsx | 2 +- src/element/textWysiwyg.tsx | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 6641f4c97..9e0db23a2 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -322,6 +322,8 @@ class App extends React.Component { private id: string; private history: History; + private activeWysiwyg: null | { handleSubmit: () => void } = null; + constructor(props: AppProps) { super(props); const defaultAppState = getDefaultAppState(); @@ -1763,7 +1765,7 @@ class App extends React.Component { ]); }; - textWysiwyg({ + const { handleSubmit } = textWysiwyg({ id: element.id, appState: this.state, canvas: this.canvas, @@ -1787,6 +1789,7 @@ class App extends React.Component { } }), onSubmit: withBatchedUpdates(({ text, viaKeyboard }) => { + this.activeWysiwyg = null; const isDeleted = !text.trim(); updateElement(text, isDeleted); // select the created text element only if submitting via keyboard @@ -1828,6 +1831,8 @@ class App extends React.Component { // do an initial update to re-initialize element position since we were // modifying element's x/y for sake of editor (case: syncing to remote) updateElement(element.text); + + this.activeWysiwyg = { handleSubmit }; } private getTextElementAtPosition( @@ -2285,6 +2290,10 @@ class App extends React.Component { ) => { event.persist(); + if (this.activeWysiwyg) { + this.activeWysiwyg.handleSubmit(); + } + // remove any active selection when we start to interact with canvas // (mainly, we care about removing selection outside the component which // would prevent our copy handling otherwise) diff --git a/src/element/textWysiwyg.test.tsx b/src/element/textWysiwyg.test.tsx index f98cb8a5e..9781c0cfa 100644 --- a/src/element/textWysiwyg.test.tsx +++ b/src/element/textWysiwyg.test.tsx @@ -16,7 +16,7 @@ describe("textWysiwyg", () => { const element = UI.createElement("text"); - new Pointer("mouse").clickOn(element); + new Pointer("mouse").doubleClickOn(element); textarea = document.querySelector( ".excalidraw-textEditorContainer > textarea", )!; diff --git a/src/element/textWysiwyg.tsx b/src/element/textWysiwyg.tsx index 6eee0d386..46afa1faf 100644 --- a/src/element/textWysiwyg.tsx +++ b/src/element/textWysiwyg.tsx @@ -368,4 +368,6 @@ export const textWysiwyg = ({ excalidrawContainer ?.querySelector(".excalidraw-textEditorContainer")! .appendChild(editable); + + return { handleSubmit }; };