This commit is contained in:
Vanessa 2022-06-29 09:09:18 +08:00
parent 22dad0a3b7
commit fa2b7c369f
2 changed files with 20 additions and 11 deletions

View File

@ -294,7 +294,10 @@ export class Wnd {
if (item.headElement && item.headElement.classList.contains("fn__none")) { if (item.headElement && item.headElement.classList.contains("fn__none")) {
// https://github.com/siyuan-note/siyuan/issues/267 // https://github.com/siyuan-note/siyuan/issues/267
} else { } 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"); item.panelElement.classList.remove("fn__none");
} }
currentTab = item; currentTab = item;
@ -310,7 +313,7 @@ export class Wnd {
if (currentTab && currentTab.model instanceof Editor) { if (currentTab && currentTab.model instanceof Editor) {
const keepCursorId = currentTab.headElement.getAttribute("keep-cursor"); const keepCursorId = currentTab.headElement.getAttribute("keep-cursor");
if (keepCursorId) { if (keepCursorId) {
// 在新页签中打开,但不跳转到新页签,切换到新页签时需调整滚动 // 在新页签中打开,但不跳转到新页签,切换到新页签时需调整滚动
let nodeElement: HTMLElement; let nodeElement: HTMLElement;
Array.from(currentTab.model.editor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${keepCursorId}"]`)).find((item: HTMLElement) => { Array.from(currentTab.model.editor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${keepCursorId}"]`)).find((item: HTMLElement) => {
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed", true)) { if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed", true)) {
@ -405,7 +408,7 @@ export class Wnd {
event.preventDefault(); 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"); const containerElement = this.element.querySelector(".layout-tab-container");
if (!containerElement.querySelector(".fn__flex-1")) { if (!containerElement.querySelector(".fn__flex-1")) {
@ -433,10 +436,10 @@ export class Wnd {
return; return;
} }
if (!openTime) { if (!openTime) {
openTime = item.headElement.getAttribute("data-opentime"); openTime = item.headElement.getAttribute("data-activetime");
removeId = this.children[index].id; removeId = this.children[index].id;
} else if (item.headElement.getAttribute("data-opentime") < openTime) { } else if (item.headElement.getAttribute("data-activetime") < openTime) {
openTime = item.headElement.getAttribute("data-opentime"); openTime = item.headElement.getAttribute("data-activetime");
removeId = this.children[index].id; removeId = this.children[index].id;
} }
}); });

View File

@ -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 {matchHotKey} from "../protyle/util/hotKey";
import {openSearch} from "../search/spread"; import {openSearch} from "../search/spread";
import { import {
@ -257,7 +257,11 @@ export const globalShortcut = () => {
let dockHtml = '' let dockHtml = ''
let tabHtml = '' let tabHtml = ''
getAllDocks().forEach(item => { getAllDocks().forEach(item => {
dockHtml += `<li data-type="${item.type}" class="b3-list-item"><svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg><span class="b3-list-item__text">${window.siyuan.languages[item.hotkeyLangId]}</span></li>` dockHtml += `<li data-type="${item.type}" class="b3-list-item">
<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>
<span class="b3-list-item__text">${window.siyuan.languages[item.hotkeyLangId]}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general[item.hotkeyLangId].custom)}</span>
</li>`
}) })
let currentTabElement = document.querySelector(".layout__wnd--active .layout-tab-bar > .item--focus") let currentTabElement = document.querySelector(".layout__wnd--active .layout-tab-bar > .item--focus")
if (!currentTabElement) { if (!currentTabElement) {
@ -265,13 +269,15 @@ export const globalShortcut = () => {
} }
if (currentTabElement) { if (currentTabElement) {
const currentId = currentTabElement.getAttribute("data-id") 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 = `<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>` let icon = `<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>`
if (item.model instanceof Editor) { if (item.model instanceof Editor) {
icon = `<span class="b3-list-item__graphic">${unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE)}</span>` icon = `<span class="b3-list-item__graphic">${unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE)}</span>`
} }
tabHtml += `<li data-id="${item.id}" class="b3-list-item${currentId === item.id ? " b3-list-item--focus" : ""}"${currentId === item.id ? ' data-original="true"' : ""}>${icon}<span class="b3-list-item__text">${item.title}</span></li>` tabHtml += `<li data-id="${item.id}" class="b3-list-item${currentId === item.id ? " b3-list-item--focus" : ""}"${currentId === item.id ? ' data-original="true"' : ""}>${icon}<span class="b3-list-item__text">${item.title}</span></li>`
}) });
} }
switchDialog = new Dialog({ switchDialog = new Dialog({
content: `<div class="fn__flex-column b3-dialog--switch"> content: `<div class="fn__flex-column b3-dialog--switch">
@ -283,7 +289,7 @@ export const globalShortcut = () => {
<div class="fn__hr"></div> <div class="fn__hr"></div>
</div>` </div>`
}); });
switchDialog.element.addEventListener("contextmenu", (event) => { switchDialog.element.addEventListener(isMac() ? "contextmenu" : "click", (event) => {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
let target = event.target as HTMLElement; let target = event.target as HTMLElement;