diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 69af81981..4aed17178 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -584,6 +584,7 @@ "closeTab": "Close current Tab", "keymap": "Keymap", "clearFontStyle": "Clear Style", + "clearInline": "Clear inline elements", "fontStyle": "Font Effects", "font": "Font", "folder": "Folder", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 62d8755ed..aea33fd33 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -584,6 +584,7 @@ "closeTab": "Cerrar pestaña actual", "keymap": "Mapa de teclas", "clearFontStyle": "Limpiar estilo", + "clearInline": "Borrar elementos en línea", "fontStyle": "Efectos de fuentes", "font": "Fuente", "folder": "Carpeta", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 37bb0649d..12824ea70 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -584,6 +584,7 @@ "closeTab": "Fermer l'onglet actuel", "keymap": "Raccourci", "clearFontStyle": "Effacer Styles", + "clearInline": "Effacer les éléments en ligne", "fontStyle": "Effets de fonte", "font": "Police", "folder": "Dossier", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 83f1fcfbf..655839078 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -584,6 +584,7 @@ "closeTab": "關閉當前分頁", "keymap": "快速鍵", "clearFontStyle": "清除樣式", + "clearInline": "清除行內元素", "fontStyle": "字體效果", "font": "字體", "folder": "資料夾", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 155c11bb9..702370586 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -584,6 +584,7 @@ "closeTab": "关闭当前页签", "keymap": "快捷键", "clearFontStyle": "清除样式", + "clearInline": "清除行内元素", "fontStyle": "字体效果", "font": "字体", "folder": "文件夹", diff --git a/app/src/constants.ts b/app/src/constants.ts index 07659c535..5e45cc614 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -217,7 +217,7 @@ export abstract class Constants { check: {default: "⌘L", custom: "⌘L"}, table: {default: "⌘O", custom: "⌘O"}, code: {default: "⇧⌘K", custom: "⇧⌘K"}, - clearFontStyle: {default: "⌘\\", custom: "⌘\\"}, + clearInline: {default: "⌘\\", custom: "⌘\\"}, }, heading: { paragraph: {default: "⌥⌘0", custom: "⌥⌘0"}, diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts index 17b9c5fe9..9e16c1bf8 100644 --- a/app/src/protyle/toolbar/Font.ts +++ b/app/src/protyle/toolbar/Font.ts @@ -232,7 +232,7 @@ export const fontEvent = (protyle: IProtyle, nodeElements: Element[], type?: str e.style.fontSize = color; } }); - focusBlock(nodeElements[0]); + focusByRange(protyle.toolbar.range); } else { if (type === "clear") { protyle.toolbar.setInlineMark(protyle, "clear", "range", {type: "text"}); @@ -359,6 +359,15 @@ export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLE backgroundColor = currentElement.style.backgroundColor; fontSize = currentElement.style.fontSize; } + if (textObj.type === "text") { + // 清除样式 + return color === sideElement.style.color && + webkitTextFillColor === sideElement.style.webkitTextFillColor && + webkitTextStroke === sideElement.style.webkitTextStroke && + textShadow === sideElement.style.textShadow && + fontSize === sideElement.style.fontSize && + backgroundColor === sideElement.style.backgroundColor; + } if (textObj.type === "color") { return textObj.color === sideElement.style.color && webkitTextFillColor === sideElement.style.webkitTextFillColor && diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index ee413d0a8..0c78f62d5 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -344,7 +344,7 @@ export class Toolbar { return true; } }); - if (rangeTypes.length === 0) { + if (rangeTypes.length === 0 || type === "clear") { newNodes.push(document.createTextNode(Constants.ZWSP)); } else { // 遇到以下类型结尾不应继承 https://github.com/siyuan-note/siyuan/issues/7200 @@ -393,6 +393,14 @@ export class Toolbar { } newNodes.push(document.createTextNode(item.textContent)); } else { + if (selectText && type === "clear" && textObj && textObj.type === "text") { + // 选中内容中没有样式需要清除时直接返回,否则清除粗体中部分内容会报错 + if (item.style.color === "" && item.style.webkitTextFillColor === "" && item.style.webkitTextStroke === "" && item.style.textShadow === "" && item.style.backgroundColor === "" && item.style.fontSize === "") { + item.setAttribute("data-type", types.join(" ")); + newNodes.push(item); + return true; + } + } if (type === "clear") { item.style.color = ""; item.style.webkitTextFillColor = ""; diff --git a/app/src/protyle/util/Options.ts b/app/src/protyle/util/Options.ts index 23c803e95..961da30ba 100644 --- a/app/src/protyle/util/Options.ts +++ b/app/src/protyle/util/Options.ts @@ -235,8 +235,8 @@ export class Options { tipPosition: "n", }, { name: "clear", - lang: "clearFontStyle", - hotkey: window.siyuan.config.keymap.editor.insert.clearFontStyle.custom, + lang: "clearInline", + hotkey: window.siyuan.config.keymap.editor.insert.clearInline.custom, icon: "iconClear", tipPosition: "n", }, { diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 7d9b6426b..ccef63ae6 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -1290,7 +1290,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (matchHotKey(window.siyuan.config.keymap.editor.insert.lastUsed.custom, event)) { protyle.toolbar.range = range; let selectElements: Element[] = []; - if (selectText === "") { + if (selectText === "" && protyle.toolbar.getCurrentType(range).length === 0) { selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")); if (selectElements.length === 0) { selectElements = [nodeElement];