diff --git a/packages/excalidraw/components/HintViewer.tsx b/packages/excalidraw/components/HintViewer.tsx index 7ca24d58ce..55db2f8736 100644 --- a/packages/excalidraw/components/HintViewer.tsx +++ b/packages/excalidraw/components/HintViewer.tsx @@ -174,17 +174,30 @@ const getHints = ({ }); } - if (selectedElements.length === 1 && isTextElement(selectedElements[0])) { - return t("hints.text_selected", { - shortcut: getTaggedShortcutKey("Enter"), - }); - } + const toggleTextAutoResize = t("hints.toggleTextAutoResize", { + shortcut: getTaggedShortcutKey(["Alt", "W"]), + }); + // (before the selected text: one just created is selected while edited) if (appState.editingTextElement) { - return t("hints.text_editing", { + const finishEditing = t("hints.text_editing", { shortcut_1: getTaggedShortcutKey("Escape"), shortcut_2: getTaggedShortcutKey(["CtrlOrCmd", "Enter"]), }); + // (a label follows its container) + return appState.editingTextElement.containerId + ? finishEditing + : [finishEditing, toggleTextAutoResize]; + } + + if (selectedElements.length === 1 && isTextElement(selectedElements[0])) { + const editText = t("hints.text_selected", { + shortcut: getTaggedShortcutKey("Enter"), + }); + // a wrapped text: its handle unwraps it too, but only on desktop + return selectedElements[0].autoResize + ? editText + : [editText, toggleTextAutoResize]; } if (appState.croppingElementId) { diff --git a/packages/excalidraw/locales/en.json b/packages/excalidraw/locales/en.json index 5a1a9aa8c0..c1764d37ef 100644 --- a/packages/excalidraw/locales/en.json +++ b/packages/excalidraw/locales/en.json @@ -396,6 +396,7 @@ "autoshape": "Draw rectangles, circles, diamonds, lines and arrows", "text_selected": "Double-click or press {{shortcut}} to edit text", "text_editing": "Press {{shortcut_1}} or {{shortcut_2}} to finish editing", + "toggleTextAutoResize": "{{shortcut}} to toggle text auto-resize", "linearElementMulti": "Click on last point or press {{shortcut_1}} or {{shortcut_2}} to finish", "lockAngle": "You can constrain angle by holding {{shortcut}}", "resize": "You can constrain proportions by holding {{shortcut_1}} while resizing,\nhold {{shortcut_2}} to resize from the center", diff --git a/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx b/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx index 75820fe9f6..97f84a8d25 100644 --- a/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx +++ b/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx @@ -3684,6 +3684,27 @@ describe("textWysiwyg", () => { }, ); + it("hints at Alt+W for a selected wrapped text, and while editing a text", async () => { + const hint = () => + h.app.ownerDocument.querySelector(".HintViewer")?.textContent ?? ""; + const toggleHint = "to toggle text auto-resize"; + + API.setElements([wrappedText()]); + API.setAppState({ selectedElementIds: { text: true } }); + await waitFor(() => expect(hint()).toContain(toggleHint)); + + // not for a text that doesn't wrap... + API.executeAction(actionTextAutoResize); + await waitFor(() => expect(hint()).toContain("to edit text")); + expect(hint()).not.toContain(toggleHint); + + // ...until it's edited + mouse.doubleClickAt(110, 110); + await getTextEditor(); + await waitFor(() => expect(hint()).toContain("to finish editing")); + expect(hint()).toContain(toggleHint); + }); + it("toggles auto-resizing of the text being edited with Alt+W", async () => { API.setElements([wrappedText()]); mouse.doubleClickAt(110, 110);