mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
keep original font size
This commit is contained in:
parent
90fc57321b
commit
230a339c7b
2 changed files with 57 additions and 13 deletions
|
@ -395,6 +395,7 @@ import ShapeSwitch, {
|
||||||
GENERIC_SWITCHABLE_SHAPES,
|
GENERIC_SWITCHABLE_SHAPES,
|
||||||
LINEAR_SWITCHABLE_SHAPES,
|
LINEAR_SWITCHABLE_SHAPES,
|
||||||
shapeSwitchAtom,
|
shapeSwitchAtom,
|
||||||
|
shapeSwitchFontSizeAtom,
|
||||||
} from "./ShapeSwitch";
|
} from "./ShapeSwitch";
|
||||||
|
|
||||||
import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
|
import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
|
||||||
|
@ -4143,6 +4144,18 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
editorJotaiStore.set(shapeSwitchAtom, {
|
editorJotaiStore.set(shapeSwitchAtom, {
|
||||||
type: "panel",
|
type: "panel",
|
||||||
});
|
});
|
||||||
|
if (!editorJotaiStore.get(shapeSwitchFontSizeAtom)) {
|
||||||
|
const boundText = getBoundTextElement(
|
||||||
|
firstElement,
|
||||||
|
this.scene.getNonDeletedElementsMap(),
|
||||||
|
);
|
||||||
|
if (boundText && isGenericSwitchable) {
|
||||||
|
editorJotaiStore.set(shapeSwitchFontSizeAtom, {
|
||||||
|
fontSize: boundText.fontSize,
|
||||||
|
elementType: firstElement.type,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4829,7 +4842,26 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
: firstElement.roundness,
|
: firstElement.roundness,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (firstElement.boundElements?.some((e) => e.type === "text")) {
|
const boundText = getBoundTextElement(
|
||||||
|
firstElement,
|
||||||
|
this.scene.getNonDeletedElementsMap(),
|
||||||
|
);
|
||||||
|
if (boundText) {
|
||||||
|
if (
|
||||||
|
editorJotaiStore.get(shapeSwitchFontSizeAtom)?.elementType ===
|
||||||
|
tool.type
|
||||||
|
) {
|
||||||
|
mutateElement(
|
||||||
|
boundText,
|
||||||
|
{
|
||||||
|
fontSize:
|
||||||
|
editorJotaiStore.get(shapeSwitchFontSizeAtom)?.fontSize ??
|
||||||
|
boundText.fontSize,
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.startTextEditing({
|
this.startTextEditing({
|
||||||
sceneX: firstElement.x + firstElement.width / 2,
|
sceneX: firstElement.x + firstElement.width / 2,
|
||||||
sceneY: firstElement.y + firstElement.height / 2,
|
sceneY: firstElement.y + firstElement.height / 2,
|
||||||
|
|
|
@ -45,11 +45,18 @@ export const shapeSwitchAtom = atom<
|
||||||
}
|
}
|
||||||
| null
|
| null
|
||||||
>(null);
|
>(null);
|
||||||
|
export const shapeSwitchFontSizeAtom = atom<{
|
||||||
|
fontSize: number;
|
||||||
|
elementType: "rectangle" | "diamond" | "ellipse";
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
const ShapeSwitch = ({ app }: { app: App }) => {
|
const ShapeSwitch = ({ app }: { app: App }) => {
|
||||||
const [shapeSwitch, setShapeSwitch] = useAtom(shapeSwitchAtom);
|
const [shapeSwitch, setShapeSwitch] = useAtom(shapeSwitchAtom);
|
||||||
|
const [, setShapeSwitchFontSize] = useAtom(shapeSwitchFontSizeAtom);
|
||||||
|
|
||||||
|
// clear if not active
|
||||||
if (!shapeSwitch) {
|
if (!shapeSwitch) {
|
||||||
|
setShapeSwitchFontSize(null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,24 +66,29 @@ const ShapeSwitch = ({ app }: { app: App }) => {
|
||||||
);
|
);
|
||||||
const firstElement = selectedElements[0];
|
const firstElement = selectedElements[0];
|
||||||
|
|
||||||
if (shapeSwitch.type === "hint" && firstElement.id !== shapeSwitch.id) {
|
const isSingleSelected = firstElement && selectedElements.length === 1;
|
||||||
|
|
||||||
|
// clear if hint target no longer matches
|
||||||
|
if (shapeSwitch.type === "hint" && firstElement?.id !== shapeSwitch.id) {
|
||||||
setShapeSwitch(null);
|
setShapeSwitch(null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstElement && selectedElements.length === 1) {
|
if (!isSingleSelected) {
|
||||||
switch (shapeSwitch.type) {
|
setShapeSwitch(null);
|
||||||
case "hint":
|
return null;
|
||||||
return <Hint app={app} element={firstElement} />;
|
|
||||||
case "panel":
|
|
||||||
return <Panel app={app} element={firstElement} />;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setShapeSwitch(null);
|
const props = { app, element: firstElement };
|
||||||
return null;
|
|
||||||
|
switch (shapeSwitch.type) {
|
||||||
|
case "hint":
|
||||||
|
return <Hint {...props} />;
|
||||||
|
case "panel":
|
||||||
|
return <Panel {...props} />;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const Hint = ({ app, element }: { app: App; element: ExcalidrawElement }) => {
|
const Hint = ({ app, element }: { app: App; element: ExcalidrawElement }) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue