mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-10 22:23:28 +08:00
This commit is contained in:
parent
95e233da95
commit
ac882d6fc9
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"groupBy": "Group By",
|
||||||
"keywordsLimit": "Keywords Limit",
|
"keywordsLimit": "Keywords Limit",
|
||||||
"exportAsImage": "Export as image",
|
"exportAsImage": "Export as image",
|
||||||
"exportBySiYuan": "Export by SiYuan",
|
"exportBySiYuan": "Export by SiYuan",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"groupBy": "Agrupar por",
|
||||||
"keywordsLimit": "Límite de palabras clave",
|
"keywordsLimit": "Límite de palabras clave",
|
||||||
"exportAsImage": "Exportar como imagen",
|
"exportAsImage": "Exportar como imagen",
|
||||||
"exportBySiYuan": "Exportar por SiYuan",
|
"exportBySiYuan": "Exportar por SiYuan",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"groupBy": "Regrouper par",
|
||||||
"keywordsLimit": "Limite de mots clés",
|
"keywordsLimit": "Limite de mots clés",
|
||||||
"exportAsImage": "Exporter en tant qu'image",
|
"exportAsImage": "Exporter en tant qu'image",
|
||||||
"exportBySiYuan": "Exporter par SiYuan",
|
"exportBySiYuan": "Exporter par SiYuan",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"groupBy": "分組",
|
||||||
"keywordsLimit": "關鍵字數量限制",
|
"keywordsLimit": "關鍵字數量限制",
|
||||||
"exportAsImage": "導出為圖片",
|
"exportAsImage": "導出為圖片",
|
||||||
"exportBySiYuan": "由思源筆記導出",
|
"exportBySiYuan": "由思源筆記導出",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"groupBy": "分组",
|
||||||
"keywordsLimit": "关键字数量限制",
|
"keywordsLimit": "关键字数量限制",
|
||||||
"exportAsImage": "导出为图片",
|
"exportAsImage": "导出为图片",
|
||||||
"exportBySiYuan": "由思源笔记导出",
|
"exportBySiYuan": "由思源笔记导出",
|
||||||
|
@ -10,7 +10,7 @@ import {openFileById} from "../editor/util";
|
|||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
import {reloadProtyle} from "../protyle/util/reload";
|
import {reloadProtyle} from "../protyle/util/reload";
|
||||||
import {MenuItem} from "../menus/Menu";
|
import {MenuItem} from "../menus/Menu";
|
||||||
import {getDisplayName, getNotebookName, movePathTo, pathPosix} from "../util/pathName";
|
import {getDisplayName, getNotebookIcon, getNotebookName, movePathTo, pathPosix} from "../util/pathName";
|
||||||
import {Protyle} from "../protyle";
|
import {Protyle} from "../protyle";
|
||||||
import {onGet} from "../protyle/util/onGet";
|
import {onGet} from "../protyle/util/onGet";
|
||||||
import {addLoading} from "../protyle/ui/initUI";
|
import {addLoading} from "../protyle/ui/initUI";
|
||||||
@ -38,7 +38,7 @@ export const openGlobalSearch = (text: string, replace: boolean) => {
|
|||||||
icon: "iconSearch",
|
icon: "iconSearch",
|
||||||
title: text,
|
title: text,
|
||||||
callback(tab) {
|
callback(tab) {
|
||||||
// ctrl+p 仅保存 types, querySyntax, 搜索/替换历史和文本
|
// ctrl+p 仅保存 types, querySyntax, 搜索/替换历史和文本, group
|
||||||
const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}");
|
const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}");
|
||||||
if (!localData.types) {
|
if (!localData.types) {
|
||||||
localData.types = {
|
localData.types = {
|
||||||
@ -64,6 +64,7 @@ export const openGlobalSearch = (text: string, replace: boolean) => {
|
|||||||
querySyntax: localData.querySyntax || false,
|
querySyntax: localData.querySyntax || false,
|
||||||
hPath: "",
|
hPath: "",
|
||||||
idPath: "",
|
idPath: "",
|
||||||
|
group: localData.group || 0,
|
||||||
types: localData.types
|
types: localData.types
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -92,12 +93,16 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
|||||||
<svg><use xlink:href="#iconFolder"></use></svg>
|
<svg><use xlink:href="#iconFolder"></use></svg>
|
||||||
</span>
|
</span>
|
||||||
<span class="fn__space"></span>
|
<span class="fn__space"></span>
|
||||||
<span id="searchRefresh" aria-label="${window.siyuan.languages.refresh}" class="block__icon b3-tooltips b3-tooltips__w">
|
<span id="searchFilter" aria-label="${window.siyuan.languages.type}" class="block__icon b3-tooltips b3-tooltips__w">
|
||||||
<svg><use xlink:href="#iconRefresh"></use></svg>
|
<svg><use xlink:href="#iconFilter"></use></svg>
|
||||||
</span>
|
</span>
|
||||||
<span class="fn__space"></span>
|
<span class="fn__space"></span>
|
||||||
<span id="searchFilter" aria-label="${window.siyuan.languages.type}" class="block__icon b3-tooltips b3-tooltips__w">
|
<span id="searchGroup" aria-label="${window.siyuan.languages.groupBy}" class="block__icon b3-tooltips b3-tooltips__w">
|
||||||
<svg><use xlink:href="#iconSettings"></use></svg>
|
<svg><use xlink:href="#iconFiles"></use></svg>
|
||||||
|
</span>
|
||||||
|
<span class="fn__space"></span>
|
||||||
|
<span id="searchRefresh" aria-label="${window.siyuan.languages.refresh}" class="block__icon b3-tooltips b3-tooltips__w">
|
||||||
|
<svg><use xlink:href="#iconRefresh"></use></svg>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -182,6 +187,12 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
|
} else if (target.id === "searchGroup") {
|
||||||
|
config.group = config.group === 0 ? 1 : 0;
|
||||||
|
inputTimeout = inputEvent(element, config, inputTimeout, edit);
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
break;
|
||||||
} else if (target.id === "searchFilter") {
|
} else if (target.id === "searchFilter") {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
addConfigMenu(config, window.siyuan.languages.math, "mathBlock", edit, element, closeCB);
|
addConfigMenu(config, window.siyuan.languages.math, "mathBlock", edit, element, closeCB);
|
||||||
@ -271,6 +282,12 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
|
} else if (target.classList.contains("b3-list-item__toggle")) {
|
||||||
|
target.parentElement.nextElementSibling.classList.toggle("fn__none");
|
||||||
|
target.firstElementChild.classList.toggle("b3-list-item__arrow");
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
break;
|
||||||
} else if (target.classList.contains("b3-list-item")) {
|
} else if (target.classList.contains("b3-list-item")) {
|
||||||
if (target.parentElement.id === "searchHistoryList") {
|
if (target.parentElement.id === "searchHistoryList") {
|
||||||
searchInputElement.value = target.textContent;
|
searchInputElement.value = target.textContent;
|
||||||
@ -279,62 +296,51 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
|||||||
} else if (target.parentElement.id === "replaceHistoryList") {
|
} else if (target.parentElement.id === "replaceHistoryList") {
|
||||||
replaceInputElement.value = target.textContent;
|
replaceInputElement.value = target.textContent;
|
||||||
replaceHistoryElement.classList.add("fn__none");
|
replaceHistoryElement.classList.add("fn__none");
|
||||||
} else if (target.parentElement.id === "searchList" && !target.classList.contains("b3-list-item--focus")) {
|
} else if (target.getAttribute("data-type") === "search-item") {
|
||||||
target.parentElement.querySelector(".b3-list-item--focus")?.classList.remove("b3-list-item--focus")
|
if (event.detail === 1) {
|
||||||
target.classList.add("b3-list-item--focus")
|
clickTimeout = window.setTimeout(() => {
|
||||||
getArticle({
|
if (event.altKey) {
|
||||||
id: target.getAttribute("data-node-id"),
|
const id = target.getAttribute("data-node-id");
|
||||||
k: getKey(target),
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
edit
|
openFileById({
|
||||||
});
|
id,
|
||||||
}
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
event.stopPropagation();
|
zoomIn: foldResponse.data,
|
||||||
event.preventDefault();
|
position: "right"
|
||||||
break;
|
});
|
||||||
} else if (target.getAttribute("data-type") === "search-item") {
|
if (closeCB) {
|
||||||
if (event.detail === 1) {
|
closeCB();
|
||||||
clickTimeout = window.setTimeout(() => {
|
}
|
||||||
if (window.siyuan.altIsPressed) {
|
|
||||||
const id = target.getAttribute("data-node-id");
|
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
|
||||||
openFileById({
|
|
||||||
id,
|
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
|
||||||
zoomIn: foldResponse.data,
|
|
||||||
position: "right"
|
|
||||||
});
|
});
|
||||||
if (closeCB) {
|
} else if (!target.classList.contains("b3-list-item--focus")) {
|
||||||
closeCB();
|
searchPanelElement.querySelector(".b3-list-item--focus").classList.remove("b3-list-item--focus");
|
||||||
}
|
target.classList.add("b3-list-item--focus");
|
||||||
|
getArticle({
|
||||||
|
edit,
|
||||||
|
id: target.getAttribute("data-node-id"),
|
||||||
|
k: getKey(target)
|
||||||
|
});
|
||||||
|
searchInputElement.focus();
|
||||||
|
}
|
||||||
|
}, Constants.TIMEOUT_DBLCLICK);
|
||||||
|
} else if (event.detail === 2) {
|
||||||
|
clearTimeout(clickTimeout);
|
||||||
|
const id = target.getAttribute("data-node-id");
|
||||||
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
|
openFileById({
|
||||||
|
id,
|
||||||
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
zoomIn: foldResponse.data
|
||||||
});
|
});
|
||||||
} else {
|
if (closeCB) {
|
||||||
searchPanelElement.querySelector(".b3-list-item--focus").classList.remove("b3-list-item--focus");
|
closeCB();
|
||||||
target.classList.add("b3-list-item--focus");
|
}
|
||||||
getArticle({
|
|
||||||
edit,
|
|
||||||
id: target.getAttribute("data-node-id"),
|
|
||||||
k: getKey(target)
|
|
||||||
});
|
|
||||||
searchInputElement.focus();
|
|
||||||
}
|
|
||||||
}, Constants.TIMEOUT_DBLCLICK);
|
|
||||||
} else if (event.detail === 2) {
|
|
||||||
clearTimeout(clickTimeout);
|
|
||||||
const id = target.getAttribute("data-node-id");
|
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
|
||||||
openFileById({
|
|
||||||
id,
|
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
|
||||||
zoomIn: foldResponse.data
|
|
||||||
});
|
});
|
||||||
if (closeCB) {
|
}
|
||||||
closeCB();
|
window.siyuan.menus.menu.remove();
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
window.siyuan.menus.menu.remove();
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
target = target.parentElement;
|
target = target.parentElement;
|
||||||
@ -591,7 +597,8 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
|
|||||||
query: inputValue,
|
query: inputValue,
|
||||||
querySyntax: config.querySyntax,
|
querySyntax: config.querySyntax,
|
||||||
types: config.types,
|
types: config.types,
|
||||||
path: config.idPath || ""
|
path: config.idPath || "",
|
||||||
|
groupBy: config.group, // 0:不分组,1:按文档分组
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
onSearch(response.data.blocks, edit, element);
|
onSearch(response.data.blocks, edit, element);
|
||||||
element.querySelector("#searchResult").innerHTML = window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount);
|
element.querySelector("#searchResult").innerHTML = window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount);
|
||||||
@ -605,33 +612,50 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
|
|||||||
const onSearch = (data: IBlock[], edit: Protyle, element: Element) => {
|
const onSearch = (data: IBlock[], edit: Protyle, element: Element) => {
|
||||||
let resultHTML = "";
|
let resultHTML = "";
|
||||||
data.forEach((item, index) => {
|
data.forEach((item, index) => {
|
||||||
const title = escapeHtml(getNotebookName(item.box)) + getDisplayName(item.hPath, false);
|
if (item.children) {
|
||||||
resultHTML += `<div data-type="search-item" class="b3-list-item${index === 0 ? " b3-list-item--focus" : ""}" data-node-id="${item.id}" data-root-id="${item.rootID}">
|
resultHTML += `<div class="b3-list-item">
|
||||||
|
<span class="b3-list-item__toggle b3-list-item__toggle--hl">
|
||||||
|
<svg class="b3-list-item__arrow b3-list-item__arrow--open"><use xlink:href="#iconRight"></use></svg>
|
||||||
|
</span>
|
||||||
|
<span class="b3-list-item__text ft__on-surface">${unicode2Emoji(getNotebookIcon(item.box) || Constants.SIYUAN_IMAGE_NOTE)}${escapeHtml(getNotebookName(item.box))}/${unicode2Emoji(item.ial.icon)}${item.ial.icon ? " " : ""}${item.content}</span>
|
||||||
|
</div><div>`;
|
||||||
|
item.children.forEach((childItem, childIndex) => {
|
||||||
|
resultHTML += `<div style="padding-left: 22px" data-type="search-item" class="b3-list-item${childIndex === 0 ? " b3-list-item--focus" : ""}" data-node-id="${childItem.id}" data-root-id="${childItem.rootID}">
|
||||||
|
<svg class="b3-list-item__graphic"><use xlink:href="#${getIconByType(childItem.type)}"></use></svg>
|
||||||
|
<span class="b3-list-item__text">${unicode2Emoji(childItem.ial.icon)}${childItem.ial.icon ? " " : ""}${childItem.content}</span>
|
||||||
|
</div>`;
|
||||||
|
})
|
||||||
|
resultHTML += "</div>";
|
||||||
|
} else {
|
||||||
|
const title = escapeHtml(getNotebookName(item.box)) + getDisplayName(item.hPath, false);
|
||||||
|
resultHTML += `<div data-type="search-item" class="b3-list-item${index === 0 ? " b3-list-item--focus" : ""}" data-node-id="${item.id}" data-root-id="${item.rootID}">
|
||||||
<svg class="b3-list-item__graphic"><use xlink:href="#${getIconByType(item.type)}"></use></svg>
|
<svg class="b3-list-item__graphic"><use xlink:href="#${getIconByType(item.type)}"></use></svg>
|
||||||
<span class="b3-list-item__text">${unicode2Emoji(item.ial.icon)}${item.ial.icon ? " " : ""}${item.content}</span>
|
<span class="b3-list-item__text">${unicode2Emoji(item.ial.icon)}${item.ial.icon ? " " : ""}${item.content}</span>
|
||||||
<span class="b3-list-item__meta b3-list-item__meta--ellipsis" title="${title}">${title}</span>
|
<span class="b3-list-item__meta b3-list-item__meta--ellipsis" title="${title}">${title}</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data[0]) {
|
if (data[0]) {
|
||||||
if (edit) {
|
edit.protyle.element.classList.remove("fn__none");
|
||||||
edit.protyle.element.classList.remove("fn__none");
|
|
||||||
} else {
|
|
||||||
element.querySelector("#searchPreview").classList.remove("fn__none");
|
|
||||||
}
|
|
||||||
const contentElement = document.createElement("div");
|
const contentElement = document.createElement("div");
|
||||||
contentElement.innerHTML = data[0].content;
|
if (data[0].children) {
|
||||||
getArticle({
|
contentElement.innerHTML = data[0].children[0].content;
|
||||||
edit,
|
getArticle({
|
||||||
id: data[0].id,
|
edit,
|
||||||
k: getKey(contentElement),
|
id: data[0].children[0].id,
|
||||||
});
|
k: getKey(contentElement),
|
||||||
} else {
|
});
|
||||||
if (edit) {
|
|
||||||
edit.protyle.element.classList.add("fn__none");
|
|
||||||
} else {
|
} else {
|
||||||
element.querySelector("#searchPreview").classList.add("fn__none");
|
contentElement.innerHTML = data[0].content;
|
||||||
|
getArticle({
|
||||||
|
edit,
|
||||||
|
id: data[0].id,
|
||||||
|
k: getKey(contentElement),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
edit.protyle.element.classList.add("fn__none");
|
||||||
}
|
}
|
||||||
element.querySelector("#searchList").innerHTML = resultHTML || `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`;
|
element.querySelector("#searchList").innerHTML = resultHTML || `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`;
|
||||||
};
|
};
|
||||||
|
1
app/src/types/index.d.ts
vendored
1
app/src/types/index.d.ts
vendored
@ -49,6 +49,7 @@ interface Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ISearchOption {
|
interface ISearchOption {
|
||||||
|
group: number,
|
||||||
hasReplace: boolean,
|
hasReplace: boolean,
|
||||||
querySyntax: boolean,
|
querySyntax: boolean,
|
||||||
hPath: string
|
hPath: string
|
||||||
|
@ -431,6 +431,17 @@ export const getNotebookName = (id: string) => {
|
|||||||
return rootPath;
|
return rootPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getNotebookIcon = (id: string) => {
|
||||||
|
let rootPath = "";
|
||||||
|
window.siyuan.notebooks.find((item) => {
|
||||||
|
if (item.id === id) {
|
||||||
|
rootPath = item.icon;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return rootPath;
|
||||||
|
};
|
||||||
|
|
||||||
export const setNotebookName = (id: string, name: string) => {
|
export const setNotebookName = (id: string, name: string) => {
|
||||||
window.siyuan.notebooks.find((item) => {
|
window.siyuan.notebooks.find((item) => {
|
||||||
if (item.id === id) {
|
if (item.id === id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user