fix(editor): keep the text auto-resize toggle on the box while typing

The toggle was positioned from `appState.editingTextElement`, the element
as it was when editing started, so it stayed put as lines were added or
removed. Resolve the current element instead, for the hit test too.
This commit is contained in:
dwelle committed 2026-11-14 22:58:55 +01:00
1 parent 3a317b55f5
commit 20b9f91fc6
3 files changed
+19 -2

No files matched your search

+12 -1
View File
@@ -20,6 +20,7 @@ import { isNonDeletedElement } from ".";
import type {
ElementsMap,
ElementsMapOrArray,
ExcalidrawTextElement,
ExcalidrawElement,
ExcalidrawFrameLikeElement,
NonDeleted,
@@ -247,9 +248,19 @@ export const makeNextSelectedElementIds = (
export const getActiveTextElement = (
selectedElements: readonly NonDeleted<ExcalidrawElement>[],
appState: Pick<AppState, "editingTextElement">,
elementsMap: ElementsMap,
) => {
// `editingTextElement` is the element as it was when editing started, so
// resolve the current one (typing changes its dimensions and position)
const editingTextElement =
appState.editingTextElement &&
((elementsMap.get(appState.editingTextElement.id) as
| ExcalidrawTextElement
| undefined) ||
appState.editingTextElement);
const activeTextElement =
appState.editingTextElement ||
editingTextElement ||
(selectedElements.length === 1 &&
isTextElement(selectedElements[0]) &&
selectedElements[0]);
@@ -477,6 +477,7 @@ export class AppText {
const activeTextElement = getActiveTextElement(
selectedElements,
this.app.state,
this.app.scene.getNonDeletedElementsMap(),
);
if (
@@ -503,6 +504,7 @@ export class AppText {
const activeTextElement = getActiveTextElement(
selectedElements,
this.app.state,
this.app.scene.getNonDeletedElementsMap(),
);
if (
!activeTextElement ||
@@ -1693,7 +1693,11 @@ const _renderInteractiveScene = ({
}
}
const activeTextElement = getActiveTextElement(selectedElements, appState);
const activeTextElement = getActiveTextElement(
selectedElements,
appState,
allElementsMap,
);
if (activeTextElement && !activeTextElement.autoResize) {
renderResetAutoResizeHandle(