Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/pull/15965

Vanessa63c86becb1c5
diff --git a/app/src/boot/globalEvent/command/global.ts b/app/src/boot/globalEvent/command/global.ts
index 5c3a4d8df5..e47cfe57c1 100644
--- a/app/src/boot/globalEvent/command/global.ts
+++ b/app/src/boot/globalEvent/command/global.ts
@@ -8,7 +8,7 @@ import {popSearch} from "../../../mobile/menu/search";
import {getRecentDocs} from "../../../mobile/menu/getRecentDocs";
/// #else
import {openNewWindow} from "../../../window/openNewWindow";
-import {toggleDockBar} from "../../../layout/dock/util";
+import {selectOpenTab, toggleDockBar} from "../../../layout/dock/util";
import {openGlobalSearch} from "../../../search/util";
import {workspaceMenu} from "../../../menus/workspace";
import {isWindow} from "../../../util/functions";
@@ -27,7 +27,6 @@ import {
} from "../../../layout/tabUtil";
import {openSetting} from "../../../config";
import {Tab} from "../../../layout/Tab";
-import {Files} from "../../../layout/dock/Files";
/// #endif
/// #if !BROWSER
import {ipcRenderer} from "electron";
@@ -42,32 +41,6 @@ import {syncGuide} from "../../../sync/syncGuide";
import {Wnd} from "../../../layout/Wnd";
import {unsplitWnd} from "../../../menus/tab";
-const selectOpenTab = () => {
- /// #if MOBILE
- if (window.siyuan.mobile.editor?.protyle) {
- openDock("file");
- window.siyuan.mobile.docks.file.selectItem(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path);
- }
- /// #else
- const dockFile = getDockByType("file");
- if (!dockFile) {
- return false;
- }
- const files = dockFile.data.file as Files;
- const element = document.querySelector(".layout__wnd--active > .fn__flex > .layout-tab-bar > .item--focus") ||
- document.querySelector("ul.layout-tab-bar > .item--focus");
- if (element) {
- const tab = getInstanceById(element.getAttribute("data-id")) as Tab;
- if (tab && tab.model instanceof Editor) {
- tab.model.editor.protyle.wysiwyg.element.blur();
- tab.model.editor.protyle.title.editElement.blur();
- files.selectItem(tab.model.editor.protyle.notebookId, tab.model.editor.protyle.path);
- }
- }
- dockFile.toggleModel("file", true);
- /// #endif
-};
-
export const globalCommand = (command: string, app: App) => {
/// #if MOBILE
switch (command) {
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index e1692a8e6c..2fe115655b 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -601,6 +601,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
const liElement = files.element.querySelector(".b3-list-item");
if (liElement) {
liElement.classList.add("b3-list-item--focus");
+ files.lastSelectedElement = liElement;
}
event.preventDefault();
}
@@ -863,6 +864,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
item.classList.remove("b3-list-item--focus");
});
parentElement.classList.add("b3-list-item--focus");
+ files.lastSelectedElement = parentElement;
const parentRect = parentElement.getBoundingClientRect();
const fileRect = files.element.getBoundingClientRect();
if (parentRect.top < fileRect.top || parentRect.bottom > fileRect.bottom) {
@@ -895,6 +897,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
item.classList.remove("b3-list-item--focus");
});
nextElement.classList.add("b3-list-item--focus");
+ files.lastSelectedElement = nextElement;
const nextRect = nextElement.getBoundingClientRect();
const fileRect = files.element.getBoundingClientRect();
if (nextRect.top < fileRect.top || nextRect.bottom > fileRect.bottom) {
@@ -928,6 +931,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
item.classList.remove("b3-list-item--focus");
});
previousElement.classList.add("b3-list-item--focus");
+ files.lastSelectedElement = previousElement;
const previousRect = previousElement.getBoundingClientRect();
const fileRect = files.element.getBoundingClientRect();
if (previousRect.top < fileRect.top || previousRect.bottom > fileRect.bottom) {
diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.ts
index 5a42836449..27038d664f 100644
--- a/app/src/layout/dock/Files.ts
+++ b/app/src/layout/dock/Files.ts
@@ -28,13 +28,14 @@ import {refreshFileTree} from "../../dialog/processSystem";
import {ipcRenderer} from "electron";
/// #endif
import {hideTooltip, showTooltip} from "../../dialog/tooltip";
+import {selectOpenTab} from "./util";
export class Files extends Model {
public element: HTMLElement;
public parent: Tab;
- private actionsElement: HTMLElement;
public closeElement: HTMLElement;
- private lastClickedFileItem: HTMLElement = null;
+ public lastSelectedElement: Element = null;
+ private actionsElement: HTMLElement;
constructor(options: { tab: Tab, app: App }) {
super({
@@ -209,23 +210,7 @@ export class Files extends Model {
window.siyuan.menus.menu.remove();
break;
} else if (type === "focus") {
- let element = document.querySelector(".layout__wnd--active > .fn__flex > .layout-tab-bar > .item--focus") as HTMLElement;
- if (!element) {
- document.querySelectorAll("ul.layout-tab-bar > .item--focus").forEach((item: HTMLElement, index) => {
- if (index === 0) {
- element = item;
- } else if (item.dataset.activetime > element.dataset.activetime) {
- element = item;
- }
- });
- }
-
- if (element) {
- const tab = getInstanceById(element.getAttribute("data-id")) as Tab;
- if (tab && tab.model instanceof Editor) {
- this.selectItem(tab.model.editor.protyle.notebookId, tab.model.editor.protyle.path);
- }
- }
+ selectOpenTab();
event.preventDefault();
break;
} else if (type === "more") {
@@ -334,47 +319,37 @@ export class Files extends Model {
} else if (target.tagName === "LI") {
if (isOnlyMeta(event) && !event.altKey && !event.shiftKey) {
target.classList.toggle("b3-list-item--focus");
- } else if (event.shiftKey && !event.altKey && !isOnlyMeta(event) && target.getAttribute("data-type") === "navigation-file") {
+ this.lastSelectedElement = target;
+ } else if (event.shiftKey && !event.altKey && isNotCtrl(event)) {
// Shift+click 多选文档
- event.preventDefault();
- event.stopPropagation();
-
- if (!this.lastClickedFileItem) {
- this.lastClickedFileItem = target;
- this.setCurrent(target, false);
- return;
+ if (!this.lastSelectedElement) {
+ this.lastSelectedElement = this.element.querySelector(".b3-list-item--focus")||
+ this.element.querySelector(".b3-list-item");
}
+ this.element.querySelectorAll(".b3-list-item--focus").forEach(item => {
+ item.classList.remove("b3-list-item--focus");
+ });
// 获取所有文档项
- const allFiles = Array.from(this.element.querySelectorAll('li[data-type="navigation-file"]'));
+ const allFiles = Array.from(this.element.querySelectorAll("li.b3-list-item"));
// 获取起始和结束索引
- const startIndex = allFiles.indexOf(this.lastClickedFileItem);
+ const startIndex = allFiles.indexOf(this.lastSelectedElement);
const endIndex = allFiles.indexOf(target);
- if (startIndex === -1 || endIndex === -1) return;
-
// 确定选择范围
const start = Math.min(startIndex, endIndex);
- const end = Math.max(startIndex, endIndex);
-
- // 清除现有选择
- allFiles.forEach(file => {
- (file as HTMLElement).classList.remove("b3-list-item--focus");
- });
+ const end = Math.max(startIndex, endIndex)
// 添加新选择
for (let i = start; i <= end; i++) {
(allFiles[i] as HTMLElement).classList.add("b3-list-item--focus");
}
-
- needFocus = false;
- return;
} else {
+ this.lastSelectedElement = target;
this.setCurrent(target, false);
if (target.getAttribute("data-type") === "navigation-file") {
// 更新最后点击的文档项
- this.lastClickedFileItem = target;
needFocus = false;
if (target.getAttribute("data-opening")) {
return;
diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.ts
index 3f6298dbc7..5414838dfc 100644
--- a/app/src/layout/dock/util.ts
+++ b/app/src/layout/dock/util.ts
@@ -3,11 +3,13 @@ import {Tab} from "../Tab";
import {Graph} from "./Graph";
import {Outline} from "./Outline";
import {fixWndFlex1, getInstanceById, getWndByLayout, saveLayout, switchWnd} from "../util";
-import {resizeTabs} from "../tabUtil";
+import {getDockByType, resizeTabs} from "../tabUtil";
import {Backlink} from "./Backlink";
import {App} from "../../index";
import {Wnd} from "../Wnd";
import {fetchSyncPost} from "../../util/fetch";
+import {Files} from "./Files";
+import {Editor} from "../../editor";
export const openBacklink = async (options: {
app: App,
@@ -234,3 +236,23 @@ export const clearOBG = () => {
item.render(undefined);
});
};
+
+export const selectOpenTab = async () => {
+ const dockFile = getDockByType("file");
+ if (!dockFile) {
+ return false;
+ }
+ const files = dockFile.data.file as Files;
+ const element = document.querySelector(".layout__wnd--active > .fn__flex > .layout-tab-bar > .item--focus") ||
+ document.querySelector("ul.layout-tab-bar > .item--focus");
+ if (element) {
+ const tab = getInstanceById(element.getAttribute("data-id")) as Tab;
+ if (tab && tab.model instanceof Editor) {
+ tab.model.editor.protyle.wysiwyg.element.blur();
+ tab.model.editor.protyle.title.editElement.blur();
+ await files.selectItem(tab.model.editor.protyle.notebookId, tab.model.editor.protyle.path);
+ files.lastSelectedElement = files.element.querySelector(".b3-list-item--focus");
+ }
+ }
+ dockFile.toggleModel("file", true);
+};