From bff305aa6aac35e000be954bcbb687c049890df7 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 13 Jul 2022 23:08:27 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/5394 --- app/src/assets/scss/_dialog.scss | 12 ++++++++ app/src/util/globalShortcut.ts | 49 +++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/app/src/assets/scss/_dialog.scss b/app/src/assets/scss/_dialog.scss index a02e17e6c..50b33e98e 100644 --- a/app/src/assets/scss/_dialog.scss +++ b/app/src/assets/scss/_dialog.scss @@ -84,6 +84,7 @@ &--switch { max-height: 70vh; + max-width: 520px; .b3-list:last-child { border-left: 1px solid var(--b3-border-color); @@ -91,5 +92,16 @@ max-width: 360px; min-width: 200px; } + + .dialog__path { + padding: 4px 8px; + border-top: 1px solid var(--b3-border-color); + color: var(--b3-theme-on-surface); + font-size: 12px; + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + line-height: 18px; + } } } diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.ts index cc79d929d..b33c32e77 100644 --- a/app/src/util/globalShortcut.ts +++ b/app/src/util/globalShortcut.ts @@ -195,7 +195,7 @@ export const globalShortcut = () => { window.siyuan.altIsPressed = false; if (switchDialog && switchDialog.element.parentElement) { if (event.key === "Tab") { - const currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus"); + let currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus"); currentLiElement.classList.remove("b3-list-item--focus"); if (event.shiftKey) { if (currentLiElement.previousElementSibling) { @@ -204,7 +204,11 @@ export const globalShortcut = () => { currentLiElement.parentElement.lastElementChild.classList.add("b3-list-item--focus"); currentLiElement.removeAttribute("data-original"); } else if (currentLiElement.parentElement.nextElementSibling) { - currentLiElement.parentElement.nextElementSibling.lastElementChild.classList.add("b3-list-item--focus"); + if (currentLiElement.parentElement.nextElementSibling.lastElementChild) { + currentLiElement.parentElement.nextElementSibling.lastElementChild.classList.add("b3-list-item--focus"); + } else { + currentLiElement.parentElement.lastElementChild.classList.add("b3-list-item--focus"); + } } else if (currentLiElement.parentElement.previousElementSibling) { currentLiElement.parentElement.previousElementSibling.lastElementChild.classList.add("b3-list-item--focus"); } @@ -215,11 +219,28 @@ export const globalShortcut = () => { currentLiElement.parentElement.firstElementChild.classList.add("b3-list-item--focus"); currentLiElement.removeAttribute("data-original"); } else if (currentLiElement.parentElement.nextElementSibling) { - currentLiElement.parentElement.nextElementSibling.firstElementChild.classList.add("b3-list-item--focus"); + if (currentLiElement.parentElement.nextElementSibling.firstElementChild) { + currentLiElement.parentElement.nextElementSibling.firstElementChild.classList.add("b3-list-item--focus"); + } else { + currentLiElement.parentElement.firstElementChild.classList.add("b3-list-item--focus"); + } } else if (currentLiElement.parentElement.previousElementSibling) { currentLiElement.parentElement.previousElementSibling.firstElementChild.classList.add("b3-list-item--focus"); } } + currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus"); + if (currentLiElement) { + const rootId = currentLiElement.getAttribute("data-node-id"); + if (rootId) { + fetchPost("/api/filetree/getFullHPathByID", { + id: rootId + }, (response) => { + currentLiElement.parentElement.parentElement.nextElementSibling.innerHTML = escapeHtml(response.data); + }); + } else { + currentLiElement.parentElement.parentElement.nextElementSibling.innerHTML = currentLiElement.querySelector(".b3-list-item__text").innerHTML; + } + } } else if (event.key === "Control") { let currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus"); // 快速切换时,不触发 Tab @@ -304,15 +325,7 @@ export const globalShortcut = () => { if (switchDialog && switchDialog.element.parentElement) { return; } - let dockHtml = ""; let tabHtml = ""; - getAllDocks().forEach(item => { - dockHtml += `
  • - - ${window.siyuan.languages[item.hotkeyLangId]} - ${updateHotkeyTip(window.siyuan.config.keymap.general[item.hotkeyLangId].custom)} -
  • `; - }); let currentTabElement = document.querySelector(".layout__wnd--active .layout-tab-bar > .item--focus"); if (!currentTabElement) { currentTabElement = document.querySelector(".layout-tab-bar > .item--focus"); @@ -323,12 +336,22 @@ export const globalShortcut = () => { return itemA.headElement.getAttribute("data-activetime") > itemB.headElement.getAttribute("data-activetime") ? -1 : 1; }).forEach(item => { let icon = ``; + let rootId = ""; if (item.model instanceof Editor) { + rootId = ` data-node-id="${item.model.editor.protyle.block.rootID}"` icon = `${unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE)}`; } - tabHtml += `
  • ${icon}${escapeHtml(item.title)}
  • `; + tabHtml += `
  • ${icon}${escapeHtml(item.title)}
  • `; }); } + let dockHtml = ""; + getAllDocks().forEach(item => { + dockHtml += `
  • + + ${window.siyuan.languages[item.hotkeyLangId]} + ${updateHotkeyTip(window.siyuan.config.keymap.general[item.hotkeyLangId].custom)} +
  • `; + }); switchDialog = new Dialog({ content: `
    @@ -336,7 +359,7 @@ export const globalShortcut = () => {
    -
    +
    `, disableClose: true, disableAnimation: true,