Skip to content

Commit

Permalink
Merge remote-tracking branch 'forke-siyuan/dev' into v0.35
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Jun 9, 2024
2 parents 481e7f1 + 65042ab commit dea697d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 100 deletions.
112 changes: 52 additions & 60 deletions app/src/search/spread.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {getNotebookName, pathPosix} from "../util/pathName";
import {Constants} from "../constants";
import {Dialog} from "../dialog";
import {fetchSyncPost} from "../util/fetch";
import {fetchPost, fetchSyncPost} from "../util/fetch";
import {focusByRange} from "../protyle/util/selection";
import {genSearch} from "./util";
import {genSearch, updateConfig} from "./util";
import type {App} from "../index";

export const openSearch = async (options: {
Expand All @@ -14,49 +14,6 @@ export const openSearch = async (options: {
searchPath?: string
}) => {
window.sout.tracker("invoked");
// 全局搜索中使用 ctrl+F 需继续执行 https://ld246.com/article/1716632837934
let globalToPath = false;
const exitDialog = window.siyuan.dialogs.find((item) => {
if (item.element.querySelector("#searchList")) {
const lastKey = item.element.getAttribute("data-key");
if (lastKey === Constants.DIALOG_GLOBALSEARCH && options.hotkey === Constants.DIALOG_SEARCH) {
globalToPath = true;
}
const replaceHeaderElement = item.element.querySelectorAll(".search__header")[1];
if (lastKey !== options.hotkey && options.hotkey === Constants.DIALOG_REPLACE && replaceHeaderElement.classList.contains("fn__none")) {
replaceHeaderElement.classList.remove("fn__none");
item.element.setAttribute("data-key", options.hotkey);
return true;
}
const searchPathElement = item.element.querySelector("#searchPathInput");
if (lastKey !== options.hotkey && options.hotkey === Constants.DIALOG_GLOBALSEARCH) {
if (searchPathElement.textContent !== "") {
item.destroy();
return false;
} else if (!replaceHeaderElement.classList.contains("fn__none")) {
replaceHeaderElement.classList.add("fn__none");
item.element.setAttribute("data-key", options.hotkey);
return true;
}
}
if (lastKey !== options.hotkey && options.hotkey === Constants.DIALOG_SEARCH) {
if (searchPathElement.textContent === "") {
item.destroy();
return false;
} else if (!replaceHeaderElement.classList.contains("fn__none")) {
replaceHeaderElement.classList.add("fn__none");
item.element.setAttribute("data-key", options.hotkey);
return true;
}
}
// 切换关闭
item.destroy();
return true;
}
});
if (exitDialog && !globalToPath) {
return;
}
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
let hPath = "";
let idPath: string[] = [];
Expand All @@ -80,7 +37,56 @@ export const openSearch = async (options: {
idPath = localData.idPath;
}
}

const config = {
removed: localData.removed,
k: options.key || localData.k,
r: localData.r,
hasReplace: options.hotkey === Constants.DIALOG_REPLACE,
method: localData.method,
hPath,
idPath,
group: localData.group,
sort: localData.sort,
types: Object.assign({}, localData.types),
replaceTypes: Object.assign({}, localData.replaceTypes),
page: options.key ? 1 : localData.page
};
// 搜索中继续执行 ctrl+F/P 不退出 https://github.com/siyuan-note/siyuan/issues/11637
const exitDialog = window.siyuan.dialogs.find((item) => {
// 再次打开
if (item.element.querySelector("#searchList")) {
const searchElement = item.element.querySelector(".b3-dialog__body")
const cloneData = JSON.parse(JSON.stringify(item.data)) as Config.IUILayoutTabSearchConfig;
const selectText = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0).toString() : undefined;
if (selectText) {
cloneData.k = selectText;
}
item.element.setAttribute("data-key", options.hotkey);
if (options.hotkey === Constants.DIALOG_REPLACE) {
cloneData.hasReplace = true;
updateConfig(searchElement, cloneData, item.data, item.editors.edit);
} else if (options.hotkey === Constants.DIALOG_GLOBALSEARCH) {
cloneData.hasReplace = false;
cloneData.hPath = "";
cloneData.idPath = [];
updateConfig(searchElement, cloneData, item.data, item.editors.edit);
} else if (options.hotkey === Constants.DIALOG_SEARCH) {
cloneData.hasReplace = false;
const toPath = item.editors.edit.protyle.path
fetchPost("/api/filetree/getHPathsByPaths", {paths: [toPath]}, (response) => {
cloneData.idPath = [pathPosix().join(item.editors.edit.protyle.notebookId, toPath)];
cloneData.hPath = response.data[0];
item.data.idPath = cloneData.idPath
item.data.hPath = cloneData.hPath
updateConfig(searchElement, cloneData, item.data, item.editors.edit);
});
}
return true;
}
});
if (exitDialog) {
return;
}
let range: Range;
if (getSelection().rangeCount > 0) {
range = getSelection().getRangeAt(0);
Expand Down Expand Up @@ -108,20 +114,6 @@ export const openSearch = async (options: {
}
});
dialog.element.setAttribute("data-key", options.hotkey);
const config = {
removed: localData.removed,
k: options.key || localData.k,
r: localData.r,
hasReplace: options.hotkey === Constants.DIALOG_REPLACE,
method: localData.method,
hPath,
idPath,
group: localData.group,
sort: localData.sort,
types: Object.assign({}, localData.types),
replaceTypes: Object.assign({}, localData.replaceTypes),
page: options.key ? 1 : localData.page
};
dialog.editors = genSearch(options.app, config, dialog.element.querySelector(".b3-dialog__body"), () => {
dialog.destroy({focus: "false"});
});
Expand Down
2 changes: 1 addition & 1 deletion app/src/search/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ export const getQueryTip = (method: number) => {
return methodTip;
};

const updateConfig = (element: Element, item: Config.IUILayoutTabSearchConfig, config: Config.IUILayoutTabSearchConfig,
export const updateConfig = (element: Element, item: Config.IUILayoutTabSearchConfig, config: Config.IUILayoutTabSearchConfig,
edit: Protyle, clear = false) => {
window.sout.tracker("invoked");
const dialogElement = hasClosestByClassName(element, "b3-dialog--open");
Expand Down
3 changes: 2 additions & 1 deletion app/src/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ declare namespace Config {
* - `1`: Group by document
*/
group: number;
hasReplace: any;
hasReplace: boolean;
/**
* Readable path list
*/
Expand Down Expand Up @@ -1961,6 +1961,7 @@ declare namespace Config {
r: string;
/**
* Whether to clear the search box after removing the currently used query condition group
* 移除后需记录搜索内容 https://github.com/siyuan-note/siyuan/issues/7745
*/
removed?: boolean;
replaceTypes: IUILayoutTabSearchConfigReplaceTypes;
Expand Down
38 changes: 0 additions & 38 deletions app/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,44 +270,6 @@ interface ISearchAssetOption {
k: string,
}

interface ISearchOption {
page: number
removed?: boolean // 移除后需记录搜索内容 https://github.com/siyuan-note/siyuan/issues/7745
name?: string
sort: number, // 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时),6:按相关度升序,7:按相关度降序
group: number, // 0:不分组,1:按文档分组
hasReplace: boolean,
method: number // 0:文本,1:查询语法,2:SQL,3:正则表达式
hPath: string
idPath: string[]
k: string
r: string
types: ISearchType,
replaceTypes: {
[key: string]: boolean;
},
}

interface ISearchType {
audioBlock: boolean
videoBlock: boolean
iframeBlock: boolean
widgetBlock: boolean
mathBlock: boolean
table: boolean
blockquote: boolean
superBlock: boolean
paragraph: boolean
document: boolean
heading: boolean
list: boolean
listItem: boolean
codeBlock: boolean
htmlBlock: boolean
embedBlock: boolean
databaseBlock: boolean
}

interface ITextOption {
color?: string,
type: string
Expand Down

0 comments on commit dea697d

Please sign in to comment.