diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index c6d00b134..75cfd021b 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -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); }); }); } diff --git a/app/src/protyle/wysiwyg/commonClick.ts b/app/src/protyle/wysiwyg/commonClick.ts new file mode 100644 index 000000000..dd6723022 --- /dev/null +++ b/app/src/protyle/wysiwyg/commonClick.ts @@ -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; + } +} diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 822d0c822..f75fdf0b3 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -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; }