mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-12-03 01:59:25 +03:00
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:
3 files changed
+19
-2
No files matched your search
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user