Browse Source

fix: show text properties button states correctly for bounded text

aakansha-font
ad1992 4 years ago
parent
commit
f41515b8bc
  1. 34
      src/actions/actionProperties.tsx
  2. 14
      src/element/textElement.ts

34
src/actions/actionProperties.tsx

@ -42,6 +42,7 @@ import { @@ -42,6 +42,7 @@ import {
redrawTextBoundingBox,
} from "../element";
import { newElementWith } from "../element/mutateElement";
import { getBoundedTextElement } from "../element/textElement";
import { isLinearElement, isLinearElementType } from "../element/typeChecks";
import {
Arrowhead,
@ -490,7 +491,16 @@ export const actionChangeFontSize = register({ @@ -490,7 +491,16 @@ export const actionChangeFontSize = register({
value={getFormValue(
elements,
appState,
(element) => isTextElement(element) && element.fontSize,
(element) => {
if (isTextElement(element)) {
return element.fontSize;
}
const boundedTextElement = getBoundedTextElement(element);
if (boundedTextElement) {
return boundedTextElement.fontSize;
}
return null;
},
appState.currentItemFontSize || DEFAULT_FONT_SIZE,
)}
onChange={(value) => updateData(value)}
@ -562,7 +572,16 @@ export const actionChangeFontFamily = register({ @@ -562,7 +572,16 @@ export const actionChangeFontFamily = register({
value={getFormValue(
elements,
appState,
(element) => isTextElement(element) && element.fontFamily,
(element) => {
if (isTextElement(element)) {
return element.fontFamily;
}
const boundedTextElement = getBoundedTextElement(element);
if (boundedTextElement) {
return boundedTextElement.fontFamily;
}
return null;
},
appState.currentItemFontFamily || DEFAULT_FONT_FAMILY,
)}
onChange={(value) => updateData(value)}
@ -628,7 +647,16 @@ export const actionChangeTextAlign = register({ @@ -628,7 +647,16 @@ export const actionChangeTextAlign = register({
value={getFormValue(
elements,
appState,
(element) => isTextElement(element) && element.textAlign,
(element) => {
if (isTextElement(element)) {
return element.textAlign;
}
const boundedTextElement = getBoundedTextElement(element);
if (boundedTextElement) {
return boundedTextElement.textAlign;
}
return null;
},
appState.currentItemTextAlign,
)}
onChange={(value) => updateData(value)}

14
src/element/textElement.ts

@ -3,6 +3,7 @@ import { @@ -3,6 +3,7 @@ import {
ExcalidrawBindableElement,
ExcalidrawElement,
ExcalidrawTextElement,
ExcalidrawTextElementWithContainer,
FontString,
NonDeletedExcalidrawElement,
} from "./types";
@ -408,3 +409,16 @@ export const getApproxCharsToFitInWidth = (font: FontString, width: number) => { @@ -408,3 +409,16 @@ export const getApproxCharsToFitInWidth = (font: FontString, width: number) => {
export const getBoundTextElementId = (container: ExcalidrawElement | null) => {
return container?.boundElements?.filter((ele) => ele.type === "text")[0]?.id;
};
export const getBoundedTextElement = (element: ExcalidrawElement | null) => {
if (!element) {
return null;
}
const boundTextElementId = getBoundTextElementId(element);
if (boundTextElementId) {
return Scene.getScene(element)!.getElement(
boundTextElementId,
) as ExcalidrawTextElementWithContainer;
}
return null;
};

Loading…
Cancel
Save