There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
fix(editor): prototype polluting in gfx util (#11831)
doodlewind1146f4d5a983
diff --git a/blocksuite/affine/gfx/text/src/element-renderer/utils.ts b/blocksuite/affine/gfx/text/src/element-renderer/utils.tsindex 6659729959..947ce26eb2 100644--- a/blocksuite/affine/gfx/text/src/element-renderer/utils.ts+++ b/blocksuite/affine/gfx/text/src/element-renderer/utils.ts@@ -399,23 +399,27 @@ export function parseTokens(text: string): string[] {}export const charWidth = (() => {- const cachedCharWidth: Record<string, Array<number>> = {};+ const cachedCharWidth = new Map<string, Array<number>>();const calculate = (char: string, font: string) => {const ascii = char.charCodeAt(0);- if (!cachedCharWidth[font]) {- cachedCharWidth[font] = [];++ let fontCache = cachedCharWidth.get(font);+ if (!fontCache) {+ fontCache = [];+ cachedCharWidth.set(font, fontCache);}- if (!cachedCharWidth[font][ascii]) {++ if (fontCache[ascii] === undefined) {const width = getLineWidth(char, font);- cachedCharWidth[font][ascii] = width;+ fontCache[ascii] = width;}- return cachedCharWidth[font][ascii];+ return fontCache[ascii];};const getCache = (font: string) => {- return cachedCharWidth[font];+ return cachedCharWidth.get(font);};return {calculate,