diff --git a/app/src/constants.ts b/app/src/constants.ts index 071f05f5a..ce134069e 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -59,7 +59,7 @@ export abstract class Constants { // localstorage public static readonly LOCAL_SEARCHEDATA = "local-searchedata"; - public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys"; // "keys","col", "row", "replaceKeys" + public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys"; // "keys", "col", "row", "replaceKeys", "layout" public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; diff --git a/app/src/search/spread.ts b/app/src/search/spread.ts index 241258f5c..15b84cbda 100644 --- a/app/src/search/spread.ts +++ b/app/src/search/spread.ts @@ -109,7 +109,6 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri hPath, idPath, group: localData.group || 0, - layout: localData.layout || 0, sort: localData.sort || 0, types: localData.types }, dialog.element.querySelector(".b3-dialog__container").lastElementChild, () => { diff --git a/app/src/search/util.ts b/app/src/search/util.ts index 5bb151c32..479b0084d 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -78,7 +78,6 @@ export const openGlobalSearch = (text: string, replace: boolean) => { hPath: "", idPath: [], group: localData.group || 0, - layout: localData.layout || 0, sort: localData.sort || 0, types: localData.types } @@ -110,6 +109,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () enableIncludeChild = true; } }); + const data = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); element.innerHTML = `
@@ -181,7 +181,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
-
+
@@ -202,9 +202,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () breadcrumbDocName: true }, }); - - const data = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); - if (config.layout === 1) { + if (data.layout === 1) { if (data.col) { edit.protyle.element.style.width = data.col; edit.protyle.element.classList.remove("fn__flex-1"); @@ -227,7 +225,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () const documentSelf = document; const nextElement = dragElement.nextElementSibling as HTMLElement; const previousElement = dragElement.previousElementSibling as HTMLElement; - const direction = config.layout === 1 ? "lr" : "tb"; + const direction = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}").layout === 1 ? "lr" : "tb"; const x = event[direction === "lr" ? "clientX" : "clientY"]; const previousSize = direction === "lr" ? previousElement.clientWidth : previousElement.clientHeight; const nextSize = direction === "lr" ? nextElement.clientWidth : nextElement.clientHeight; @@ -706,40 +704,44 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element: } }] }).element); + const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}") + if (typeof localData.layout === "undefined") { + localData.layout = 0; + } window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.layout, type: "submenu", submenu: [{ label: window.siyuan.languages.topBottomLayout, - current: config.layout === 0, + current: localData.layout === 0, click() { element.querySelector(".search__layout").classList.remove("search__layout--row"); edit.protyle.element.style.width = ""; - const data = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); - if (data.row) { - edit.protyle.element.style.height = data.row; + if (localData.row) { + edit.protyle.element.style.height = localData.row; edit.protyle.element.classList.remove("fn__flex-1"); } else { edit.protyle.element.classList.add("fn__flex-1"); } setPadding(edit.protyle); - config.layout = 0; + localData.layout = 0; + localStorage.setItem(Constants.LOCAL_SEARCHEKEYS, JSON.stringify(localData)); } }, { label: window.siyuan.languages.leftRightLayout, - current: config.layout === 1, + current: localData.layout === 1, click() { element.querySelector(".search__layout").classList.add("search__layout--row"); edit.protyle.element.style.height = ""; - const data = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); - if (data.col) { - edit.protyle.element.style.width = data.col; + if (localData.col) { + edit.protyle.element.style.width = localData.col; edit.protyle.element.classList.remove("fn__flex-1"); } else { edit.protyle.element.classList.add("fn__flex-1"); } setPadding(edit.protyle); - config.layout = 1; + localData.layout = 1; + localStorage.setItem(Constants.LOCAL_SEARCHEKEYS, JSON.stringify(localData)); } }] }).element); @@ -814,7 +816,6 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element: updateConfig(element, { sort: 0, group: 0, - layout: 0, hasReplace: false, method: 0, hPath: "", @@ -847,29 +848,6 @@ const updateConfig = (element: Element, item: ISearchOption, config: ISearchOpti item.hPath = config.hPath; item.idPath = config.idPath.join(",").split(","); } - if (config.layout !== item.layout) { - const data = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); - if (item.layout === 0) { - element.querySelector(".search__layout").classList.remove("search__layout--row"); - if (data.row) { - edit.protyle.element.classList.remove("fn__flex-1"); - edit.protyle.element.style.height = data.row; - edit.protyle.element.style.width = ""; - } else { - edit.protyle.element.classList.add("fn__flex-1"); - } - } else { - element.querySelector(".search__layout").classList.add("search__layout--row"); - if (data.col) { - edit.protyle.element.style.width = data.col; - edit.protyle.element.classList.remove("fn__flex-1"); - edit.protyle.element.style.height = ""; - } else { - edit.protyle.element.classList.add("fn__flex-1"); - } - } - setPadding(edit.protyle); - } if (config.hasReplace !== item.hasReplace) { if (item.hasReplace) { element.querySelector("#replaceHistoryBtn").parentElement.classList.remove("fn__none"); diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index c9d4799f7..da0e5cd0a 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -61,7 +61,6 @@ interface ISearchOption { name?: string sort: number, // 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时),6:按相关度升序,7:按相关度降序 group: number, // 0:不分组,1:按文档分组 - layout: number // 0:上下,1:左右 hasReplace: boolean, method: number // 0:文本,1:查询语法,2:SQL,3:正则表达式 hPath: string