Vanessa 2024-02-29 00:33:11 +08:00
parent 9f69d7dc4a
commit 93df02dbab
12 changed files with 154 additions and 101 deletions

View file

@ -187,11 +187,18 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
}
if (range) {
window.siyuan.dialogs.find(item => {
if (item.editor && item.editor.protyle.element.contains(range.startContainer)) {
protyle = item.editor.protyle;
// https://github.com/siyuan-note/siyuan/issues/9384
isFileFocus = false;
return true;
if (item.editors) {
Object.keys(item.editors).find(key => {
if (item.editors[key].protyle.element.contains(range.startContainer)) {
protyle = item.editors[key].protyle;
// https://github.com/siyuan-note/siyuan/issues/9384
isFileFocus = false;
return true;
}
});
if (protyle) {
return true;
}
}
});
}
@ -200,7 +207,11 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
if (activeTab.model instanceof Editor) {
protyle = activeTab.model.editor.protyle;
} else if (activeTab.model instanceof Search) {
protyle = activeTab.model.edit.protyle;
if (activeTab.model.element.querySelector("#searchUnRefPanel").classList.contains("fn__none")) {
protyle = activeTab.model.editors.edit.protyle;
} else {
protyle = activeTab.model.editors.unRefEdit.protyle;
}
} else if (activeTab.model instanceof Custom && activeTab.model.data?.editor instanceof Protyle) {
protyle = activeTab.model.data.editor.protyle;
} else {

View file

@ -16,6 +16,7 @@ import {assetInputEvent, renderPreview, toggleAssetHistory} from "../../search/a
import {initSearchMenu} from "../../menus/search";
import {writeText} from "../../protyle/util/compatibility";
import {checkFold} from "../../util/noRelyPCFunction";
import {getUnRefList} from "../../search/unRef";
export const searchKeydown = (app: App, event: KeyboardEvent) => {
if (getSelection().rangeCount === 0) {
@ -28,13 +29,15 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
let element: HTMLElement;
let dialog: Dialog;
let edit;
let unRefEdit;
let config: ISearchOption;
window.siyuan.dialogs.find((item) => {
if (item.element.contains(range.startContainer) && item.element.querySelector("#searchList")) {
element = item.element.querySelector(".b3-dialog__body");
dialog = item;
config = dialog.data;
edit = dialog.editor;
edit = dialog.editors.edit;
unRefEdit = dialog.editors.unRefEdit;
return true;
}
});
@ -42,8 +45,9 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
getAllModels().search.find((item) => {
if (item.element.contains(range.startContainer)) {
element = item.element;
edit = item.edit;
edit = item.editors.edit;
config = item.config;
unRefEdit = item.editors.unRefEdit;
return true;
}
});
@ -52,10 +56,11 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
return false;
}
const assetsElement = element.querySelector("#searchAssets");
const isAsset = !assetsElement.classList.contains("fn__none");
const listElement = isAsset ? assetsElement.querySelector("#searchAssetList") : element.querySelector("#searchList");
const unRefElement = element.querySelector("#searchUnRefPanel");
const searchType = assetsElement.classList.contains("fn__none") ? (unRefElement.classList.contains("fn__none") ? "doc" : "unRef") : "asset";
const listElement = searchType === "asset" ? assetsElement.querySelector("#searchAssetList") : (searchType === "doc" ? element.querySelector("#searchList") : unRefElement.querySelector("#searchUnRefList"));
const searchInputElement = element.querySelector("#searchInput") as HTMLInputElement;
if (!isAsset && matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
if (searchType === "doc" && matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
if (config.method === 0) {
newFileByName(app, searchInputElement.value);
}
@ -63,9 +68,9 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
}
const targetId = (event.target as HTMLElement).id;
if (event.key === "ArrowDown" && event.altKey) {
if (isAsset) {
if (searchType === "asset") {
toggleAssetHistory(assetsElement);
} else {
} else if (searchType === "doc") {
if (targetId === "replaceInput") {
toggleReplaceHistory(element);
} else {
@ -90,7 +95,7 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
}
return false;
}
if (!isAsset) {
if (searchType !== "asset") {
if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) {
const id = currentList.getAttribute("data-node-id");
checkFold(id, (zoomIn, action) => {
@ -151,7 +156,7 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
}
if (Constants.KEYCODELIST[event.keyCode] === "PageUp") {
if (isAsset) {
if (searchType === "asset") {
if (!assetsElement.querySelector('[data-type="assetPrevious"]').getAttribute("disabled")) {
let currentPage = parseInt(assetsElement.querySelector("#searchAssetResult .fn__flex-center").textContent.split("/")[0]);
if (currentPage > 1) {
@ -159,18 +164,26 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
assetInputEvent(assetsElement, assetLocal, currentPage);
}
}
} else {
} else if (searchType === "doc") {
if (!element.querySelector('[data-type="previous"]').getAttribute("disabled")) {
if (config.page > 1) {
config.page--;
inputEvent(element, config, edit);
}
}
} else if (searchType === "unRef") {
if (!element.querySelector('[data-type="unRefPrevious"]').getAttribute("disabled")) {
let currentPage = parseInt(unRefElement.querySelector("#searchUnRefResult").textContent);
if (currentPage > 1) {
currentPage--;
getUnRefList(unRefElement, unRefEdit, currentPage);
}
}
}
return true;
}
if (Constants.KEYCODELIST[event.keyCode] === "PageDown") {
if (isAsset) {
if (searchType === "asset") {
if (!assetsElement.querySelector('[data-type="assetNext"]').getAttribute("disabled")) {
const assetPages = assetsElement.querySelector("#searchAssetResult .fn__flex-center").textContent.split("/");
let currentPage = parseInt(assetPages[0]);
@ -179,7 +192,7 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
assetInputEvent(assetsElement, assetLocal, currentPage);
}
}
} else {
} else if (searchType === "doc") {
const nextElement = element.querySelector('[data-type="next"]');
if (!nextElement.getAttribute("disabled")) {
if (config.page < parseInt(nextElement.parentElement.querySelector("#searchResult").getAttribute("data-pagecount"))) {
@ -187,6 +200,14 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
inputEvent(element, config, edit);
}
}
} else if (searchType === "unRef") {
if (!element.querySelector('[data-type="unRefNext"]').getAttribute("disabled")) {
let currentPage = parseInt(unRefElement.querySelector("#searchUnRefResult").textContent);
if (currentPage < parseInt(unRefElement.querySelector("#searchUnRefResult").textContent.split("/")[1])) {
currentPage++;
getUnRefList(unRefElement, unRefEdit, currentPage);
}
}
}
return true;
}
@ -194,7 +215,7 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
return false;
}
if (event.key === "Enter") {
if (!isAsset) {
if (searchType !== "asset") {
if (targetId === "replaceInput") {
replace(element, config, edit, false);
} else {
@ -223,7 +244,7 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
if (event.key === "ArrowDown") {
currentList.classList.remove("b3-list-item--focus");
if (!currentList.nextElementSibling) {
if (config.group === 1 && !isAsset) {
if (config.group === 1 && searchType === "doc") {
if (currentList.parentElement.nextElementSibling) {
currentList.parentElement.nextElementSibling.nextElementSibling.firstElementChild.classList.add("b3-list-item--focus");
} else {
@ -240,22 +261,27 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
listElement.scrollTop > currentList.offsetTop) {
listElement.scrollTop = currentList.offsetTop - listElement.clientHeight + lineHeight;
}
if (isAsset) {
if (searchType === "asset") {
renderPreview(assetPreviewElement, currentList.dataset.id, searchInputElement.value, assetLocal.method);
} else {
} else if (searchType === "doc") {
getArticle({
id: currentList.getAttribute("data-node-id"),
config,
value: searchInputElement.value,
edit,
});
} else {
getArticle({
id: currentList.getAttribute("data-node-id"),
edit: unRefEdit,
});
}
return true;
}
if (event.key === "ArrowUp") {
currentList.classList.remove("b3-list-item--focus");
if (!currentList.previousElementSibling) {
if (config.group === 1 && !isAsset) {
if (config.group === 1 && searchType === "doc") {
if (currentList.parentElement.previousElementSibling.previousElementSibling) {
currentList.parentElement.previousElementSibling.previousElementSibling.lastElementChild.classList.add("b3-list-item--focus");
} else {
@ -272,15 +298,20 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
listElement.scrollTop > currentList.offsetTop - lineHeight * 2) {
listElement.scrollTop = currentList.offsetTop - lineHeight * 2;
}
if (isAsset) {
if (searchType === "asset") {
renderPreview(assetPreviewElement, currentList.dataset.id, searchInputElement.value, assetLocal.method);
} else {
} else if (searchType === "doc") {
getArticle({
id: currentList.getAttribute("data-node-id"),
config,
value: searchInputElement.value,
edit,
});
} else if (searchType === "unRef") {
getArticle({
id: currentList.getAttribute("data-node-id"),
edit: unRefEdit,
});
}
return true;
}