This commit is contained in:
Vanessa 2022-12-25 11:47:31 +08:00
parent ec00af7334
commit 0153d9b8d7
4 changed files with 19 additions and 43 deletions

View file

@ -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";

View file

@ -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, () => {

View file

@ -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 = `<div class="fn__flex-column" style="height: 100%;${closeCB ? "border-radius: 4px;overflow: hidden;" : ""}">
<div class="b3-form__icon search__header">
<span class="fn__a" id="searchHistoryBtn">
@ -181,7 +181,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
</span>
</div>
</div>
<div class="search__layout${config.layout === 1 ? " search__layout--row" : ""}">
<div class="search__layout${data.layout === 1 ? " search__layout--row" : ""}">
<div id="searchList" class="fn__flex-1 search__list b3-list b3-list--background"></div>
<div class="search__drag"></div>
<div id="searchPreview" class="fn__flex-1 search__preview"></div>
@ -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");

View file

@ -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查询语法2SQL3正则表达式
hPath: string