mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
This commit is contained in:
parent
aab0a269de
commit
9d27198c70
4 changed files with 13 additions and 7 deletions
|
|
@ -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: `<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) {
|
||||
const inputElement = menuItemElement.querySelector("input");
|
||||
inputElement.value = element.getAttribute("data-subtype") === "d" ? "" : element.textContent;
|
||||
|
|
|
|||
|
|
@ -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)}</button>`;
|
|||
}
|
||||
|
||||
// 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)}</button>`;
|
|||
}
|
||||
}
|
||||
|
||||
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)}</button>`;
|
|||
let tempElement = document.createElement("div");
|
||||
tempElement.innerHTML = value.replace(/<mark>/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)}</button>`;
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue