mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 04:02:58 +08:00
This commit is contained in:
parent
eba36f4baa
commit
e2017a9fba
@ -26,7 +26,13 @@ import {
|
|||||||
import {addClearButton} from "../../util/addClearButton";
|
import {addClearButton} from "../../util/addClearButton";
|
||||||
import {checkFold} from "../../util/noRelyPCFunction";
|
import {checkFold} from "../../util/noRelyPCFunction";
|
||||||
import {getDefaultType} from "../../search/getDefault";
|
import {getDefaultType} from "../../search/getDefault";
|
||||||
import {toggleAssetHistory, toggleReplaceHistory, toggleSearchHistory} from "../../search/toggleHistory";
|
import {
|
||||||
|
saveAssetKeyList,
|
||||||
|
saveKeyList,
|
||||||
|
toggleAssetHistory,
|
||||||
|
toggleReplaceHistory,
|
||||||
|
toggleSearchHistory
|
||||||
|
} from "../../search/toggleHistory";
|
||||||
|
|
||||||
const replace = (element: Element, config: Config.IUILayoutTabSearchConfig, isAll: boolean) => {
|
const replace = (element: Element, config: Config.IUILayoutTabSearchConfig, isAll: boolean) => {
|
||||||
if (config.method === 1 || config.method === 2) {
|
if (config.method === 1 || config.method === 2) {
|
||||||
@ -40,6 +46,7 @@ const replace = (element: Element, config: Config.IUILayoutTabSearchConfig, isAl
|
|||||||
if (!loadElement.classList.contains("fn__none")) {
|
if (!loadElement.classList.contains("fn__none")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
saveKeyList("replaceKeys", replaceInputElement.value);
|
||||||
let currentLiElement: HTMLElement = searchListElement.querySelector(".b3-list-item--focus");
|
let currentLiElement: HTMLElement = searchListElement.querySelector(".b3-list-item--focus");
|
||||||
if (!currentLiElement) {
|
if (!currentLiElement) {
|
||||||
return;
|
return;
|
||||||
@ -288,6 +295,7 @@ const initSearchEvent = (app: App, element: Element, config: Config.IUILayoutTab
|
|||||||
window.siyuan.storage[Constants.LOCAL_SEARCHDATA] = Object.assign({}, config);
|
window.siyuan.storage[Constants.LOCAL_SEARCHDATA] = Object.assign({}, config);
|
||||||
setStorageVal(Constants.LOCAL_SEARCHDATA, window.siyuan.storage[Constants.LOCAL_SEARCHDATA]);
|
setStorageVal(Constants.LOCAL_SEARCHDATA, window.siyuan.storage[Constants.LOCAL_SEARCHDATA]);
|
||||||
}
|
}
|
||||||
|
saveKeyList("keys", searchInputElement.value);
|
||||||
});
|
});
|
||||||
addClearButton({
|
addClearButton({
|
||||||
inputElement: searchInputElement,
|
inputElement: searchInputElement,
|
||||||
@ -802,6 +810,9 @@ const goAsset = () => {
|
|||||||
}
|
}
|
||||||
assetInputEvent(assetsElement, localSearch);
|
assetInputEvent(assetsElement, localSearch);
|
||||||
});
|
});
|
||||||
|
inputElement.addEventListener("blur", () => {
|
||||||
|
saveAssetKeyList(inputElement)
|
||||||
|
});
|
||||||
assetInputEvent(assetsElement, localSearch);
|
assetInputEvent(assetsElement, localSearch);
|
||||||
addClearButton({
|
addClearButton({
|
||||||
inputElement,
|
inputElement,
|
||||||
|
@ -12,6 +12,7 @@ import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
|||||||
import {addClearButton} from "../util/addClearButton";
|
import {addClearButton} from "../util/addClearButton";
|
||||||
import {isPaidUser} from "../util/needSubscribe";
|
import {isPaidUser} from "../util/needSubscribe";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
|
import {saveAssetKeyList} from "./toggleHistory";
|
||||||
|
|
||||||
export const openSearchAsset = (element: Element, isStick: boolean) => {
|
export const openSearchAsset = (element: Element, isStick: boolean) => {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
@ -108,18 +109,7 @@ export const openSearchAsset = (element: Element, isStick: boolean) => {
|
|||||||
assetInputEvent(element, localSearch);
|
assetInputEvent(element, localSearch);
|
||||||
});
|
});
|
||||||
searchInputElement.addEventListener("blur", () => {
|
searchInputElement.addEventListener("blur", () => {
|
||||||
if (!searchInputElement.value) {
|
saveAssetKeyList(searchInputElement)
|
||||||
return;
|
|
||||||
}
|
|
||||||
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHASSET].keys;
|
|
||||||
list.splice(0, 0, searchInputElement.value);
|
|
||||||
list = Array.from(new Set(list));
|
|
||||||
if (list.length > window.siyuan.config.search.limit) {
|
|
||||||
list.splice(window.siyuan.config.search.limit, list.length - window.siyuan.config.search.limit);
|
|
||||||
}
|
|
||||||
window.siyuan.storage[Constants.LOCAL_SEARCHASSET].k = searchInputElement.value;
|
|
||||||
window.siyuan.storage[Constants.LOCAL_SEARCHASSET].keys = list;
|
|
||||||
setStorageVal(Constants.LOCAL_SEARCHASSET, window.siyuan.storage[Constants.LOCAL_SEARCHASSET]);
|
|
||||||
});
|
});
|
||||||
assetInputEvent(element, localSearch);
|
assetInputEvent(element, localSearch);
|
||||||
addClearButton({
|
addClearButton({
|
||||||
|
@ -220,3 +220,30 @@ export const toggleAssetHistory = (assetElement: Element) => {
|
|||||||
y: rect.bottom
|
y: rect.bottom
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
|
||||||
|
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][type];
|
||||||
|
list.splice(0, 0, value);
|
||||||
|
list = Array.from(new Set(list));
|
||||||
|
if (list.length > window.siyuan.config.search.limit) {
|
||||||
|
list.splice(window.siyuan.config.search.limit, list.length - window.siyuan.config.search.limit);
|
||||||
|
}
|
||||||
|
// new Set 后需重新赋值
|
||||||
|
window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][type] = list;
|
||||||
|
setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const saveAssetKeyList = (inputElement:HTMLInputElement) => {
|
||||||
|
if (!inputElement.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHASSET].keys;
|
||||||
|
list.splice(0, 0, inputElement.value);
|
||||||
|
list = Array.from(new Set(list));
|
||||||
|
if (list.length > window.siyuan.config.search.limit) {
|
||||||
|
list.splice(window.siyuan.config.search.limit, list.length - window.siyuan.config.search.limit);
|
||||||
|
}
|
||||||
|
window.siyuan.storage[Constants.LOCAL_SEARCHASSET].k = inputElement.value;
|
||||||
|
window.siyuan.storage[Constants.LOCAL_SEARCHASSET].keys = list;
|
||||||
|
setStorageVal(Constants.LOCAL_SEARCHASSET, window.siyuan.storage[Constants.LOCAL_SEARCHASSET]);
|
||||||
|
}
|
||||||
|
@ -50,19 +50,7 @@ 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";
|
||||||
import {toggleAssetHistory, toggleReplaceHistory, toggleSearchHistory} from "./toggleHistory";
|
import {saveKeyList, toggleAssetHistory, toggleReplaceHistory, toggleSearchHistory} from "./toggleHistory";
|
||||||
|
|
||||||
const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
|
|
||||||
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][type];
|
|
||||||
list.splice(0, 0, value);
|
|
||||||
list = Array.from(new Set(list));
|
|
||||||
if (list.length > window.siyuan.config.search.limit) {
|
|
||||||
list.splice(window.siyuan.config.search.limit, list.length - window.siyuan.config.search.limit);
|
|
||||||
}
|
|
||||||
// new Set 后需重新赋值
|
|
||||||
window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][type] = list;
|
|
||||||
setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const openGlobalSearch = (app: App, text: string, replace: boolean, searchData?: Config.IUILayoutTabSearchConfig) => {
|
export const openGlobalSearch = (app: App, text: string, replace: boolean, searchData?: Config.IUILayoutTabSearchConfig) => {
|
||||||
text = text.trim();
|
text = text.trim();
|
||||||
|
Loading…
Reference in New Issue
Block a user