From c54aeeaefe638730cb9b97d86e856f4051274dc0 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 22 Sep 2022 22:52:05 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/5924 --- app/src/protyle/wysiwyg/index.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index fc21ab505..acde46d53 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -28,7 +28,7 @@ import { getLastBlock, getNextBlock, getPreviousHeading, getTopAloneElement, - hasNextSibling, + hasNextSibling, hasPreviousSibling, isNotEditBlock } from "./getBlock"; import {transaction, updateTransaction} from "./transaction"; @@ -113,6 +113,22 @@ export class WYSIWYG { protyle.toolbar.range = range; const inlineElement = range.startContainer.parentElement; const currentTypes = protyle.toolbar.getCurrentType(); + + let dataLength = inputData.length; + if (inputData === "<" || inputData === ">") { + // 使用 inlineElement.innerHTML 会出现 https://ld246.com/article/1627185027423 中的第2个问题 + dataLength = 4; + } + if (currentTypes.length > 0 && range.toString() === "" && range.startOffset === inputData.length && inlineElement.tagName === "SPAN" && + !hasPreviousSibling(range.startContainer) && !hasPreviousSibling(inlineElement)) { + const html = inlineElement.innerHTML.replace(Constants.ZWSP, ""); + inlineElement.innerHTML = html.substr(dataLength); + const textNode = document.createTextNode(inputData); + inlineElement.before(textNode); + range.selectNodeContents(textNode); + range.collapse(false); + return; + } if (// 表格行内公式之前无法插入文字 https://github.com/siyuan-note/siyuan/issues/3908 inlineElement.tagName === "SPAN" && inlineElement.textContent.replace(Constants.ZWSP, "") !== inputData && @@ -122,11 +138,6 @@ export class WYSIWYG { inlineElement.textContent.replace(Constants.ZWSP, "").length >= inputData.length // 为空的时候需要等于 ) { const position = getSelectionOffset(inlineElement, protyle.wysiwyg.element, range); - let dataLength = inputData.length; - if (inputData === "<" || inputData === ">") { - // 使用 inlineElement.innerHTML 会出现 https://ld246.com/article/1627185027423 中的第2个问题 - dataLength = 4; - } // ctrl+k 会产生 ZWSP,需要移除 const html = inlineElement.innerHTML.replace(Constants.ZWSP, ""); if (position.start === inlineElement.textContent.length) {