This commit is contained in:
Vanessa 2023-04-20 18:40:29 +08:00
parent aab0a269de
commit 9d27198c70
4 changed files with 13 additions and 7 deletions

View file

@ -54,7 +54,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
let oldHTML = nodeElement.outerHTML; let oldHTML = nodeElement.outerHTML;
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: `<input style="margin: 4px 0" class="b3-text-field" placeholder="${window.siyuan.languages.anchor}">`, label: `<input style="margin: 4px 0" class="b3-text-field fn__block" placeholder="${window.siyuan.languages.anchor}">`,
bind(menuItemElement) { bind(menuItemElement) {
const inputElement = menuItemElement.querySelector("input"); const inputElement = menuItemElement.querySelector("input");
inputElement.value = element.getAttribute("data-subtype") === "d" ? "" : element.textContent; inputElement.value = element.getAttribute("data-subtype") === "d" ? "" : element.textContent;

View file

@ -31,6 +31,7 @@ import {getIconByType} from "../../editor/getIcon";
import {processRender} from "../util/processCode"; import {processRender} from "../util/processCode";
import {AIChat} from "../../ai/chat"; import {AIChat} from "../../ai/chat";
import {isMobile} from "../../util/functions"; import {isMobile} from "../../util/functions";
import {isCtrl} from "../util/compatibility";
export class Hint { export class Hint {
public timeId: number; public timeId: number;
@ -56,7 +57,7 @@ export class Hint {
const btnElement = hasClosestByMatchTag(eventTarget, "BUTTON"); const btnElement = hasClosestByMatchTag(eventTarget, "BUTTON");
if (btnElement && !btnElement.classList.contains("emojis__item")) { if (btnElement && !btnElement.classList.contains("emojis__item")) {
if (btnElement.parentElement.classList.contains("b3-list")) { 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 { } else {
// 划选引用点击,需先重置 range // 划选引用点击,需先重置 range
setTimeout(() => { setTimeout(() => {
@ -163,7 +164,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
} }
// https://github.com/siyuan-note/siyuan/issues/7933 // https://github.com/siyuan-note/siyuan/issues/7933
if (this.splitChar === "#" ) { if (this.splitChar === "#") {
const blockElement = hasClosestBlock(protyle.toolbar.range.startContainer); const blockElement = hasClosestBlock(protyle.toolbar.range.startContainer);
if (blockElement && blockElement.getAttribute("data-type") === "NodeHeading") { if (blockElement && blockElement.getAttribute("data-type") === "NodeHeading") {
const blockIndex = getSelectionOffset(protyle.toolbar.range.startContainer, blockElement).start; const blockIndex = getSelectionOffset(protyle.toolbar.range.startContainer, blockElement).start;
@ -406,7 +407,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
} }
} }
public fill(value: string, protyle: IProtyle, updateRange = true) { public fill(value: string, protyle: IProtyle, updateRange = true, refIsS = false) {
hideElements(["hint", "toolbar"], protyle); hideElements(["hint", "toolbar"], protyle);
if (updateRange) { if (updateRange) {
protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element); protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element);
@ -486,6 +487,10 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
let tempElement = document.createElement("div"); let tempElement = document.createElement("div");
tempElement.innerHTML = value.replace(/<mark>/g, "").replace(/<\/mark>/g, ""); tempElement.innerHTML = value.replace(/<mark>/g, "").replace(/<\/mark>/g, "");
tempElement = tempElement.firstElementChild as HTMLDivElement; 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", { protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
type: "id", type: "id",
color: `${tempElement.getAttribute("data-id")}${Constants.ZWSP}${tempElement.getAttribute("data-subtype")}${Constants.ZWSP}${tempElement.textContent}` color: `${tempElement.getAttribute("data-id")}${Constants.ZWSP}${tempElement.getAttribute("data-subtype")}${Constants.ZWSP}${tempElement.textContent}`
@ -743,7 +748,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
if (mark === Constants.ZWSP + 3) { if (mark === Constants.ZWSP + 3) {
(this.element.querySelector(".b3-list-item--focus input") as HTMLElement).click(); (this.element.querySelector(".b3-list-item--focus input") as HTMLElement).click();
} else { } else {
this.fill(mark, protyle); this.fill(mark, protyle, true, isCtrl(event));
} }
} }
event.preventDefault(); event.preventDefault();

View file

@ -74,7 +74,7 @@ export const getEventName = () => {
}; };
// 区别 mac 上的 ctrl 和 meta // 区别 mac 上的 ctrl 和 meta
export const isCtrl = (event: KeyboardEvent) => { export const isCtrl = (event: KeyboardEvent | MouseEvent) => {
if (isMac()) { if (isMac()) {
// mac // mac
if (event.metaKey && !event.ctrlKey) { if (event.metaKey && !event.ctrlKey) {

View file

@ -515,7 +515,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return; return;
} }
// hint: 上下、回车选择 // 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)) { !protyle.hint.element.classList.contains("fn__none") && protyle.hint.select(event, protyle)) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();