Bläddra i källkod

use a const for default font value (#834)

Faustino Kialungila 5 år sedan
förälder
incheckning
1355e0201c
3 ändrade filer med 7 tillägg och 4 borttagningar
  1. 3 2
      src/actions/actionProperties.tsx
  2. 2 1
      src/actions/actionStyles.ts
  3. 2 1
      src/appState.ts

+ 3 - 2
src/actions/actionProperties.tsx

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

+ 2 - 1
src/actions/actionStyles.ts

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

+ 2 - 1
src/appState.ts

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