From d4af0d0342f0eba0df183310ad0764683069b98c Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 23 Jun 2022 00:28:27 +0800 Subject: [PATCH] :sparkles: https://github.com/siyuan-note/siyuan/issues/2098 --- app/src/layout/Wnd.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index 4607054c7..37780bf1a 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -404,6 +404,8 @@ export class Wnd { event.stopPropagation(); event.preventDefault(); }); + + tab.headElement.setAttribute("data-opentime", (new Date()).getTime().toString()); } const containerElement = this.element.querySelector(".layout-tab-container"); if (!containerElement.querySelector(".fn__flex-1")) { @@ -423,6 +425,24 @@ export class Wnd { // 移除 centerLayout 中的 empty if (this.parent.type === "center" && this.children.length === 2 && !this.children[0].headElement) { this.removeTab(this.children[0].id); + } else if (this.children.length > 5) { // TODO: 需从后台设置中获取 + let removeId: string; + let openTime: string + this.children.forEach((item, index) => { + if (item.headElement.classList.contains("item--pin") || item.headElement.classList.contains("item--focus") || index === oldFocusIndex) { + return; + } + if (!openTime) { + openTime = item.headElement.getAttribute("data-opentime") + removeId = this.children[index].id + } else if (item.headElement.getAttribute("data-opentime") < openTime) { + openTime = item.headElement.getAttribute("data-opentime") + removeId = this.children[index].id + } + }); + if (removeId) { + this.removeTab(removeId); + } } }