Virtual whiteboard for sketching hand-drawn like diagrams
fix(editor): pan once and keep editing on a wheel-button drag over the text editor (#12244)
David Luzar2559257bb2bc
diff --git a/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx b/packages/excalidraw/wysiwyg/textWysiwyg.test.tsxindex c9a73bad79..76e8fc281b 100644--- a/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx+++ b/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx@@ -1332,6 +1332,38 @@ describe("textWysiwyg", () => {editorBox.scrollTop = 0;});+ it("should pan the canvas by a wheel-button drag on the editor and keep editing", async () => {+ // (the editor takes pointer downs from the next frame on)+ const nextFrame = () =>+ act(() => new Promise((resolve) => requestAnimationFrame(resolve)));+ await nextFrame();+ // in a later editing session, which the earlier ones don't pan too+ updateTextEditor(textarea, "Hello");+ Keyboard.exitTextEditor(textarea);+ Keyboard.keyPress(KEYS.ENTER);+ textarea = await getTextEditor();+ await nextFrame();+ const { scrollX, scrollY } = h.state;++ const pointer = {+ pointerId: 1,+ pointerType: "mouse",+ button: 1,+ buttons: 4,+ clientX: 100,+ clientY: 100,+ };+ fireEvent.pointerDown(textarea, pointer);+ const moved = { ...pointer, clientX: 140, clientY: 120 };+ fireEvent.pointerMove(window, moved);+ fireEvent.pointerUp(window, { ...moved, buttons: 0 });++ expect(h.state.scrollX).toBe(scrollX + 40);+ expect(h.state.scrollY).toBe(scrollY + 20);+ expect(h.state.editingTextElement?.id).toBe(textElement.id);+ await waitFor(() => expect(document.activeElement).toBe(textarea));+ });+it("should keep the editor's box off a docked sidebar", () => {const editorBox = textarea.parentElement!;const sidebar = dockSidebar(500, 300);diff --git a/packages/excalidraw/wysiwyg/textWysiwyg.tsx b/packages/excalidraw/wysiwyg/textWysiwyg.tsxindex 682864ab3e..c9a1db0cca 100644--- a/packages/excalidraw/wysiwyg/textWysiwyg.tsx+++ b/packages/excalidraw/wysiwyg/textWysiwyg.tsx@@ -1078,7 +1078,9 @@ export const textWysiwyg = ({ownerWindow.removeEventListener("resize", updateWysiwygStyle);ownerWindow.removeEventListener("wheel", stopEvent, true);- ownerWindow.removeEventListener("pointerdown", onPointerDown);+ ownerWindow.removeEventListener("pointerdown", onPointerDown, {+ capture: true,+ });ownerWindow.removeEventListener("pointerup", bindBlurEvent);ownerWindow.removeEventListener("blur", handleSubmit);ownerWindow.removeEventListener("beforeunload", handleSubmit);@@ -1150,13 +1152,13 @@ export const textWysiwyg = ({// panning canvasif (event.button === POINTER_BUTTON.WHEEL) {+ // before the pan starts: it focuses the container, blurring the editor+ temporarilyDisableSubmit();// trying to pan by clicking inside text area itself -> handle hereif (target instanceof ownerWindow.HTMLTextAreaElement) {event.preventDefault();app.pan.start(event);}-- temporarilyDisableSubmit();return;}