From fa2b7c369f09ffb339760ccd46e04e0ff7c67a94 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 29 Jun 2022 09:09:18 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/5290 --- app/src/layout/Wnd.ts | 15 +++++++++------ app/src/util/globalShortcut.ts | 16 +++++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index 64545c420..188d674b8 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -294,7 +294,10 @@ export class Wnd { if (item.headElement && item.headElement.classList.contains("fn__none")) { // https://github.com/siyuan-note/siyuan/issues/267 } else { - item.headElement?.classList.add("item--focus"); + if (item.headElement) { + item.headElement.classList.add("item--focus"); + item.headElement.setAttribute("data-activetime", (new Date()).getTime().toString()); + } item.panelElement.classList.remove("fn__none"); } currentTab = item; @@ -310,7 +313,7 @@ export class Wnd { if (currentTab && currentTab.model instanceof Editor) { const keepCursorId = currentTab.headElement.getAttribute("keep-cursor"); if (keepCursorId) { - // 在新页签中打开,但不跳转到新页签,单切换到新页签时需调整滚动 + // 在新页签中打开,但不跳转到新页签,但切换到新页签时需调整滚动 let nodeElement: HTMLElement; Array.from(currentTab.model.editor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${keepCursorId}"]`)).find((item: HTMLElement) => { if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed", true)) { @@ -405,7 +408,7 @@ export class Wnd { event.preventDefault(); }); - tab.headElement.setAttribute("data-opentime", (new Date()).getTime().toString()); + tab.headElement.setAttribute("data-activetime", (new Date()).getTime().toString()); } const containerElement = this.element.querySelector(".layout-tab-container"); if (!containerElement.querySelector(".fn__flex-1")) { @@ -433,10 +436,10 @@ export class Wnd { return; } if (!openTime) { - openTime = item.headElement.getAttribute("data-opentime"); + openTime = item.headElement.getAttribute("data-activetime"); removeId = this.children[index].id; - } else if (item.headElement.getAttribute("data-opentime") < openTime) { - openTime = item.headElement.getAttribute("data-opentime"); + } else if (item.headElement.getAttribute("data-activetime") < openTime) { + openTime = item.headElement.getAttribute("data-activetime"); removeId = this.children[index].id; } }); diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.ts index e65f3b4ba..1843d5ea8 100644 --- a/app/src/util/globalShortcut.ts +++ b/app/src/util/globalShortcut.ts @@ -1,4 +1,4 @@ -import {isCtrl, isMac, writeText} from "../protyle/util/compatibility"; +import {isCtrl, isMac, updateHotkeyTip, writeText} from "../protyle/util/compatibility"; import {matchHotKey} from "../protyle/util/hotKey"; import {openSearch} from "../search/spread"; import { @@ -257,7 +257,11 @@ export const globalShortcut = () => { let dockHtml = '' let tabHtml = '' getAllDocks().forEach(item => { - dockHtml += `
  • ${window.siyuan.languages[item.hotkeyLangId]}
  • ` + 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) { @@ -265,13 +269,15 @@ export const globalShortcut = () => { } if (currentTabElement) { const currentId = currentTabElement.getAttribute("data-id") - getAllTabs().forEach(item => { + getAllTabs().sort((itemA, itemB) => { + return itemA.headElement.getAttribute("data-activetime") > itemB.headElement.getAttribute("data-activetime") ? -1 : 1 + }).forEach(item => { let icon = `` if (item.model instanceof Editor) { icon = `${unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE)}` } tabHtml += `
  • ${icon}${item.title}
  • ` - }) + }); } switchDialog = new Dialog({ content: `
    @@ -283,7 +289,7 @@ export const globalShortcut = () => {
    ` }); - switchDialog.element.addEventListener("contextmenu", (event) => { + switchDialog.element.addEventListener(isMac() ? "contextmenu" : "click", (event) => { event.preventDefault(); event.stopPropagation(); let target = event.target as HTMLElement;