diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index 312a938c8..54be10d2b 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -54,7 +54,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => { let oldHTML = nodeElement.outerHTML; window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.append(new MenuItem({ - label: ``, + label: ``, bind(menuItemElement) { const inputElement = menuItemElement.querySelector("input"); inputElement.value = element.getAttribute("data-subtype") === "d" ? "" : element.textContent; diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts index 89feac8fd..82c57a8cf 100644 --- a/app/src/protyle/hint/index.ts +++ b/app/src/protyle/hint/index.ts @@ -31,6 +31,7 @@ import {getIconByType} from "../../editor/getIcon"; import {processRender} from "../util/processCode"; import {AIChat} from "../../ai/chat"; import {isMobile} from "../../util/functions"; +import {isCtrl} from "../util/compatibility"; export class Hint { public timeId: number; @@ -56,7 +57,7 @@ export class Hint { const btnElement = hasClosestByMatchTag(eventTarget, "BUTTON"); if (btnElement && !btnElement.classList.contains("emojis__item")) { if (btnElement.parentElement.classList.contains("b3-list")) { - this.fill(decodeURIComponent(btnElement.getAttribute("data-value")), protyle); + this.fill(decodeURIComponent(btnElement.getAttribute("data-value")), protyle, true, isCtrl(event)); } else { // 划选引用点击,需先重置 range setTimeout(() => { @@ -163,7 +164,7 @@ ${unicode2Emoji(emoji.unicode, true)}`; } // https://github.com/siyuan-note/siyuan/issues/7933 - if (this.splitChar === "#" ) { + if (this.splitChar === "#") { const blockElement = hasClosestBlock(protyle.toolbar.range.startContainer); if (blockElement && blockElement.getAttribute("data-type") === "NodeHeading") { const blockIndex = getSelectionOffset(protyle.toolbar.range.startContainer, blockElement).start; @@ -406,7 +407,7 @@ ${unicode2Emoji(emoji.unicode, true)}`; } } - public fill(value: string, protyle: IProtyle, updateRange = true) { + public fill(value: string, protyle: IProtyle, updateRange = true, refIsS = false) { hideElements(["hint", "toolbar"], protyle); if (updateRange) { protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element); @@ -486,6 +487,10 @@ ${unicode2Emoji(emoji.unicode, true)}`; let tempElement = document.createElement("div"); tempElement.innerHTML = value.replace(//g, "").replace(/<\/mark>/g, ""); tempElement = tempElement.firstElementChild as HTMLDivElement; + if (refIsS) { + tempElement.setAttribute("data-subtype", "s"); + tempElement.innerText = range.toString().replace(this.splitChar, ""); + } protyle.toolbar.setInlineMark(protyle, "block-ref", "range", { type: "id", color: `${tempElement.getAttribute("data-id")}${Constants.ZWSP}${tempElement.getAttribute("data-subtype")}${Constants.ZWSP}${tempElement.textContent}` @@ -743,7 +748,7 @@ ${unicode2Emoji(emoji.unicode, true)}`; if (mark === Constants.ZWSP + 3) { (this.element.querySelector(".b3-list-item--focus input") as HTMLElement).click(); } else { - this.fill(mark, protyle); + this.fill(mark, protyle, true, isCtrl(event)); } } event.preventDefault(); diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts index bbbd0259d..734a4a4bf 100644 --- a/app/src/protyle/util/compatibility.ts +++ b/app/src/protyle/util/compatibility.ts @@ -74,7 +74,7 @@ export const getEventName = () => { }; // 区别 mac 上的 ctrl 和 meta -export const isCtrl = (event: KeyboardEvent) => { +export const isCtrl = (event: KeyboardEvent | MouseEvent) => { if (isMac()) { // mac if (event.metaKey && !event.ctrlKey) { diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 41ab859fe..8c299e75d 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -515,7 +515,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { return; } // hint: 上下、回车选择 - if (!event.altKey && !event.shiftKey && !isCtrl(event) && (event.key.indexOf("Arrow") > -1 || event.key === "Enter") && + if (!event.altKey && !event.shiftKey && + ((event.key.indexOf("Arrow") > -1 && !isCtrl(event)) || event.key === "Enter") && !protyle.hint.element.classList.contains("fn__none") && protyle.hint.select(event, protyle)) { event.stopPropagation(); event.preventDefault();