From bd59d77a769371771aaaca36857df727cf70cb48 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 18 Aug 2023 12:09:55 +0800 Subject: [PATCH] :art: asset search --- app/src/assets/scss/protyle/_wysiwyg.scss | 2 +- app/src/constants.ts | 3 +++ app/src/protyle/util/compatibility.ts | 11 ++++------- app/src/search/assets.ts | 24 ++++++++--------------- app/src/search/util.ts | 2 +- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/app/src/assets/scss/protyle/_wysiwyg.scss b/app/src/assets/scss/protyle/_wysiwyg.scss index 00ef6ac3d..d5bbff5e0 100644 --- a/app/src/assets/scss/protyle/_wysiwyg.scss +++ b/app/src/assets/scss/protyle/_wysiwyg.scss @@ -216,7 +216,7 @@ } .def--mark { - background-color: var(--b3-protyle-inline-mark-background); + background-color: var(--b3-theme-secondary); } span[data-type~="block-ref"], diff --git a/app/src/constants.ts b/app/src/constants.ts index 1aa9378f6..ac164f56d 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -491,6 +491,9 @@ export abstract class Constants { public static readonly SIYUAN_ASSETS_AUDIO: string[] = [".mp3", ".wav", ".ogg", ".m4a"]; public static readonly SIYUAN_ASSETS_VIDEO: string[] = [".mov", ".weba", ".mkv", ".mp4", ".webm"]; public static readonly SIYUAN_ASSETS_EXTS: string[] = [".pdf"].concat(Constants.SIYUAN_ASSETS_IMAGE).concat(Constants.SIYUAN_ASSETS_AUDIO).concat(Constants.SIYUAN_ASSETS_VIDEO); + public static readonly SIYUAN_ASSETS_SEARCH: string[] = [".txt", ".md", ".markdown", ".docx", ".xlsx", ".pptx", ".pdf", ".json", ".log", ".sql", ".html", ".xml", ".java", ".h", ".c", + ".cpp", ".go", ".rs", ".swift", ".kt", ".py", ".php", ".js", ".css", ".ts", ".sh", ".bat", ".cmd", ".ini", ".yaml", + ".rst", ".adoc", ".textile", ".opml", ".org", ".wiki"]; // protyle public static readonly SIYUAN_CONFIG_APPEARANCE_DARK_CODE: string[] = ["a11y-dark", "agate", "an-old-hope", "androidstudio", diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts index 2114532a5..38be59ba7 100644 --- a/app/src/protyle/util/compatibility.ts +++ b/app/src/protyle/util/compatibility.ts @@ -154,16 +154,13 @@ export const getLocalStorage = (cb: () => void) => { row: "", layout: 0, method: 0, - types: { - ".txt": true, - ".md": true, - ".docx": true, - ".xlsx": true, - ".pptx": true, - }, + types: {}, sort: 0, k: "", }; + Constants.SIYUAN_ASSETS_SEARCH.forEach(type => { + defaultStorage[Constants.LOCAL_SEARCHASSET].types[type] = true + }) defaultStorage[Constants.LOCAL_SEARCHKEYS] = { keys: [], replaceKeys: [], diff --git a/app/src/search/assets.ts b/app/src/search/assets.ts index e07703463..1892d8ee0 100644 --- a/app/src/search/assets.ts +++ b/app/src/search/assets.ts @@ -69,7 +69,7 @@ export const openSearchAsset = (element: Element, isStick: boolean) => {
-
+
↑/↓ ${window.siyuan.languages.searchTip1} ${enterTip} Esc ${window.siyuan.languages.searchTip5} @@ -357,35 +357,27 @@ export const assetMethodMenu = (target: HTMLElement, cb: () => void) => { window.siyuan.menus.menu.popup({x: rect.right, y: rect.bottom}, true); }; -let filterTypes: string[] = [ - ".txt", ".md", ".markdown", ".docx", ".xlsx", ".pptx", ".pdf", ".json", ".log", ".sql", ".html", ".xml", ".java", ".h", ".c", - ".cpp", ".go", ".rs", ".swift", ".kt", ".py", ".php", ".js", ".css", ".ts", ".sh", ".bat", ".cmd", ".ini", ".yaml", - ".rst", ".adoc", ".textile", ".opml", ".org", ".wiki", -] - -const filterTypesHTML = (types: string[]) => { - filterTypes = filterTypes.sort((a: string, b: string) => { - return a.localeCompare(b); - }); - +const filterTypesHTML = (types:IObject) => { let html = ""; - types.forEach((type: string) => { + Constants.SIYUAN_ASSETS_SEARCH.sort((a: string, b: string) => { + return a.localeCompare(b); + }).forEach((type: string) => { html += ``; }); return html; -} +}; export const assetFilterMenu = (assetsElement: Element) => { const localData = window.siyuan.storage[Constants.LOCAL_SEARCHASSET].types; const filterDialog = new Dialog({ title: window.siyuan.languages.type, - content: `
` + filterTypesHTML(filterTypes) + `
+ content: `
${filterTypesHTML(localData)}
diff --git a/app/src/search/util.ts b/app/src/search/util.ts index c3103d2d0..6f4725918 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -508,7 +508,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo event.preventDefault(); break; } else if (target.id === "searchAsset") { - openSearchAsset(assetsElement, !!closeCB); + openSearchAsset(assetsElement, !closeCB); event.stopPropagation(); event.preventDefault(); break;