|
@@ -7,19 +7,22 @@ import {Constants} from "../../../constants";
|
|
import {Editor} from "../../../editor";
|
|
import {Editor} from "../../../editor";
|
|
/// #if MOBILE
|
|
/// #if MOBILE
|
|
import {getCurrentEditor} from "../../../mobile/editor";
|
|
import {getCurrentEditor} from "../../../mobile/editor";
|
|
|
|
+import {popSearch} from "../../../mobile/menu/search";
|
|
/// #else
|
|
/// #else
|
|
import {getActiveTab, getDockByType} from "../../../layout/tabUtil";
|
|
import {getActiveTab, getDockByType} from "../../../layout/tabUtil";
|
|
import {Custom} from "../../../layout/dock/Custom";
|
|
import {Custom} from "../../../layout/dock/Custom";
|
|
import {getAllModels} from "../../../layout/getAll";
|
|
import {getAllModels} from "../../../layout/getAll";
|
|
import {Files} from "../../../layout/dock/Files";
|
|
import {Files} from "../../../layout/dock/Files";
|
|
import {Search} from "../../../search";
|
|
import {Search} from "../../../search";
|
|
|
|
+import {openSearch} from "../../../search/spread";
|
|
/// #endif
|
|
/// #endif
|
|
import {addEditorToDatabase, addFilesToDatabase} from "../../../protyle/render/av/addToDatabase";
|
|
import {addEditorToDatabase, addFilesToDatabase} from "../../../protyle/render/av/addToDatabase";
|
|
-import {hasClosestBlock, hasClosestByClassName} from "../../../protyle/util/hasClosest";
|
|
|
|
|
|
+import {hasClosestBlock, hasClosestByClassName, hasTopClosestByTag} from "../../../protyle/util/hasClosest";
|
|
import {onlyProtyleCommand} from "./protyle";
|
|
import {onlyProtyleCommand} from "./protyle";
|
|
import {globalCommand} from "./global";
|
|
import {globalCommand} from "./global";
|
|
-import {getTopPaths, movePathTo, moveToPath} from "../../../util/pathName";
|
|
|
|
|
|
+import {getDisplayName, getNotebookName, getTopPaths, movePathTo, moveToPath, pathPosix} from "../../../util/pathName";
|
|
import {hintMoveBlock} from "../../../protyle/hint/extend";
|
|
import {hintMoveBlock} from "../../../protyle/hint/extend";
|
|
|
|
+import {fetchSyncPost} from "../../../util/fetch";
|
|
|
|
|
|
export const commandPanel = (app: App) => {
|
|
export const commandPanel = (app: App) => {
|
|
const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined;
|
|
const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined;
|
|
@@ -48,9 +51,9 @@ export const commandPanel = (app: App) => {
|
|
/// #if MOBILE
|
|
/// #if MOBILE
|
|
keys = ["addToDatabase", "fileTree", "outline", "bookmark", "tag", "dailyNote", "inbox", "backlinks",
|
|
keys = ["addToDatabase", "fileTree", "outline", "bookmark", "tag", "dailyNote", "inbox", "backlinks",
|
|
"dataHistory", "editReadonly", "enter", "enterBack", "globalSearch",
|
|
"dataHistory", "editReadonly", "enter", "enterBack", "globalSearch",
|
|
- "lockScreen", "mainMenu", "move", "newFile", "recentDocs",
|
|
|
|
|
|
+ "lockScreen", "mainMenu", "move", "newFile", "recentDocs", "replace", "riffCard", "search",
|
|
|
|
|
|
- "replace", "riffCard", "search", "selectOpen1",
|
|
|
|
|
|
+ "selectOpen1",
|
|
"splitLR", "splitMoveB", "splitMoveR", "splitTB", "stickSearch", "syncNow", "tabToWindow",
|
|
"splitLR", "splitMoveB", "splitMoveR", "splitTB", "stickSearch", "syncNow", "tabToWindow",
|
|
"toggleDock", "toggleWin"];
|
|
"toggleDock", "toggleWin"];
|
|
/// #else
|
|
/// #else
|
|
@@ -59,9 +62,9 @@ export const commandPanel = (app: App) => {
|
|
"closeUnmodified", "config", "dataHistory", "editReadonly", "enter", "enterBack", "globalSearch", "goBack",
|
|
"closeUnmodified", "config", "dataHistory", "editReadonly", "enter", "enterBack", "globalSearch", "goBack",
|
|
"goForward", "goToEditTabNext", "goToEditTabPrev", "goToTab1", "goToTab2", "goToTab3", "goToTab4",
|
|
"goForward", "goToEditTabNext", "goToEditTabPrev", "goToTab1", "goToTab2", "goToTab3", "goToTab4",
|
|
"goToTab5", "goToTab6", "goToTab7", "goToTab8", "goToTab9", "goToTabNext", "goToTabPrev", "lockScreen",
|
|
"goToTab5", "goToTab6", "goToTab7", "goToTab8", "goToTab9", "goToTabNext", "goToTabPrev", "lockScreen",
|
|
- "mainMenu", "move", "newFile", "recentDocs",
|
|
|
|
|
|
+ "mainMenu", "move", "newFile", "recentDocs", "replace", "riffCard", "search",
|
|
|
|
|
|
- "replace", "riffCard", "search", "selectOpen1",
|
|
|
|
|
|
+ "selectOpen1",
|
|
"splitLR", "splitMoveB", "splitMoveR", "splitTB", "stickSearch", "syncNow", "tabToWindow",
|
|
"splitLR", "splitMoveB", "splitMoveR", "splitTB", "stickSearch", "syncNow", "tabToWindow",
|
|
"toggleDock", "toggleWin"];
|
|
"toggleDock", "toggleWin"];
|
|
|
|
|
|
@@ -172,7 +175,7 @@ const filterList = (inputElement: HTMLInputElement, listElement: Element) => {
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
-export const execByCommand = (options: {
|
|
|
|
|
|
+export const execByCommand = async (options: {
|
|
command: string,
|
|
command: string,
|
|
app?: App,
|
|
app?: App,
|
|
previousRange?: Range,
|
|
previousRange?: Range,
|
|
@@ -192,7 +195,7 @@ export const execByCommand = (options: {
|
|
options.previousRange = protyle.toolbar.range;
|
|
options.previousRange = protyle.toolbar.range;
|
|
}
|
|
}
|
|
/// #endif
|
|
/// #endif
|
|
- const range: Range = options.previousRange || getSelection().getRangeAt(0);
|
|
|
|
|
|
+ const range: Range = options.previousRange || (getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : document.createRange());
|
|
let fileLiElements = options.fileLiElements;
|
|
let fileLiElements = options.fileLiElements;
|
|
if (!isFileFocus && !protyle) {
|
|
if (!isFileFocus && !protyle) {
|
|
if (range) {
|
|
if (range) {
|
|
@@ -230,9 +233,6 @@ export const execByCommand = (options: {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (!protyle) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
} else if (!protyle) {
|
|
} else if (!protyle) {
|
|
if (!protyle && range) {
|
|
if (!protyle && range) {
|
|
window.siyuan.blockPanels.find(item => {
|
|
window.siyuan.blockPanels.find(item => {
|
|
@@ -274,14 +274,11 @@ export const execByCommand = (options: {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- if (!protyle) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// only protyle
|
|
// only protyle
|
|
- if (!isFileFocus && onlyProtyleCommand({
|
|
|
|
|
|
+ if (!isFileFocus && protyle && onlyProtyleCommand({
|
|
command: options.command,
|
|
command: options.command,
|
|
previousRange: range,
|
|
previousRange: range,
|
|
protyle
|
|
protyle
|
|
@@ -298,8 +295,132 @@ export const execByCommand = (options: {
|
|
fileLiElements = Array.from(files.element.querySelectorAll(".b3-list-item--focus"));
|
|
fileLiElements = Array.from(files.element.querySelectorAll(".b3-list-item--focus"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 全局命令,在没有 protyle 和文件树没聚焦的情况下执行
|
|
|
|
+ if ((!protyle && !isFileFocus) ||
|
|
|
|
+ (isFileFocus && (!fileLiElements || fileLiElements.length === 0)) ||
|
|
|
|
+ (isMobile() && !document.getElementById("empty").classList.contains("fn__none"))) {
|
|
|
|
+ if (options.command === "replace") {
|
|
|
|
+ /// #if MOBILE
|
|
|
|
+ popSearch(options.app, {hasReplace: true, page: 1});
|
|
|
|
+ /// #else
|
|
|
|
+ openSearch({
|
|
|
|
+ app: options.app,
|
|
|
|
+ hotkey: Constants.DIALOG_REPLACE,
|
|
|
|
+ key: range.toString()
|
|
|
|
+ });
|
|
|
|
+ /// #endif
|
|
|
|
+ } else if (options.command === "search") {
|
|
|
|
+ /// #if MOBILE
|
|
|
|
+ popSearch(options.app, {hasReplace: false, page: 1});
|
|
|
|
+ /// #else
|
|
|
|
+ openSearch({
|
|
|
|
+ app: options.app,
|
|
|
|
+ hotkey: Constants.DIALOG_SEARCH,
|
|
|
|
+ key: range.toString()
|
|
|
|
+ });
|
|
|
|
+ /// #endif
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
// protyle and file tree
|
|
// protyle and file tree
|
|
switch (options.command) {
|
|
switch (options.command) {
|
|
|
|
+ case "replace":
|
|
|
|
+ if (!isFileFocus) {
|
|
|
|
+ /// #if MOBILE
|
|
|
|
+ const response = await fetchSyncPost("/api/filetree/getHPathByPath", {
|
|
|
|
+ notebook: protyle.notebookId,
|
|
|
|
+ path: protyle.path.endsWith(".sy") ? protyle.path : protyle.path + ".sy"
|
|
|
|
+ });
|
|
|
|
+ popSearch(options.app, {
|
|
|
|
+ page: 1,
|
|
|
|
+ hasReplace: true,
|
|
|
|
+ hPath: pathPosix().join(getNotebookName(protyle.notebookId), response.data),
|
|
|
|
+ idPath: [pathPosix().join(protyle.notebookId, protyle.path)]
|
|
|
|
+ });
|
|
|
|
+ /// #else
|
|
|
|
+ openSearch({
|
|
|
|
+ app: options.app,
|
|
|
|
+ hotkey: Constants.DIALOG_REPLACE,
|
|
|
|
+ key: range.toString(),
|
|
|
|
+ notebookId: protyle.notebookId,
|
|
|
|
+ searchPath: protyle.path
|
|
|
|
+ });
|
|
|
|
+ /// #endif
|
|
|
|
+ } else {
|
|
|
|
+ /// #if !MOBILE
|
|
|
|
+ const topULElement = hasTopClosestByTag(fileLiElements[0], "UL");
|
|
|
|
+ if (!topULElement) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ const notebookId = topULElement.getAttribute("data-url");
|
|
|
|
+ const pathString = fileLiElements[0].getAttribute("data-path");
|
|
|
|
+ const isFile = fileLiElements[0].getAttribute("data-type") === "navigation-file";
|
|
|
|
+ if (isFile) {
|
|
|
|
+ openSearch({
|
|
|
|
+ app: options.app,
|
|
|
|
+ hotkey: Constants.DIALOG_REPLACE,
|
|
|
|
+ notebookId: notebookId,
|
|
|
|
+ searchPath: getDisplayName(pathString, false, true)
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ openSearch({
|
|
|
|
+ app: options.app,
|
|
|
|
+ hotkey: Constants.DIALOG_REPLACE,
|
|
|
|
+ notebookId: notebookId,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ /// #endif
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "search":
|
|
|
|
+ if (!isFileFocus) {
|
|
|
|
+ /// #if MOBILE
|
|
|
|
+ const response = await fetchSyncPost("/api/filetree/getHPathByPath", {
|
|
|
|
+ notebook: protyle.notebookId,
|
|
|
|
+ path: protyle.path.endsWith(".sy") ? protyle.path : protyle.path + ".sy"
|
|
|
|
+ });
|
|
|
|
+ popSearch(options.app, {
|
|
|
|
+ page: 1,
|
|
|
|
+ hasReplace: false,
|
|
|
|
+ hPath: pathPosix().join(getNotebookName(protyle.notebookId), response.data),
|
|
|
|
+ idPath: [pathPosix().join(protyle.notebookId, protyle.path)]
|
|
|
|
+ });
|
|
|
|
+ /// #else
|
|
|
|
+ openSearch({
|
|
|
|
+ app: options.app,
|
|
|
|
+ hotkey: Constants.DIALOG_SEARCH,
|
|
|
|
+ key: range.toString(),
|
|
|
|
+ notebookId: protyle.notebookId,
|
|
|
|
+ searchPath: protyle.path
|
|
|
|
+ });
|
|
|
|
+ /// #endif
|
|
|
|
+ } else {
|
|
|
|
+ /// #if !MOBILE
|
|
|
|
+ const topULElement = hasTopClosestByTag(fileLiElements[0], "UL");
|
|
|
|
+ if (!topULElement) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ const notebookId = topULElement.getAttribute("data-url");
|
|
|
|
+ const pathString = fileLiElements[0].getAttribute("data-path");
|
|
|
|
+ const isFile = fileLiElements[0].getAttribute("data-type") === "navigation-file";
|
|
|
|
+ if (isFile) {
|
|
|
|
+ openSearch({
|
|
|
|
+ app: options.app,
|
|
|
|
+ hotkey: Constants.DIALOG_SEARCH,
|
|
|
|
+ notebookId: notebookId,
|
|
|
|
+ searchPath: getDisplayName(pathString, false, true)
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ openSearch({
|
|
|
|
+ app: options.app,
|
|
|
|
+ hotkey: Constants.DIALOG_SEARCH,
|
|
|
|
+ notebookId: notebookId,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ /// #endif
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
case "addToDatabase":
|
|
case "addToDatabase":
|
|
if (!isFileFocus) {
|
|
if (!isFileFocus) {
|
|
addEditorToDatabase(protyle, range);
|
|
addEditorToDatabase(protyle, range);
|