瀏覽代碼

fix: manually confirm active wysiwyg on pointerdown

dwelle 4 年之前
父節點
當前提交
3439da164d
共有 3 個文件被更改,包括 13 次插入2 次删除
  1. 10 1
      src/components/App.tsx
  2. 1 1
      src/element/textWysiwyg.test.tsx
  3. 2 0
      src/element/textWysiwyg.tsx

+ 10 - 1
src/components/App.tsx

@@ -322,6 +322,8 @@ class App extends React.Component<AppProps, AppState> {
   private id: string;
   private id: string;
   private history: History;
   private history: History;
 
 
+  private activeWysiwyg: null | { handleSubmit: () => void } = null;
+
   constructor(props: AppProps) {
   constructor(props: AppProps) {
     super(props);
     super(props);
     const defaultAppState = getDefaultAppState();
     const defaultAppState = getDefaultAppState();
@@ -1763,7 +1765,7 @@ class App extends React.Component<AppProps, AppState> {
       ]);
       ]);
     };
     };
 
 
-    textWysiwyg({
+    const { handleSubmit } = textWysiwyg({
       id: element.id,
       id: element.id,
       appState: this.state,
       appState: this.state,
       canvas: this.canvas,
       canvas: this.canvas,
@@ -1787,6 +1789,7 @@ class App extends React.Component<AppProps, AppState> {
         }
         }
       }),
       }),
       onSubmit: withBatchedUpdates(({ text, viaKeyboard }) => {
       onSubmit: withBatchedUpdates(({ text, viaKeyboard }) => {
+        this.activeWysiwyg = null;
         const isDeleted = !text.trim();
         const isDeleted = !text.trim();
         updateElement(text, isDeleted);
         updateElement(text, isDeleted);
         // select the created text element only if submitting via keyboard
         // select the created text element only if submitting via keyboard
@@ -1828,6 +1831,8 @@ class App extends React.Component<AppProps, AppState> {
     // do an initial update to re-initialize element position since we were
     // 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)
     // modifying element's x/y for sake of editor (case: syncing to remote)
     updateElement(element.text);
     updateElement(element.text);
+
+    this.activeWysiwyg = { handleSubmit };
   }
   }
 
 
   private getTextElementAtPosition(
   private getTextElementAtPosition(
@@ -2285,6 +2290,10 @@ class App extends React.Component<AppProps, AppState> {
   ) => {
   ) => {
     event.persist();
     event.persist();
 
 
+    if (this.activeWysiwyg) {
+      this.activeWysiwyg.handleSubmit();
+    }
+
     // remove any active selection when we start to interact with canvas
     // remove any active selection when we start to interact with canvas
     // (mainly, we care about removing selection outside the component which
     // (mainly, we care about removing selection outside the component which
     //  would prevent our copy handling otherwise)
     //  would prevent our copy handling otherwise)

+ 1 - 1
src/element/textWysiwyg.test.tsx

@@ -16,7 +16,7 @@ describe("textWysiwyg", () => {
 
 
     const element = UI.createElement("text");
     const element = UI.createElement("text");
 
 
-    new Pointer("mouse").clickOn(element);
+    new Pointer("mouse").doubleClickOn(element);
     textarea = document.querySelector(
     textarea = document.querySelector(
       ".excalidraw-textEditorContainer > textarea",
       ".excalidraw-textEditorContainer > textarea",
     )!;
     )!;

+ 2 - 0
src/element/textWysiwyg.tsx

@@ -368,4 +368,6 @@ export const textWysiwyg = ({
   excalidrawContainer
   excalidrawContainer
     ?.querySelector(".excalidraw-textEditorContainer")!
     ?.querySelector(".excalidraw-textEditorContainer")!
     .appendChild(editable);
     .appendChild(editable);
+
+  return { handleSubmit };
 };
 };