From 9ced6be03ec25afef66452a655c88a16bb5eb607 Mon Sep 17 00:00:00 2001 From: mmjang <752515918@qq.com> Date: Wed, 2 Oct 2024 17:37:40 +0800 Subject: [PATCH] Decide if element is bold by getComputedStyle (#2453) (#2579) * Decide if element is bold by getComputedStyle (#2453) * Use getComputedStyle() for italics too (dae) --- ts/editor/editor-toolbar/BoldButton.svelte | 5 +++-- ts/editor/editor-toolbar/ItalicButton.svelte | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ts/editor/editor-toolbar/BoldButton.svelte b/ts/editor/editor-toolbar/BoldButton.svelte index d6b580b56..215e98430 100644 --- a/ts/editor/editor-toolbar/BoldButton.svelte +++ b/ts/editor/editor-toolbar/BoldButton.svelte @@ -17,8 +17,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html return match.remove(); } - const fontWeight = element.style.fontWeight; - if (fontWeight === "bold" || Number(fontWeight) >= 700) { + const fontWeight = getComputedStyle(element).fontWeight; + const threshold = 700; + if (fontWeight && Number(fontWeight) >= threshold) { return match.clear((): void => { if ( removeStyleProperties(element, "font-weight") && diff --git a/ts/editor/editor-toolbar/ItalicButton.svelte b/ts/editor/editor-toolbar/ItalicButton.svelte index c31b8e93b..d5bbb3004 100644 --- a/ts/editor/editor-toolbar/ItalicButton.svelte +++ b/ts/editor/editor-toolbar/ItalicButton.svelte @@ -17,7 +17,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html return match.remove(); } - if (["italic", "oblique"].includes(element.style.fontStyle)) { + const fontStyle = getComputedStyle(element).fontStyle; + if (["italic", "oblique"].includes(fontStyle)) { return match.clear((): void => { if ( removeStyleProperties(element, "font-style") &&