use a const for default font value (#834)

This commit is contained in:
Faustino Kialungila 2020-02-24 16:29:54 +01:00 committed by GitHub
parent 2131befd7a
commit 1355e0201c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import { isTextElement, redrawTextBoundingBox } from "../element";
import { ColorPicker } from "../components/ColorPicker";
import { AppState } from "../../src/types";
import { t } from "../i18n";
import { DEFAULT_FONT } from "../appState";
const changeProperty = (
elements: readonly ExcalidrawElement[],
@ -297,7 +298,7 @@ export const actionChangeFontSize: Action = {
appState.editingElement,
elements,
element => isTextElement(element) && +element.font.split("px ")[0],
+(appState.currentItemFont || "20px Virgil").split("px ")[0],
+(appState.currentItemFont || DEFAULT_FONT).split("px ")[0],
)}
onChange={value => updateData(value)}
/>
@ -345,7 +346,7 @@ export const actionChangeFontFamily: Action = {
appState.editingElement,
elements,
element => isTextElement(element) && element.font.split("px ")[1],
(appState.currentItemFont || "20px Virgil").split("px ")[1],
(appState.currentItemFont || DEFAULT_FONT).split("px ")[1],
)}
onChange={value => updateData(value)}
/>

View File

@ -5,6 +5,7 @@ import {
redrawTextBoundingBox,
} from "../element";
import { KEYS } from "../keys";
import { DEFAULT_FONT } from "../appState";
let copiedStyles: string = "{}";
@ -43,7 +44,7 @@ export const actionPasteStyles: Action = {
roughness: pastedElement?.roughness,
};
if (isTextElement(newElement)) {
newElement.font = pastedElement?.font || "20px Virgil";
newElement.font = pastedElement?.font || DEFAULT_FONT;
redrawTextBoundingBox(newElement);
}
return newElement;

View File

@ -2,6 +2,7 @@ import { AppState, FlooredNumber } from "./types";
import { getDateTime } from "./utils";
const DEFAULT_PROJECT_NAME = `excalidraw-${getDateTime()}`;
export const DEFAULT_FONT = "20px Virgil";
export function getDefaultAppState(): AppState {
return {
@ -18,7 +19,7 @@ export function getDefaultAppState(): AppState {
currentItemStrokeWidth: 1,
currentItemRoughness: 1,
currentItemOpacity: 100,
currentItemFont: "20px Virgil",
currentItemFont: DEFAULT_FONT,
viewBackgroundColor: "#ffffff",
scrollX: 0 as FlooredNumber,
scrollY: 0 as FlooredNumber,