mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-16 00:50:56 +08:00
This commit is contained in:
parent
39cd4379df
commit
e6304e1d24
@ -1,4 +1,6 @@
|
||||
{
|
||||
"enterNew": "Enter to create",
|
||||
"enterNewTip": "No documents found, Enter to create a new document.",
|
||||
"searchTip1": "to navigate",
|
||||
"searchTip2": "to open",
|
||||
"searchTip3": "to switch to the next hit",
|
||||
|
@ -1,4 +1,6 @@
|
||||
{
|
||||
"enterNew": "Ingresar para crear",
|
||||
"enterNewTip": "No se encontraron documentos, ingrese para crear un nuevo documento.",
|
||||
"searchTip1": "para navegar",
|
||||
"searchTip2": "para abrir",
|
||||
"searchTip3": "para cambiar al siguiente resultado",
|
||||
|
@ -1,4 +1,6 @@
|
||||
{
|
||||
"enterNew": "Entrez pour créer",
|
||||
"enterNewTip": "Aucun document trouvé, entrez pour créer un nouveau document.",
|
||||
"searchTip1": "pour naviguer",
|
||||
"searchTip2": "pour ouvrir",
|
||||
"searchTip3": "pour passer au résultat suivant",
|
||||
|
@ -1,4 +1,6 @@
|
||||
{
|
||||
"enterNew": "回車創建",
|
||||
"enterNewTip": "搜索結果為空,回車創建新文檔",
|
||||
"searchTip1": "導航",
|
||||
"searchTip2": "打開",
|
||||
"searchTip3": "切換到下一個命中",
|
||||
|
@ -1,4 +1,6 @@
|
||||
{
|
||||
"enterNew": "回车创建",
|
||||
"enterNewTip": "搜索结果为空,回车创建新文档",
|
||||
"searchTip1": "导航",
|
||||
"searchTip2": "打开",
|
||||
"searchTip3": "切换到下一个命中",
|
||||
|
@ -185,4 +185,11 @@
|
||||
margin: 2px 4px 0 16px;
|
||||
}
|
||||
}
|
||||
|
||||
&__empty {
|
||||
text-align: center;
|
||||
font-size: 17px;
|
||||
padding: 32px;
|
||||
color: var(--b3-theme-on-surface);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,10 @@ import {unicode2Emoji} from "../emoji";
|
||||
import {Dialog} from "../dialog";
|
||||
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
||||
import {replaceFileName} from "../editor/rename";
|
||||
import {hideElements} from "../protyle/ui/hideElements";
|
||||
import {getNewFilePath} from "../util/newFile";
|
||||
import {matchHotKey} from "../protyle/util/hotKey";
|
||||
|
||||
const appendCriteria = (element: HTMLElement, data: ISearchOption[]) => {
|
||||
fetchPost("/api/storage/getCriteria", {}, (response) => {
|
||||
@ -92,6 +96,24 @@ export const openGlobalSearch = (text: string, replace: boolean) => {
|
||||
wnd.split("lr").addTab(tab);
|
||||
setPanelFocus(tab.panelElement);
|
||||
};
|
||||
|
||||
const newEmptyFileByInput = (value: string) => {
|
||||
const newData = getNewFilePath(true)
|
||||
fetchPost("/api/filetree/getHPathByPath", {
|
||||
notebook: newData.notebookId,
|
||||
path: newData.currentPath,
|
||||
}, (responsePath) => {
|
||||
fetchPost("/api/filetree/createDocWithMd", {
|
||||
notebook: newData.notebookId,
|
||||
path: pathPosix().join(responsePath.data, replaceFileName(value.trim()) || "Untitled"),
|
||||
markdown: ""
|
||||
}, response => {
|
||||
hideElements(["dialog"]);
|
||||
openFileById({id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// closeCB 不存在为页签搜索
|
||||
export const genSearch = (config: ISearchOption, element: Element, closeCB?: () => void) => {
|
||||
let methodText = window.siyuan.languages.keyword;
|
||||
@ -529,6 +551,8 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
||||
} else if (target.parentElement.id === "replaceHistoryList") {
|
||||
replaceInputElement.value = target.textContent;
|
||||
replaceHistoryElement.classList.add("fn__none");
|
||||
} else if (target.getAttribute("data-type") === "search-new") {
|
||||
newEmptyFileByInput(searchInputElement.value)
|
||||
} else if (target.getAttribute("data-type") === "search-item") {
|
||||
if (event.detail === 1) {
|
||||
clickTimeout = window.setTimeout(() => {
|
||||
@ -611,6 +635,35 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
||||
if (!currentList || event.isComposing) {
|
||||
return;
|
||||
}
|
||||
const focusIsNew = currentList.getAttribute("data-type") === "search-new"
|
||||
if (focusIsNew && matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
|
||||
newEmptyFileByInput(searchInputElement.value);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (event.key === "Enter") {
|
||||
if (focusIsNew) {
|
||||
newEmptyFileByInput(searchInputElement.value)
|
||||
} else {
|
||||
const id = currentList.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();
|
||||
}
|
||||
});
|
||||
}
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (focusIsNew) {
|
||||
return;
|
||||
}
|
||||
if (event.key === "ArrowDown") {
|
||||
currentList.classList.remove("b3-list-item--focus");
|
||||
if (!currentList.nextElementSibling) {
|
||||
@ -663,19 +716,6 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
||||
edit
|
||||
});
|
||||
event.preventDefault();
|
||||
} else if (event.key === "Enter") {
|
||||
const id = currentList.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();
|
||||
}
|
||||
});
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
replaceInputElement.addEventListener("keydown", (event: KeyboardEvent) => {
|
||||
@ -1413,5 +1453,15 @@ ${unicode2Emoji(item.ial.icon, false, "b3-list-item__graphic", true)}
|
||||
edit.protyle.element.classList.add("fn__none");
|
||||
element.querySelector(".search__drag").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-item b3-list-item--focus" data-type="search-new">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconFile"></use></svg>
|
||||
<span class="b3-list-item__text">
|
||||
${window.siyuan.languages.newFile} <mark>${(element.querySelector("#searchInput") as HTMLInputElement).value}</mark>
|
||||
</span>
|
||||
<kbd class="b3-list-item__meta">${window.siyuan.languages.enterNew}</kbd>
|
||||
</div>
|
||||
<div class="search__empty">
|
||||
${window.siyuan.languages.enterNewTip}
|
||||
</div>`;
|
||||
};
|
||||
|
@ -11,42 +11,38 @@ import {getDisplayName, getOpenNotebookCount, pathPosix} from "./pathName";
|
||||
import {Constants} from "../constants";
|
||||
import {validateName} from "../editor/rename";
|
||||
|
||||
export const newFile = (notebookId?: string, currentPath?: string, paths?: string[], useSavePath = false) => {
|
||||
if (getOpenNotebookCount() === 0) {
|
||||
showMessage(window.siyuan.languages.newFileTip);
|
||||
return;
|
||||
}
|
||||
export const getNewFilePath = (useSavePath: boolean) => {
|
||||
let notebookId = ""
|
||||
let currentPath = ""
|
||||
/// #if !MOBILE
|
||||
if (!notebookId) {
|
||||
getAllModels().editor.find((item) => {
|
||||
const currentElement = item.parent.headElement;
|
||||
if (currentElement.classList.contains("item--focus")) {
|
||||
notebookId = item.editor.protyle.notebookId;
|
||||
if (useSavePath) {
|
||||
currentPath = item.editor.protyle.path;
|
||||
} else {
|
||||
currentPath = pathPosix().dirname(item.editor.protyle.path);
|
||||
}
|
||||
if (hasClosestByClassName(currentElement, "layout__wnd--active")) {
|
||||
return true;
|
||||
}
|
||||
getAllModels().editor.find((item) => {
|
||||
const currentElement = item.parent.headElement;
|
||||
if (currentElement.classList.contains("item--focus")) {
|
||||
notebookId = item.editor.protyle.notebookId;
|
||||
if (useSavePath) {
|
||||
currentPath = item.editor.protyle.path;
|
||||
} else {
|
||||
currentPath = pathPosix().dirname(item.editor.protyle.path);
|
||||
}
|
||||
});
|
||||
if (!notebookId) {
|
||||
const fileModel = getDockByType("file").data.file;
|
||||
if (fileModel instanceof Files) {
|
||||
const currentElement = fileModel.element.querySelector(".b3-list-item--focus");
|
||||
if (currentElement) {
|
||||
const topElement = hasTopClosestByTag(currentElement, "UL");
|
||||
if (topElement) {
|
||||
notebookId = topElement.getAttribute("data-url");
|
||||
}
|
||||
const selectPath = currentElement.getAttribute("data-path");
|
||||
if (useSavePath) {
|
||||
currentPath = selectPath;
|
||||
} else {
|
||||
currentPath = pathPosix().dirname(selectPath);
|
||||
}
|
||||
if (hasClosestByClassName(currentElement, "layout__wnd--active")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!notebookId) {
|
||||
const fileModel = getDockByType("file").data.file;
|
||||
if (fileModel instanceof Files) {
|
||||
const currentElement = fileModel.element.querySelector(".b3-list-item--focus");
|
||||
if (currentElement) {
|
||||
const topElement = hasTopClosestByTag(currentElement, "UL");
|
||||
if (topElement) {
|
||||
notebookId = topElement.getAttribute("data-url");
|
||||
}
|
||||
const selectPath = currentElement.getAttribute("data-path");
|
||||
if (useSavePath) {
|
||||
currentPath = selectPath;
|
||||
} else {
|
||||
currentPath = pathPosix().dirname(selectPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,6 +57,19 @@ export const newFile = (notebookId?: string, currentPath?: string, paths?: strin
|
||||
}
|
||||
});
|
||||
}
|
||||
return {notebookId, currentPath}
|
||||
}
|
||||
|
||||
export const newFile = (notebookId?: string, currentPath?: string, paths?: string[], useSavePath = false) => {
|
||||
if (getOpenNotebookCount() === 0) {
|
||||
showMessage(window.siyuan.languages.newFileTip);
|
||||
return;
|
||||
}
|
||||
if (!notebookId) {
|
||||
const resultData = getNewFilePath(useSavePath)
|
||||
notebookId = resultData.notebookId;
|
||||
currentPath = resultData.currentPath;
|
||||
}
|
||||
fetchPost("/api/filetree/getDocCreateSavePath", {notebook: notebookId}, (data) => {
|
||||
if (data.data.path.indexOf("/") > -1 && useSavePath) {
|
||||
if (data.data.path.startsWith("/") || currentPath === "/") {
|
||||
|
Loading…
Reference in New Issue
Block a user