mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-16 09:00:42 +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",
|
"searchTip1": "to navigate",
|
||||||
"searchTip2": "to open",
|
"searchTip2": "to open",
|
||||||
"searchTip3": "to switch to the next hit",
|
"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",
|
"searchTip1": "para navegar",
|
||||||
"searchTip2": "para abrir",
|
"searchTip2": "para abrir",
|
||||||
"searchTip3": "para cambiar al siguiente resultado",
|
"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",
|
"searchTip1": "pour naviguer",
|
||||||
"searchTip2": "pour ouvrir",
|
"searchTip2": "pour ouvrir",
|
||||||
"searchTip3": "pour passer au résultat suivant",
|
"searchTip3": "pour passer au résultat suivant",
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"enterNew": "回車創建",
|
||||||
|
"enterNewTip": "搜索結果為空,回車創建新文檔",
|
||||||
"searchTip1": "導航",
|
"searchTip1": "導航",
|
||||||
"searchTip2": "打開",
|
"searchTip2": "打開",
|
||||||
"searchTip3": "切換到下一個命中",
|
"searchTip3": "切換到下一個命中",
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"enterNew": "回车创建",
|
||||||
|
"enterNewTip": "搜索结果为空,回车创建新文档",
|
||||||
"searchTip1": "导航",
|
"searchTip1": "导航",
|
||||||
"searchTip2": "打开",
|
"searchTip2": "打开",
|
||||||
"searchTip3": "切换到下一个命中",
|
"searchTip3": "切换到下一个命中",
|
||||||
|
@ -185,4 +185,11 @@
|
|||||||
margin: 2px 4px 0 16px;
|
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 {Dialog} from "../dialog";
|
||||||
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||||
import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
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[]) => {
|
const appendCriteria = (element: HTMLElement, data: ISearchOption[]) => {
|
||||||
fetchPost("/api/storage/getCriteria", {}, (response) => {
|
fetchPost("/api/storage/getCriteria", {}, (response) => {
|
||||||
@ -92,6 +96,24 @@ export const openGlobalSearch = (text: string, replace: boolean) => {
|
|||||||
wnd.split("lr").addTab(tab);
|
wnd.split("lr").addTab(tab);
|
||||||
setPanelFocus(tab.panelElement);
|
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 不存在为页签搜索
|
// closeCB 不存在为页签搜索
|
||||||
export const genSearch = (config: ISearchOption, element: Element, closeCB?: () => void) => {
|
export const genSearch = (config: ISearchOption, element: Element, closeCB?: () => void) => {
|
||||||
let methodText = window.siyuan.languages.keyword;
|
let methodText = window.siyuan.languages.keyword;
|
||||||
@ -529,6 +551,8 @@ 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.getAttribute("data-type") === "search-new") {
|
||||||
|
newEmptyFileByInput(searchInputElement.value)
|
||||||
} else if (target.getAttribute("data-type") === "search-item") {
|
} else if (target.getAttribute("data-type") === "search-item") {
|
||||||
if (event.detail === 1) {
|
if (event.detail === 1) {
|
||||||
clickTimeout = window.setTimeout(() => {
|
clickTimeout = window.setTimeout(() => {
|
||||||
@ -611,6 +635,35 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
|||||||
if (!currentList || event.isComposing) {
|
if (!currentList || event.isComposing) {
|
||||||
return;
|
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") {
|
if (event.key === "ArrowDown") {
|
||||||
currentList.classList.remove("b3-list-item--focus");
|
currentList.classList.remove("b3-list-item--focus");
|
||||||
if (!currentList.nextElementSibling) {
|
if (!currentList.nextElementSibling) {
|
||||||
@ -663,19 +716,6 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
|||||||
edit
|
edit
|
||||||
});
|
});
|
||||||
event.preventDefault();
|
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) => {
|
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");
|
edit.protyle.element.classList.add("fn__none");
|
||||||
element.querySelector(".search__drag").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 {Constants} from "../constants";
|
||||||
import {validateName} from "../editor/rename";
|
import {validateName} from "../editor/rename";
|
||||||
|
|
||||||
export const newFile = (notebookId?: string, currentPath?: string, paths?: string[], useSavePath = false) => {
|
export const getNewFilePath = (useSavePath: boolean) => {
|
||||||
if (getOpenNotebookCount() === 0) {
|
let notebookId = ""
|
||||||
showMessage(window.siyuan.languages.newFileTip);
|
let currentPath = ""
|
||||||
return;
|
|
||||||
}
|
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (!notebookId) {
|
getAllModels().editor.find((item) => {
|
||||||
getAllModels().editor.find((item) => {
|
const currentElement = item.parent.headElement;
|
||||||
const currentElement = item.parent.headElement;
|
if (currentElement.classList.contains("item--focus")) {
|
||||||
if (currentElement.classList.contains("item--focus")) {
|
notebookId = item.editor.protyle.notebookId;
|
||||||
notebookId = item.editor.protyle.notebookId;
|
if (useSavePath) {
|
||||||
if (useSavePath) {
|
currentPath = item.editor.protyle.path;
|
||||||
currentPath = item.editor.protyle.path;
|
} else {
|
||||||
} else {
|
currentPath = pathPosix().dirname(item.editor.protyle.path);
|
||||||
currentPath = pathPosix().dirname(item.editor.protyle.path);
|
|
||||||
}
|
|
||||||
if (hasClosestByClassName(currentElement, "layout__wnd--active")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
if (hasClosestByClassName(currentElement, "layout__wnd--active")) {
|
||||||
if (!notebookId) {
|
return true;
|
||||||
const fileModel = getDockByType("file").data.file;
|
}
|
||||||
if (fileModel instanceof Files) {
|
}
|
||||||
const currentElement = fileModel.element.querySelector(".b3-list-item--focus");
|
});
|
||||||
if (currentElement) {
|
if (!notebookId) {
|
||||||
const topElement = hasTopClosestByTag(currentElement, "UL");
|
const fileModel = getDockByType("file").data.file;
|
||||||
if (topElement) {
|
if (fileModel instanceof Files) {
|
||||||
notebookId = topElement.getAttribute("data-url");
|
const currentElement = fileModel.element.querySelector(".b3-list-item--focus");
|
||||||
}
|
if (currentElement) {
|
||||||
const selectPath = currentElement.getAttribute("data-path");
|
const topElement = hasTopClosestByTag(currentElement, "UL");
|
||||||
if (useSavePath) {
|
if (topElement) {
|
||||||
currentPath = selectPath;
|
notebookId = topElement.getAttribute("data-url");
|
||||||
} else {
|
}
|
||||||
currentPath = pathPosix().dirname(selectPath);
|
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) => {
|
fetchPost("/api/filetree/getDocCreateSavePath", {notebook: notebookId}, (data) => {
|
||||||
if (data.data.path.indexOf("/") > -1 && useSavePath) {
|
if (data.data.path.indexOf("/") > -1 && useSavePath) {
|
||||||
if (data.data.path.startsWith("/") || currentPath === "/") {
|
if (data.data.path.startsWith("/") || currentPath === "/") {
|
||||||
|
Loading…
Reference in New Issue
Block a user