From a3379c897971149b9fac1a47488bc010a08a9210 Mon Sep 17 00:00:00 2001 From: Aisha Roslan <137568721+aisharoslan@users.noreply.github.com> Date: Thu, 26 Mar 2026 02:49:10 -0400 Subject: [PATCH] fix(editor): font weight dropdown empty on Chrome/Safari in edgeless mode (#14725) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Summary Resolves #14528. Normalizes font family string before comparison. Removes browser dependency. ### What Changed On Edgeless mode, font dropdown was not appearing for shapes on Chrome. Now, it appears on Chrome, Safari, and Firefox. ### Screenshot Verification **Google Chrome** Screenshot 2026-03-25 at 1 24 51 PM ## Summary by CodeRabbit * **Bug Fixes** * Improved font matching to be more tolerant of whitespace, quotes, and casing so font family comparisons are consistent across browsers, reducing incorrect font fallbacks and visual mismatches. --- .../affine/blocks/surface/src/utils/font.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/blocksuite/affine/blocks/surface/src/utils/font.ts b/blocksuite/affine/blocks/surface/src/utils/font.ts index dd961670ca..8d86c033d6 100644 --- a/blocksuite/affine/blocks/surface/src/utils/font.ts +++ b/blocksuite/affine/blocks/surface/src/utils/font.ts @@ -1,6 +1,17 @@ import type { FontFamily } from '@blocksuite/affine-model'; import { IS_FIREFOX } from '@blocksuite/global/env'; +function normalizeFontFamily(fontFamily: FontFamily | string): string { + let s = fontFamily.trim(); + if ( + (s.startsWith('"') && s.endsWith('"')) || + (s.startsWith("'") && s.endsWith("'")) + ) { + s = s.slice(1, -1); + } + return s.toLowerCase(); +} + export function wrapFontFamily(fontFamily: FontFamily | string): string { return `"${fontFamily}"`; } @@ -21,11 +32,9 @@ export const getFontFaces = IS_FIREFOX } : () => [...document.fonts.keys()]; -export const isSameFontFamily = IS_FIREFOX - ? (fontFamily: FontFamily | string) => (fontFace: FontFace) => - fontFace.family === `"${fontFamily}"` - : (fontFamily: FontFamily | string) => (fontFace: FontFace) => - fontFace.family === fontFamily; +export const isSameFontFamily = + (fontFamily: FontFamily | string) => (fontFace: FontFace) => + normalizeFontFamily(fontFace.family) === normalizeFontFamily(fontFamily); export function getFontFacesByFontFamily( fontFamily: FontFamily | string