|
@@ -43,153 +43,14 @@ import {
|
|
openSearchAsset,
|
|
openSearchAsset,
|
|
renderNextAssetMark,
|
|
renderNextAssetMark,
|
|
renderPreview,
|
|
renderPreview,
|
|
- toggleAssetHistory
|
|
|
|
} from "./assets";
|
|
} from "./assets";
|
|
import {resize} from "../protyle/util/resize";
|
|
import {resize} from "../protyle/util/resize";
|
|
-import {Menu} from "../plugin/Menu";
|
|
|
|
import {addClearButton} from "../util/addClearButton";
|
|
import {addClearButton} from "../util/addClearButton";
|
|
import {checkFold} from "../util/noRelyPCFunction";
|
|
import {checkFold} from "../util/noRelyPCFunction";
|
|
import {getUnRefList, openSearchUnRef, unRefMoreMenu} from "./unRef";
|
|
import {getUnRefList, openSearchUnRef, unRefMoreMenu} from "./unRef";
|
|
import {getDefaultType} from "./getDefault";
|
|
import {getDefaultType} from "./getDefault";
|
|
import {isSupportCSSHL, searchMarkRender} from "../protyle/render/searchMarkRender";
|
|
import {isSupportCSSHL, searchMarkRender} from "../protyle/render/searchMarkRender";
|
|
-
|
|
|
|
-export const toggleReplaceHistory = (searchElement: Element) => {
|
|
|
|
- const list = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS];
|
|
|
|
- if (!list.replaceKeys || list.replaceKeys.length === 0) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- const menu = new Menu("search-replace-history");
|
|
|
|
- if (menu.isOpen) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- menu.element.classList.add("b3-menu--list");
|
|
|
|
- menu.addItem({
|
|
|
|
- iconHTML: "",
|
|
|
|
- label: window.siyuan.languages.clearHistory,
|
|
|
|
- click() {
|
|
|
|
- window.siyuan.storage[Constants.LOCAL_SEARCHKEYS].replaceKeys = [];
|
|
|
|
- setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- const separatorElement = menu.addSeparator(1);
|
|
|
|
- let current = true;
|
|
|
|
- const replaceInputElement = searchElement.querySelector("#replaceInput") as HTMLInputElement;
|
|
|
|
- list.replaceKeys.forEach((s: string) => {
|
|
|
|
- if (s !== replaceInputElement.value && s) {
|
|
|
|
- const menuItem = menu.addItem({
|
|
|
|
- iconHTML: "",
|
|
|
|
- label: escapeHtml(s),
|
|
|
|
- action: "iconCloseRound",
|
|
|
|
- bind(element) {
|
|
|
|
- element.addEventListener("click", (itemEvent) => {
|
|
|
|
- if (hasClosestByClassName(itemEvent.target as Element, "b3-menu__action")) {
|
|
|
|
- list.replaceKeys.find((item: string, index: number) => {
|
|
|
|
- if (item === s) {
|
|
|
|
- list.replaceKeys.splice(index, 1);
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- window.siyuan.storage[Constants.LOCAL_SEARCHKEYS].replaceKeys = list.replaceKeys;
|
|
|
|
- setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
|
|
|
|
- if (element.previousElementSibling?.classList.contains("b3-menu__separator") && !element.nextElementSibling) {
|
|
|
|
- window.siyuan.menus.menu.remove();
|
|
|
|
- } else {
|
|
|
|
- element.remove();
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- replaceInputElement.value = element.textContent;
|
|
|
|
- window.siyuan.menus.menu.remove();
|
|
|
|
- }
|
|
|
|
- itemEvent.preventDefault();
|
|
|
|
- itemEvent.stopPropagation();
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- if (current) {
|
|
|
|
- menuItem.classList.add("b3-menu__item--current");
|
|
|
|
- }
|
|
|
|
- current = false;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- if (current) {
|
|
|
|
- separatorElement.remove();
|
|
|
|
- }
|
|
|
|
- const rect = replaceInputElement.getBoundingClientRect();
|
|
|
|
- menu.open({
|
|
|
|
- x: rect.left,
|
|
|
|
- y: rect.bottom
|
|
|
|
- });
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-export const toggleSearchHistory = (searchElement: Element, config: Config.IUILayoutTabSearchConfig, edit: Protyle) => {
|
|
|
|
- const list = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS];
|
|
|
|
- if (!list.keys || list.keys.length === 0) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- const menu = new Menu("search-history");
|
|
|
|
- if (menu.isOpen) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- menu.element.classList.add("b3-menu--list");
|
|
|
|
- menu.addItem({
|
|
|
|
- iconHTML: "",
|
|
|
|
- label: window.siyuan.languages.clearHistory,
|
|
|
|
- click() {
|
|
|
|
- window.siyuan.storage[Constants.LOCAL_SEARCHKEYS].keys = [];
|
|
|
|
- setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- const separatorElement = menu.addSeparator(1);
|
|
|
|
- let current = true;
|
|
|
|
- const searchInputElement = searchElement.querySelector("#searchInput") as HTMLInputElement;
|
|
|
|
- list.keys.forEach((s: string) => {
|
|
|
|
- if (s !== searchInputElement.value && s) {
|
|
|
|
- const menuItem = menu.addItem({
|
|
|
|
- iconHTML: "",
|
|
|
|
- label: escapeHtml(s),
|
|
|
|
- action: "iconCloseRound",
|
|
|
|
- bind(element) {
|
|
|
|
- element.addEventListener("click", (itemEvent) => {
|
|
|
|
- if (hasClosestByClassName(itemEvent.target as Element, "b3-menu__action")) {
|
|
|
|
- list.keys.find((item: string, index: number) => {
|
|
|
|
- if (item === s) {
|
|
|
|
- list.keys.splice(index, 1);
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- window.siyuan.storage[Constants.LOCAL_SEARCHKEYS].keys = list.keys;
|
|
|
|
- setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
|
|
|
|
- if (element.previousElementSibling?.classList.contains("b3-menu__separator") && !element.nextElementSibling) {
|
|
|
|
- window.siyuan.menus.menu.remove();
|
|
|
|
- } else {
|
|
|
|
- element.remove();
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- searchInputElement.value = element.textContent;
|
|
|
|
- config.page = 1;
|
|
|
|
- inputEvent(searchElement, config, edit, true);
|
|
|
|
- window.siyuan.menus.menu.remove();
|
|
|
|
- }
|
|
|
|
- itemEvent.preventDefault();
|
|
|
|
- itemEvent.stopPropagation();
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- if (current) {
|
|
|
|
- menuItem.classList.add("b3-menu__item--current");
|
|
|
|
- }
|
|
|
|
- current = false;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- if (current) {
|
|
|
|
- separatorElement.remove();
|
|
|
|
- }
|
|
|
|
- const rect = searchInputElement.getBoundingClientRect();
|
|
|
|
- menu.open({
|
|
|
|
- x: rect.left,
|
|
|
|
- y: rect.bottom
|
|
|
|
- });
|
|
|
|
-};
|
|
|
|
|
|
+import {toggleAssetHistory, toggleReplaceHistory, toggleSearchHistory} from "./toggleHistory";
|
|
|
|
|
|
const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
|
|
const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
|
|
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][type];
|
|
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][type];
|
|
@@ -296,7 +157,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele
|
|
</div>
|
|
</div>
|
|
<div class="b3-form__icon search__header">
|
|
<div class="b3-form__icon search__header">
|
|
<div style="position: relative" class="fn__flex-1">
|
|
<div style="position: relative" class="fn__flex-1">
|
|
- <span class="search__history-icon ariaLabel" id="searchHistoryBtn" aria-label="${updateHotkeyTip("⌥↓")}">
|
|
|
|
|
|
+ <span class="search__history-icon ariaLabel" id="searchHistoryBtn" aria-label="${updateHotkeyTip("⌥↓")}">
|
|
<svg data-menu="true" class="b3-form__icon-icon"><use xlink:href="#iconSearch"></use></svg>
|
|
<svg data-menu="true" class="b3-form__icon-icon"><use xlink:href="#iconSearch"></use></svg>
|
|
<svg class="search__arrowdown"><use xlink:href="#iconDown"></use></svg>
|
|
<svg class="search__arrowdown"><use xlink:href="#iconDown"></use></svg>
|
|
</span>
|
|
</span>
|
|
@@ -908,7 +769,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele
|
|
event.preventDefault();
|
|
event.preventDefault();
|
|
return;
|
|
return;
|
|
} else if (target.id === "replaceHistoryBtn") {
|
|
} else if (target.id === "replaceHistoryBtn") {
|
|
- toggleReplaceHistory(element);
|
|
|
|
|
|
+ toggleReplaceHistory(element.querySelector("#replaceInput"));
|
|
event.stopPropagation();
|
|
event.stopPropagation();
|
|
event.preventDefault();
|
|
event.preventDefault();
|
|
return;
|
|
return;
|