From 2e15fbf09861c945f830cb5393032f13dc849e45 Mon Sep 17 00:00:00 2001 From: meteor Date: Thu, 8 Dec 2022 21:41:35 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=B7=B2=E9=80=89=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=86=8D=E6=AC=A1=E9=80=89=E4=B8=AD=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E4=BC=9A=E5=9C=A8=E6=96=87=E4=BB=B6=E6=A0=91?= =?UTF-8?q?=E4=B8=AD=E8=B7=B3=E8=BD=AC=20(#6820)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/editor/util.ts | 2 +- app/src/layout/dock/Files.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 085b81568..3e00e91af 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -345,7 +345,7 @@ export const updatePanelByEditor = (protyle?: IProtyle, focus = true, pushBackSt } if (window.siyuan.config.fileTree.alwaysSelectOpenedFile && protyle) { const fileModel = getDockByType("file")?.data.file; - if (fileModel instanceof Files) { + if (fileModel instanceof Files && !fileModel.isSelected(protyle.path)) { fileModel.selectItem(protyle.notebookId, protyle.path); } } diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.ts index 393be5830..f0e13c590 100644 --- a/app/src/layout/dock/Files.ts +++ b/app/src/layout/dock/Files.ts @@ -852,6 +852,21 @@ export class Files extends Model { liElement.insertAdjacentHTML("afterend", ``); this.setCurrent(this.element.querySelector(`ul[data-url="${data.box}"] li[data-path="${filePath}"]`)); } + /** + * 判断文件树中当前选中的是否是此文件 + * @param filePath 要判断的文件路径 + * @returns + */ + public isSelected(filePath: string): boolean { + if(!filePath) { + return false; + } + const target = this.element.querySelector(`li[data-path="${filePath}"]`); + if(target) { + return target.classList.contains("b3-list-item--focus"); + } + return false; + } private setCurrent(target: HTMLElement, isScroll = true) { if (!target) {