diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index a67b12b09..098c6747d 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -34,6 +34,8 @@ import {Constants} from "../../constants";
import {openMobileFileById} from "../../mobile/editor";
import {mathRender} from "../markdown/mathRender";
import {duplicateBlock} from "../wysiwyg/commonHotkey";
+import {movePathTo} from "../../util/pathName";
+import {hintMoveBlock} from "../hint/extend";
export class Gutter {
public element: HTMLElement;
@@ -646,7 +648,9 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.general.move.custom,
icon: "iconMove",
click: () => {
- protyle.toolbar.showFile(protyle, selectsElement, getEditorRange(selectsElement[0]));
+ movePathTo([], undefined, (toPath) => {
+ hintMoveBlock(toPath, selectsElement, protyle);
+ });
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
@@ -981,7 +985,7 @@ export class Gutter {
click() {
let html = nodeElement.outerHTML
if (protyle.disabled) {
- html = getEnableHTML(html)
+ html = getEnableHTML(html)
}
writeText(protyle.lute.BlockDOM2HTML(html));
}
@@ -1015,7 +1019,9 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.general.move.custom,
icon: "iconMove",
click: () => {
- protyle.toolbar.showFile(protyle, [nodeElement], getEditorRange(nodeElement));
+ movePathTo([], undefined, (toPath) => {
+ hintMoveBlock(toPath, [nodeElement], protyle);
+ });
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index ecf23d4ae..01513d657 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -1492,77 +1492,6 @@ export class Toolbar {
inputElement.select();
});
}
-
- public showFile(protyle: IProtyle, nodeElements: Element[], range: Range) {
- this.range = range;
- fetchPost("/api/filetree/searchDocs", {
- k: "",
- }, (response) => {
- let html = "";
- response.data.forEach((item: { boxIcon: string, box: string, hPath: string, path: string }) => {
- if (item.path === "/") {
- return;
- }
- html += `
- ${item.boxIcon ? ('' + unicode2Emoji(item.boxIcon) + "") : ""}
- ${escapeHtml(item.hPath)}
-
`;
- });
- this.subElement.style.width = "";
- this.subElement.style.padding = "";
- this.subElement.innerHTML = ``;
-
- const inputElement = this.subElement.querySelector("input");
- inputElement.addEventListener("keydown", (event: KeyboardEvent) => {
- event.stopPropagation();
- if (event.isComposing) {
- return;
- }
- upDownHint(this.subElement.lastElementChild.lastElementChild as HTMLElement, event);
- if (event.key === "Enter") {
- hintMoveBlock(this.subElement.querySelector(".b3-list-item--focus").getAttribute("data-path"), nodeElements, protyle);
- event.preventDefault();
- } else if (event.key === "Escape") {
- this.subElement.classList.add("fn__none");
- focusByRange(this.range);
- }
- });
- inputElement.addEventListener("input", (event) => {
- event.stopPropagation();
- fetchPost("/api/filetree/searchDocs", {
- k: inputElement.value,
- }, (response) => {
- let searchHTML = "";
- response.data.forEach((item: { boxIcon: string, box: string, hPath: string, path: string }) => {
- if (item.path === "/") {
- return;
- }
- searchHTML += `
- ${item.boxIcon ? ('' + unicode2Emoji(item.boxIcon) + "") : ""}
- ${escapeHtml(item.hPath)}
-
`;
- });
- this.subElement.firstElementChild.lastElementChild.innerHTML = searchHTML;
- });
- });
- this.subElement.lastElementChild.addEventListener("click", (event) => {
- const target = event.target as HTMLElement;
- const listElement = hasClosestByClassName(target, "b3-list-item");
- if (!listElement) {
- return;
- }
- hintMoveBlock(listElement.getAttribute("data-path"), nodeElements, protyle);
- });
- const rangePosition = getSelectionPosition(nodeElements[0], range);
- this.subElement.classList.remove("fn__none");
- this.subElementCloseCB = undefined;
- setPosition(this.subElement, rangePosition.left, rangePosition.top + 18, Constants.SIZE_TOOLBAR_HEIGHT);
- this.element.classList.add("fn__none");
- inputElement.select();
- });
- }
}
diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.ts
index a331cde68..8c8db22bd 100644
--- a/app/src/util/globalShortcut.ts
+++ b/app/src/util/globalShortcut.ts
@@ -41,6 +41,7 @@ import {showPopover} from "../block/popover";
import {getStartEndElement} from "../protyle/wysiwyg/commonHotkey";
import {getNextFileLi, getPreviousFileLi} from "../protyle/wysiwyg/getBlock";
import {editor} from "../config/editor";
+import {hintMoveBlock} from "../protyle/hint/extend";
const getRightBlock = (element: HTMLElement, x: number, y: number) => {
let index = 1;
@@ -800,10 +801,16 @@ const editKeydown = (event: KeyboardEvent) => {
range = getSelection().getRangeAt(0);
nodeElement = hasClosestBlock(range.startContainer);
}
- if (nodeElement && range && protyle.element.contains(range.startContainer)) {
- protyle.toolbar.showFile(protyle, [nodeElement], range);
- } else {
- movePathTo([protyle.path]);
+ if (protyle.title?.editElement.contains(range.startContainer)) {
+ movePathTo([protyle.path], range);
+ } else if (nodeElement && range && protyle.element.contains(range.startContainer)) {
+ let selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"))
+ if (selectElements.length === 0) {
+ selectElements = [nodeElement]
+ }
+ movePathTo([], undefined, (toPath) => {
+ hintMoveBlock(toPath, selectElements, protyle);
+ });
}
event.preventDefault();
event.stopPropagation();
@@ -917,7 +924,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
}
if (isFile && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) {
window.siyuan.menus.menu.remove();
- movePathTo(getTopPaths(liElements), false);
+ movePathTo(getTopPaths(liElements));
event.preventDefault();
event.stopPropagation();
return true;
diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts
index 29564c1be..b687b3f5b 100644
--- a/app/src/util/pathName.ts
+++ b/app/src/util/pathName.ts
@@ -77,16 +77,15 @@ export const getTopPaths = (liElements: Element[]) => {
return fromPaths;
};
-const moveToPath = (fromPaths: string[], toNotebook: string, toPath: string, dialog: Dialog) => {
+const moveToPath = (fromPaths: string[], toNotebook: string, toPath: string) => {
fetchPost("/api/filetree/moveDocs", {
toNotebook,
fromPaths,
toPath,
});
- dialog.destroy();
};
-export const movePathTo = (paths: string[], focus = true) => {
+export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath:string) => void) => {
const exitDialog = window.siyuan.dialogs.find((item) => {
if (item.element.querySelector("#foldList")) {
item.destroy();
@@ -96,11 +95,6 @@ export const movePathTo = (paths: string[], focus = true) => {
if (exitDialog) {
return;
}
-
- let range: Range;
- if (getSelection().rangeCount > 0) {
- range = getSelection().getRangeAt(0);
- }
const dialog = new Dialog({
title: `${window.siyuan.languages.move} `,
content: `
@@ -118,14 +112,16 @@ export const movePathTo = (paths: string[], focus = true) => {
`,
width: isMobile() ? "80vw" : "50vw",
destroyCallback() {
- if (range && focus) {
+ if (range) {
focusByRange(range);
}
}
});
- fetchPost("/api/filetree/getHPathsByPaths", {paths}, (response) => {
- dialog.element.querySelector(".b3-dialog__header .ft__smaller").innerHTML = escapeHtml(response.data.join(", "))
- });
+ if (paths.length) {
+ fetchPost("/api/filetree/getHPathsByPaths", {paths}, (response) => {
+ dialog.element.querySelector(".b3-dialog__header .ft__smaller").innerHTML = escapeHtml(response.data.join(", "))
+ });
+ }
const searchListElement = dialog.element.querySelector("#foldList");
const searchTreeElement = dialog.element.querySelector("#foldTree");
let html = "";
@@ -161,9 +157,6 @@ export const movePathTo = (paths: string[], focus = true) => {
}, (data) => {
let fileHTML = "";
data.data.forEach((item: { boxIcon: string, box: string, hPath: string, path: string }) => {
- if (paths.includes(item.path)) {
- return;
- }
fileHTML += `
${unicode2Emoji(item.boxIcon || Constants.SIYUAN_IMAGE_NOTE)}
${escapeHtml(item.hPath)}
@@ -315,7 +308,12 @@ export const movePathTo = (paths: string[], focus = true) => {
}
}
if (event.key === "Enter") {
- moveToPath(paths, currentItemElement.getAttribute("data-box"), currentItemElement.getAttribute("data-path"), dialog);
+ if (cb) {
+ cb(currentItemElement.getAttribute("data-path"));
+ } else {
+ moveToPath(paths, currentItemElement.getAttribute("data-box"), currentItemElement.getAttribute("data-path"));
+ }
+ dialog.destroy();
event.preventDefault();
}
});
@@ -333,7 +331,12 @@ export const movePathTo = (paths: string[], focus = true) => {
if (!currentItemElement) {
return;
}
- moveToPath(paths, currentItemElement.getAttribute("data-box"), currentItemElement.getAttribute("data-path"), dialog);
+ if (cb) {
+ cb(currentItemElement.getAttribute("data-path"));
+ } else {
+ moveToPath(paths, currentItemElement.getAttribute("data-box"), currentItemElement.getAttribute("data-path"));
+ }
+ dialog.destroy();
event.preventDefault();
event.stopPropagation();
break;
@@ -356,6 +359,7 @@ export const movePathTo = (paths: string[], focus = true) => {
}
target = target.parentElement;
}
+ inputElement.focus()
});
};