mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-15 19:48:06 +01:00
This commit is contained in:
parent
441b6f7f65
commit
b60f84fe09
5 changed files with 118 additions and 5 deletions
|
|
@ -10,7 +10,10 @@ import {Constants} from "../constants";
|
|||
import {ipcRenderer} from "electron";
|
||||
/// #endif
|
||||
import {showMessage} from "../dialog/message";
|
||||
import {isOnlyMeta} from "../protyle/util/compatibility";
|
||||
import {isOnlyMeta, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
||||
import {matchHotKey} from "../protyle/util/hotKey";
|
||||
import {Menu} from "../plugin/Menu";
|
||||
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
|
||||
export const showFileInFolder = (filePath: string) => {
|
||||
/// #if !BROWSER
|
||||
|
|
@ -154,8 +157,11 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
|
|||
title: `${title || window.siyuan.languages.move}
|
||||
<div style="max-height: 16px;overflow: auto;line-height: 14px;-webkit-mask-image: linear-gradient(to top, rgba(0, 0, 0, 0) 0, #000 6px);padding-bottom: 4px;margin-bottom: -4px" class="ft__smaller ft__on-surface fn__hidescrollbar"></div>`,
|
||||
content: `<div class="b3-form__icon" style="margin: 8px">
|
||||
<svg class="b3-form__icon-icon"><use xlink:href="#iconSearch"></use></svg>
|
||||
<input class="b3-text-field fn__block b3-form__icon-input" value="" placeholder="${window.siyuan.languages.search}">
|
||||
<span data-menu="true" class="b3-form__icon-list fn__a b3-tooltips b3-tooltips__s" aria-label="${updateHotkeyTip("⌥↓")}">
|
||||
<svg class="svg--mid"><use xlink:href="#iconSearch"></use></svg>
|
||||
<svg class="svg--smaller"><use xlink:href="#iconDown"></use></svg>
|
||||
</span>
|
||||
<input class="b3-text-field fn__block" style="padding-left: 42px;" value="" placeholder="${window.siyuan.languages.search}">
|
||||
</div>
|
||||
<ul id="foldList" class="fn__flex-1 fn__none b3-list b3-list--background${isMobile() ? " b3-list--mobile" : ""}" style="overflow: auto;position: relative"></ul>
|
||||
<div id="foldTree" class="fn__flex-1${isMobile() ? " b3-list--mobile" : ""}" style="overflow: auto;position: relative"></div>
|
||||
|
|
@ -250,6 +256,75 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
|
|||
searchListElement.innerHTML = fileHTML;
|
||||
});
|
||||
};
|
||||
|
||||
const toggleMovePathHistory = () => {
|
||||
const keys = window.siyuan.storage[Constants.LOCAL_MOVE_PATH].keys;
|
||||
if (!keys || keys.length === 0) {
|
||||
return;
|
||||
}
|
||||
const menu = new Menu("move-path-history");
|
||||
if (menu.isOpen) {
|
||||
return;
|
||||
}
|
||||
menu.element.classList.add("b3-menu--list");
|
||||
menu.addItem({
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.clearHistory,
|
||||
click() {
|
||||
window.siyuan.storage[Constants.LOCAL_MOVE_PATH].keys = [];
|
||||
setStorageVal(Constants.LOCAL_MOVE_PATH, window.siyuan.storage[Constants.LOCAL_MOVE_PATH]);
|
||||
}
|
||||
});
|
||||
const separatorElement = menu.addSeparator(1);
|
||||
let current = true;
|
||||
keys.forEach((s: string) => {
|
||||
if (s !== inputElement.value && s) {
|
||||
const menuItem = menu.addItem({
|
||||
iconHTML: "",
|
||||
label: escapeHtml(s),
|
||||
action: "iconCloseRound",
|
||||
bind(element) {
|
||||
element.addEventListener("click", (itemEvent) => {
|
||||
if (hasClosestByClassName(itemEvent.target as Element, "b3-menu__action")) {
|
||||
keys.find((item: string, index: number) => {
|
||||
if (item === s) {
|
||||
keys.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
window.siyuan.storage[Constants.LOCAL_MOVE_PATH].keys = keys;
|
||||
setStorageVal(Constants.LOCAL_MOVE_PATH, window.siyuan.storage[Constants.LOCAL_MOVE_PATH]);
|
||||
if (element.previousElementSibling?.classList.contains("b3-menu__separator") && !element.nextElementSibling) {
|
||||
window.siyuan.menus.menu.remove();
|
||||
} else {
|
||||
element.remove();
|
||||
}
|
||||
} else {
|
||||
inputElement.value = element.textContent;
|
||||
inputEvent();
|
||||
window.siyuan.menus.menu.remove();
|
||||
}
|
||||
itemEvent.preventDefault();
|
||||
itemEvent.stopPropagation();
|
||||
});
|
||||
}
|
||||
});
|
||||
if (current) {
|
||||
menuItem.classList.add("b3-menu__item--current");
|
||||
}
|
||||
current = false;
|
||||
}
|
||||
});
|
||||
if (current) {
|
||||
separatorElement.remove();
|
||||
}
|
||||
const rect = inputElement.getBoundingClientRect();
|
||||
menu.open({
|
||||
x: rect.left,
|
||||
y: rect.bottom
|
||||
});
|
||||
}
|
||||
inputElement.value = window.siyuan.storage[Constants.LOCAL_MOVE_PATH].k;
|
||||
inputEvent();
|
||||
inputElement.addEventListener("compositionend", (event: InputEvent) => {
|
||||
inputEvent(event);
|
||||
|
|
@ -257,11 +332,33 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
|
|||
inputElement.addEventListener("input", (event: InputEvent) => {
|
||||
inputEvent(event);
|
||||
});
|
||||
inputElement.addEventListener("blur", () => {
|
||||
if (!inputElement.value) {
|
||||
return;
|
||||
}
|
||||
let list: string[] = window.siyuan.storage[Constants.LOCAL_MOVE_PATH].keys;
|
||||
list.splice(0, 0, inputElement.value);
|
||||
list = Array.from(new Set(list));
|
||||
if (list.length > window.siyuan.config.search.limit) {
|
||||
list.splice(window.siyuan.config.search.limit, list.length - window.siyuan.config.search.limit);
|
||||
}
|
||||
window.siyuan.storage[Constants.LOCAL_MOVE_PATH].k = inputElement.value;
|
||||
window.siyuan.storage[Constants.LOCAL_MOVE_PATH].keys = list;
|
||||
setStorageVal(Constants.LOCAL_MOVE_PATH, window.siyuan.storage[Constants.LOCAL_MOVE_PATH]);
|
||||
});
|
||||
const lineHeight = 28;
|
||||
inputElement.addEventListener("keydown", (event: KeyboardEvent) => {
|
||||
if (event.isComposing) {
|
||||
return;
|
||||
}
|
||||
if (matchHotKey("⌥↓", event)) {
|
||||
event.stopPropagation();
|
||||
toggleMovePathHistory();
|
||||
return;
|
||||
}
|
||||
if (window.siyuan.menus.menu.element.getAttribute("data-name") === "move-path-history") {
|
||||
return
|
||||
}
|
||||
const currentPanelElement = searchListElement.classList.contains("fn__none") ? searchTreeElement : searchListElement;
|
||||
const currentItemElements = currentPanelElement.querySelectorAll(".b3-list-item--focus");
|
||||
if (currentItemElements.length === 0) {
|
||||
|
|
@ -424,6 +521,11 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
break;
|
||||
} else if (target.classList.contains("b3-form__icon-list")) {
|
||||
toggleMovePathHistory();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
break;
|
||||
} else if (target.classList.contains("b3-button--text")) {
|
||||
const currentPanelElement = searchListElement.classList.contains("fn__none") ? searchTreeElement : searchListElement;
|
||||
const currentItemElements = currentPanelElement.querySelectorAll(".b3-list-item--focus");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue