mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-16 20:18:06 +01:00
This commit is contained in:
parent
1830cb102e
commit
6f505eb099
4 changed files with 42 additions and 96 deletions
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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 += `<div class="b3-list-item${html === "" ? " b3-list-item--focus" : ""}" data-path="${item.path}" data-box="${item.box}">
|
||||
${item.boxIcon ? ('<span class="b3-list-item__icon">' + unicode2Emoji(item.boxIcon) + "</span>") : ""}
|
||||
<span class="b3-list-item__text">${escapeHtml(item.hPath)}</span>
|
||||
</div>`;
|
||||
});
|
||||
this.subElement.style.width = "";
|
||||
this.subElement.style.padding = "";
|
||||
this.subElement.innerHTML = `<div class="fn__flex-column" style="max-height:50vh"><input style="margin: 4px 8px 8px 8px" class="b3-text-field"/>
|
||||
<div class="b3-list fn__flex-1 b3-list--background" style="position: relative">${html}</div>
|
||||
</div>`;
|
||||
|
||||
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 += `<div class="b3-list-item${searchHTML === "" ? " b3-list-item--focus" : ""}" data-path="${item.path}" data-box="${item.box}">
|
||||
${item.boxIcon ? ('<span class="b3-list-item__icon">' + unicode2Emoji(item.boxIcon) + "</span>") : ""}
|
||||
<span class="b3-list-item__text">${escapeHtml(item.hPath)}</span>
|
||||
</div>`;
|
||||
});
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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} <span class="ft__smaller ft__on-surface"></span>`,
|
||||
content: `<div>
|
||||
|
|
@ -118,14 +112,16 @@ export const movePathTo = (paths: string[], focus = true) => {
|
|||
</div>`,
|
||||
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 += `<li style="padding: 4px" class="b3-list-item${fileHTML === "" ? " b3-list-item--focus" : ""}" data-path="${item.path}" data-box="${item.box}">
|
||||
<span class="b3-list-item__graphic">${unicode2Emoji(item.boxIcon || Constants.SIYUAN_IMAGE_NOTE)}</span>
|
||||
<span class="b3-list-item__showall">${escapeHtml(item.hPath)}</span>
|
||||
|
|
@ -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()
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue