From 979cb54766db433b63ec00f0ed4e1984eb499b38 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 15 Dec 2025 23:52:49 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/15108 --- app/src/protyle/wysiwyg/input.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts index a5e2cc0f9..e5dbb1b65 100644 --- a/app/src/protyle/wysiwyg/input.ts +++ b/app/src/protyle/wysiwyg/input.ts @@ -4,7 +4,7 @@ import * as dayjs from "dayjs"; import {transaction, updateTransaction} from "./transaction"; import {mathRender} from "../render/mathRender"; import {highlightRender} from "../render/highlightRender"; -import {getContenteditableElement, hasNextSibling, isNotEditBlock} from "./getBlock"; +import {getContenteditableElement, hasNextSibling, hasPreviousSibling, isNotEditBlock} from "./getBlock"; import {genEmptyBlock} from "../../block/util"; import {blockRender} from "../render/blockRender"; import {hideElements} from "../ui/hideElements"; @@ -59,6 +59,11 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range: range.insertNode(wbrElement); if (event) { const wbrNextElement = hasNextSibling(wbrElement) as HTMLElement; + // 行内代码前软换行,光标应在行内代码前 + if (!hasPreviousSibling(wbrElement) && wbrElement.parentElement.tagName === "SPAN" && + wbrNextElement && wbrNextElement.textContent.startsWith(Constants.ZWSP)) { + wbrElement.parentElement.before(wbrElement); + } if (event.inputType === "deleteContentForward") { if (wbrNextElement && wbrNextElement.nodeType === 1 && !wbrNextElement.textContent.startsWith(Constants.ZWSP)) { const nextType = (wbrNextElement.getAttribute("data-type") || "").split(" "); @@ -169,7 +174,7 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range: let replaceInnerHTML = editElement.innerHTML.trim().replace(/^(~|·|`){3,}/g, "```").replace(/\n(~|·|`){3,}/g, "\n```").trim(); if (replaceInnerHTML.endsWith("\n```") && (replaceInnerHTML.split("\n```").length - 1 + (replaceInnerHTML.startsWith("```") ? 1 : 0)) % 2 === 0) { - // 匹配已闭合的不需添加 https://github.com/siyuan-note/siyuan/issues/16053 + // 匹配已闭合的不需添加 https://github.com/siyuan-note/siyuan/issues/16053 } else if (!replaceInnerHTML.endsWith("\n```")) { // 以 "\n```" 结尾需要添加的情况 https://github.com/siyuan-note/siyuan/issues/16519 replaceInnerHTML = replaceInnerHTML.replace("", "") + "\n```";