mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-03 15:28:49 +01:00
This commit is contained in:
parent
7e6fb4edee
commit
134292dbc6
3 changed files with 28 additions and 25 deletions
|
|
@ -3,7 +3,7 @@ import {fetchPost} from "../util/fetch";
|
|||
import {escapeAriaLabel} from "../util/escape";
|
||||
import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
||||
/// #if !MOBILE
|
||||
import {getQueryTip} from "./util";
|
||||
import {genQueryHTML} from "./util";
|
||||
/// #endif
|
||||
import {MenuItem} from "../menus/Menu";
|
||||
import {Dialog} from "../dialog";
|
||||
|
|
@ -57,9 +57,7 @@ export const openSearchAsset = (element: HTMLElement, isStick: boolean) => {
|
|||
<svg><use xlink:href="#iconRefresh"></use></svg>
|
||||
</span>
|
||||
<span class="fn__space"></span>
|
||||
<span id="assetSyntaxCheck" aria-label="${getQueryTip(localSearch.method)}" class="block__icon ariaLabel" data-position="9south">
|
||||
<svg><use xlink:href="#iconRegex"></use></svg>
|
||||
</span>
|
||||
${genQueryHTML(localSearch.method, "assetSyntaxCheck")}
|
||||
<span class="fn__space"></span>
|
||||
<span id="assetFilter" aria-label="${window.siyuan.languages.type}" class="block__icon ariaLabel" data-position="9south">
|
||||
<svg><use xlink:href="#iconFilter"></use></svg>
|
||||
|
|
@ -280,7 +278,7 @@ export const assetMethodMenu = (target: HTMLElement, cb: () => void) => {
|
|||
window.siyuan.menus.menu.remove();
|
||||
window.siyuan.menus.menu.element.setAttribute("data-name", "searchAssetMethod");
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: "",
|
||||
icon: "iconExact",
|
||||
label: window.siyuan.languages.keyword,
|
||||
current: method === 0,
|
||||
click() {
|
||||
|
|
@ -289,7 +287,7 @@ export const assetMethodMenu = (target: HTMLElement, cb: () => void) => {
|
|||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: "",
|
||||
icon: "iconQuote",
|
||||
label: window.siyuan.languages.querySyntax,
|
||||
current: method === 1,
|
||||
click() {
|
||||
|
|
@ -298,7 +296,7 @@ export const assetMethodMenu = (target: HTMLElement, cb: () => void) => {
|
|||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: "",
|
||||
icon: "iconRegex",
|
||||
label: window.siyuan.languages.regex,
|
||||
current: method === 3,
|
||||
click() {
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ export const queryMenu = (config: Config.IUILayoutTabSearchConfig, cb: () => voi
|
|||
window.siyuan.menus.menu.remove();
|
||||
window.siyuan.menus.menu.element.setAttribute("data-name", "searchMethod");
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: "",
|
||||
icon: "iconExact",
|
||||
label: window.siyuan.languages.keyword,
|
||||
current: config.method === 0,
|
||||
click() {
|
||||
|
|
@ -245,7 +245,7 @@ export const queryMenu = (config: Config.IUILayoutTabSearchConfig, cb: () => voi
|
|||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: "",
|
||||
icon: "iconQuote",
|
||||
label: window.siyuan.languages.querySyntax,
|
||||
current: config.method === 1,
|
||||
click() {
|
||||
|
|
@ -254,7 +254,7 @@ export const queryMenu = (config: Config.IUILayoutTabSearchConfig, cb: () => voi
|
|||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: "",
|
||||
icon: "iconDatabase",
|
||||
label: "SQL",
|
||||
current: config.method === 2,
|
||||
click() {
|
||||
|
|
@ -263,7 +263,7 @@ export const queryMenu = (config: Config.IUILayoutTabSearchConfig, cb: () => voi
|
|||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: "",
|
||||
icon: "iconRegex",
|
||||
label: window.siyuan.languages.regex,
|
||||
current: config.method === 3,
|
||||
click() {
|
||||
|
|
|
|||
|
|
@ -157,9 +157,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele
|
|||
<svg><use xlink:href="#iconFilter"></use></svg>
|
||||
</span>
|
||||
<span class="fn__space"></span>
|
||||
<span id="searchSyntaxCheck" aria-label="${window.siyuan.languages.searchMethod} ${methodText}" class="block__icon ariaLabel" data-position="9south">
|
||||
<svg><use xlink:href="#iconRegex"></use></svg>
|
||||
</span>
|
||||
${genQueryHTML(config.method, "searchSyntaxCheck")}
|
||||
<span class="fn__space"></span>
|
||||
<span id="searchReplace" aria-label="${window.siyuan.languages.replace}" class="block__icon ariaLabel" data-position="9south">
|
||||
<svg><use xlink:href="#iconReplace"></use></svg>
|
||||
|
|
@ -739,7 +737,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele
|
|||
break;
|
||||
} else if (target.id === "assetSyntaxCheck") {
|
||||
assetMethodMenu(target, () => {
|
||||
element.querySelector("#assetSyntaxCheck").setAttribute("aria-label", getQueryTip(localSearch.method));
|
||||
element.querySelector("#assetSyntaxCheck").outerHTML = genQueryHTML(localSearch.method, "assetSyntaxCheck");
|
||||
assetInputEvent(assetsElement, localSearch);
|
||||
setStorageVal(Constants.LOCAL_SEARCHASSET, localSearch);
|
||||
});
|
||||
|
|
@ -748,7 +746,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele
|
|||
break;
|
||||
} else if (target.id === "searchSyntaxCheck") {
|
||||
queryMenu(config, () => {
|
||||
element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", getQueryTip(config.method));
|
||||
element.querySelector("#searchSyntaxCheck").outerHTML = genQueryHTML(config.method, "searchSyntaxCheck");
|
||||
config.page = 1;
|
||||
inputEvent(element, config, edit, true);
|
||||
});
|
||||
|
|
@ -932,23 +930,30 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele
|
|||
return {edit, unRefEdit};
|
||||
};
|
||||
|
||||
export const getQueryTip = (method: number) => {
|
||||
let methodTip = window.siyuan.languages.searchMethod + " ";
|
||||
export const genQueryHTML = (method: number, id: string) => {
|
||||
let methodTip = "";
|
||||
let methodIcon = "";
|
||||
switch (method) {
|
||||
case 0:
|
||||
methodTip += window.siyuan.languages.keyword;
|
||||
methodTip = window.siyuan.languages.keyword;
|
||||
methodIcon = "Exact";
|
||||
break;
|
||||
case 1:
|
||||
methodTip += window.siyuan.languages.querySyntax;
|
||||
methodTip = window.siyuan.languages.querySyntax;
|
||||
methodIcon = "Quote";
|
||||
break;
|
||||
case 2:
|
||||
methodTip += "SQL";
|
||||
methodTip = "SQL";
|
||||
methodIcon = "Database";
|
||||
break;
|
||||
case 3:
|
||||
methodTip += window.siyuan.languages.regex;
|
||||
methodTip = window.siyuan.languages.regex;
|
||||
methodIcon = "Regex";
|
||||
break;
|
||||
}
|
||||
return methodTip;
|
||||
return `<span id="${id}" aria-label="${window.siyuan.languages.searchMethod} ${methodTip}" class="block__icon ariaLabel" data-position="9south">
|
||||
<svg><use xlink:href="#icon${methodIcon}"></use></svg>
|
||||
</span>`;
|
||||
};
|
||||
|
||||
export const updateConfig = (element: Element, item: Config.IUILayoutTabSearchConfig, config: Config.IUILayoutTabSearchConfig,
|
||||
|
|
@ -1007,7 +1012,7 @@ export const updateConfig = (element: Element, item: Config.IUILayoutTabSearchCo
|
|||
(element.querySelector("#searchInput") as HTMLInputElement).value = item.k;
|
||||
}
|
||||
(element.querySelector("#replaceInput") as HTMLInputElement).value = item.r;
|
||||
element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", getQueryTip(item.method));
|
||||
element.querySelector("#searchSyntaxCheck").outerHTML = genQueryHTML(item.method, "searchSyntaxCheck");
|
||||
Object.assign(config, item);
|
||||
window.siyuan.storage[Constants.LOCAL_SEARCHDATA] = Object.assign({}, config);
|
||||
setStorageVal(Constants.LOCAL_SEARCHDATA, window.siyuan.storage[Constants.LOCAL_SEARCHDATA]);
|
||||
|
|
@ -1015,7 +1020,7 @@ export const updateConfig = (element: Element, item: Config.IUILayoutTabSearchCo
|
|||
window.siyuan.menus.menu.remove();
|
||||
};
|
||||
|
||||
const scrollToCurrent = (contentElement: HTMLElement,currentRange: Range, contentRect:DOMRect) => {
|
||||
const scrollToCurrent = (contentElement: HTMLElement, currentRange: Range, contentRect: DOMRect) => {
|
||||
contentElement.scrollTop = contentElement.scrollTop + currentRange.getBoundingClientRect().top - contentRect.top - contentRect.height / 2;
|
||||
const tableElement = hasClosestByClassName(currentRange.startContainer, "table");
|
||||
if (tableElement) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue