This commit is contained in:
Vanessa 2023-04-12 19:02:35 +08:00
parent a2138b989c
commit f30e9893e8
3 changed files with 83 additions and 49 deletions

View file

@ -37,6 +37,7 @@ import {openCardByData} from "../../card/openCard";
import {makeCard, quickMakeCard} from "../../card/makeCard";
import {viewCards} from "../../card/viewCards";
import {getNotebookName, pathPosix} from "../../util/pathName";
import {commonClick} from "../wysiwyg/commonClick";
export class Title {
public element: HTMLElement;
@ -245,33 +246,7 @@ export class Title {
fetchPost("/api/block/getDocInfo", {
id: protyle.block.rootID
}, (response) => {
const attrBookmarkElement = hasClosestByClassName(event.target, "protyle-attr--bookmark");
if (attrBookmarkElement) {
openFileAttr(response.data.ial, protyle.block.rootID, "bookmark");
event.stopPropagation();
return;
}
const attrNameElement = hasClosestByClassName(event.target, "protyle-attr--name");
if (attrNameElement) {
openFileAttr(response.data.ial, protyle.block.rootID, "name");
event.stopPropagation();
return;
}
const attrAliasElement = hasClosestByClassName(event.target, "protyle-attr--alias");
if (attrAliasElement) {
openFileAttr(response.data.ial, protyle.block.rootID, "alias");
event.stopPropagation();
return;
}
const attrMemoElement = hasClosestByClassName(event.target, "protyle-attr--memo");
if (attrMemoElement) {
openFileAttr(response.data.ial, protyle.block.rootID, "memo");
event.stopPropagation();
return;
}
commonClick(event, protyle, response.data.ial);
});
});
}

View file

@ -0,0 +1,79 @@
import {hasClosestByClassName} from "../util/hasClosest";
import {openAttr, openFileAttr} from "../../menus/commonMenuItem";
/// #if !MOBILE
import {openGlobalSearch} from "../../search/util";
/// #endif
import {isMobile} from "../../util/functions";
export const commonClick = (event: MouseEvent & {
target: HTMLElement
}, protyle: IProtyle, data?:IObject) => {
const isM = isMobile();
const attrBookmarkElement = hasClosestByClassName(event.target, "protyle-attr--bookmark");
if (attrBookmarkElement) {
if (!isM && (event.ctrlKey || event.metaKey)) {
/// #if !MOBILE
openGlobalSearch(attrBookmarkElement.textContent.trim(), true);
/// #endif
} else {
if (data) {
openFileAttr(data, protyle.block.rootID, "bookmark");
} else {
openAttr(attrBookmarkElement.parentElement.parentElement, protyle, "bookmark");
}
}
event.stopPropagation();
return true;
}
const attrNameElement = hasClosestByClassName(event.target, "protyle-attr--name");
if (attrNameElement) {
if (!isM && (event.ctrlKey || event.metaKey)) {
/// #if !MOBILE
openGlobalSearch(attrNameElement.textContent.trim(), true);
/// #endif
} else {
if (data ) {
openFileAttr(data, protyle.block.rootID, "name");
} else {
openAttr(attrNameElement.parentElement.parentElement, protyle, "name");
}
}
event.stopPropagation();
return true;
}
const attrAliasElement = hasClosestByClassName(event.target, "protyle-attr--alias");
if (attrAliasElement) {
if (!isM && (event.ctrlKey || event.metaKey)) {
/// #if !MOBILE
openGlobalSearch(attrAliasElement.textContent.trim(), true);
/// #endif
} else {
if (data) {
openFileAttr(data, protyle.block.rootID, "alias");
} else {
openAttr(attrAliasElement.parentElement.parentElement, protyle, "alias");
}
}
event.stopPropagation();
return true;
}
const attrMemoElement = hasClosestByClassName(event.target, "protyle-attr--memo");
if (attrMemoElement) {
if (!isM && (event.ctrlKey || event.metaKey)) {
/// #if !MOBILE
openGlobalSearch(attrMemoElement.getAttribute("aria-label").trim(), true);
/// #endif
} else {
if (data) {
openFileAttr(data, protyle.block.rootID, "memo");
} else {
openAttr(attrMemoElement.parentElement.parentElement, protyle, "memo");
}
}
event.stopPropagation();
return true;
}
}

View file

@ -63,6 +63,7 @@ import {showMessage} from "../../dialog/message";
import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink";
import {removeSearchMark} from "../toolbar/util";
import {activeBlur, hideKeyboardToolbar} from "../../mobile/util/keyboardToolbar";
import {commonClick} from "./commonClick";
export class WYSIWYG {
public lastHTMLs: { [key: string]: string } = {};
@ -1718,28 +1719,7 @@ export class WYSIWYG {
return;
}
const attrBookmarkElement = hasClosestByClassName(event.target, "protyle-attr--bookmark");
if (attrBookmarkElement) {
openAttr(attrBookmarkElement.parentElement.parentElement, protyle, "bookmark");
event.stopPropagation();
return;
}
const attrNameElement = hasClosestByClassName(event.target, "protyle-attr--name");
if (attrNameElement) {
openAttr(attrNameElement.parentElement.parentElement, protyle, "name");
event.stopPropagation();
return;
}
const attrAliasElement = hasClosestByClassName(event.target, "protyle-attr--alias");
if (attrAliasElement) {
openAttr(attrAliasElement.parentElement.parentElement, protyle, "alias");
event.stopPropagation();
return;
}
const attrMemoElement = hasClosestByClassName(event.target, "protyle-attr--memo");
if (attrMemoElement) {
openAttr(attrMemoElement.parentElement.parentElement, protyle, "memo");
event.stopPropagation();
if (commonClick(event, protyle)) {
return;
}