mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
This commit is contained in:
parent
eb03fbb11c
commit
63c86becb1
4 changed files with 44 additions and 70 deletions
|
|
@ -8,7 +8,7 @@ import {popSearch} from "../../../mobile/menu/search";
|
||||||
import {getRecentDocs} from "../../../mobile/menu/getRecentDocs";
|
import {getRecentDocs} from "../../../mobile/menu/getRecentDocs";
|
||||||
/// #else
|
/// #else
|
||||||
import {openNewWindow} from "../../../window/openNewWindow";
|
import {openNewWindow} from "../../../window/openNewWindow";
|
||||||
import {toggleDockBar} from "../../../layout/dock/util";
|
import {selectOpenTab, toggleDockBar} from "../../../layout/dock/util";
|
||||||
import {openGlobalSearch} from "../../../search/util";
|
import {openGlobalSearch} from "../../../search/util";
|
||||||
import {workspaceMenu} from "../../../menus/workspace";
|
import {workspaceMenu} from "../../../menus/workspace";
|
||||||
import {isWindow} from "../../../util/functions";
|
import {isWindow} from "../../../util/functions";
|
||||||
|
|
@ -27,7 +27,6 @@ import {
|
||||||
} from "../../../layout/tabUtil";
|
} from "../../../layout/tabUtil";
|
||||||
import {openSetting} from "../../../config";
|
import {openSetting} from "../../../config";
|
||||||
import {Tab} from "../../../layout/Tab";
|
import {Tab} from "../../../layout/Tab";
|
||||||
import {Files} from "../../../layout/dock/Files";
|
|
||||||
/// #endif
|
/// #endif
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {ipcRenderer} from "electron";
|
import {ipcRenderer} from "electron";
|
||||||
|
|
@ -42,32 +41,6 @@ import {syncGuide} from "../../../sync/syncGuide";
|
||||||
import {Wnd} from "../../../layout/Wnd";
|
import {Wnd} from "../../../layout/Wnd";
|
||||||
import {unsplitWnd} from "../../../menus/tab";
|
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) => {
|
export const globalCommand = (command: string, app: App) => {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
switch (command) {
|
switch (command) {
|
||||||
|
|
|
||||||
|
|
@ -601,6 +601,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
|
||||||
const liElement = files.element.querySelector(".b3-list-item");
|
const liElement = files.element.querySelector(".b3-list-item");
|
||||||
if (liElement) {
|
if (liElement) {
|
||||||
liElement.classList.add("b3-list-item--focus");
|
liElement.classList.add("b3-list-item--focus");
|
||||||
|
files.lastSelectedElement = liElement;
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
@ -863,6 +864,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
|
||||||
item.classList.remove("b3-list-item--focus");
|
item.classList.remove("b3-list-item--focus");
|
||||||
});
|
});
|
||||||
parentElement.classList.add("b3-list-item--focus");
|
parentElement.classList.add("b3-list-item--focus");
|
||||||
|
files.lastSelectedElement = parentElement;
|
||||||
const parentRect = parentElement.getBoundingClientRect();
|
const parentRect = parentElement.getBoundingClientRect();
|
||||||
const fileRect = files.element.getBoundingClientRect();
|
const fileRect = files.element.getBoundingClientRect();
|
||||||
if (parentRect.top < fileRect.top || parentRect.bottom > fileRect.bottom) {
|
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");
|
item.classList.remove("b3-list-item--focus");
|
||||||
});
|
});
|
||||||
nextElement.classList.add("b3-list-item--focus");
|
nextElement.classList.add("b3-list-item--focus");
|
||||||
|
files.lastSelectedElement = nextElement;
|
||||||
const nextRect = nextElement.getBoundingClientRect();
|
const nextRect = nextElement.getBoundingClientRect();
|
||||||
const fileRect = files.element.getBoundingClientRect();
|
const fileRect = files.element.getBoundingClientRect();
|
||||||
if (nextRect.top < fileRect.top || nextRect.bottom > fileRect.bottom) {
|
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");
|
item.classList.remove("b3-list-item--focus");
|
||||||
});
|
});
|
||||||
previousElement.classList.add("b3-list-item--focus");
|
previousElement.classList.add("b3-list-item--focus");
|
||||||
|
files.lastSelectedElement = previousElement;
|
||||||
const previousRect = previousElement.getBoundingClientRect();
|
const previousRect = previousElement.getBoundingClientRect();
|
||||||
const fileRect = files.element.getBoundingClientRect();
|
const fileRect = files.element.getBoundingClientRect();
|
||||||
if (previousRect.top < fileRect.top || previousRect.bottom > fileRect.bottom) {
|
if (previousRect.top < fileRect.top || previousRect.bottom > fileRect.bottom) {
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,14 @@ import {refreshFileTree} from "../../dialog/processSystem";
|
||||||
import {ipcRenderer} from "electron";
|
import {ipcRenderer} from "electron";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {hideTooltip, showTooltip} from "../../dialog/tooltip";
|
import {hideTooltip, showTooltip} from "../../dialog/tooltip";
|
||||||
|
import {selectOpenTab} from "./util";
|
||||||
|
|
||||||
export class Files extends Model {
|
export class Files extends Model {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
public parent: Tab;
|
public parent: Tab;
|
||||||
private actionsElement: HTMLElement;
|
|
||||||
public closeElement: HTMLElement;
|
public closeElement: HTMLElement;
|
||||||
private lastClickedFileItem: HTMLElement = null;
|
public lastSelectedElement: Element = null;
|
||||||
|
private actionsElement: HTMLElement;
|
||||||
|
|
||||||
constructor(options: { tab: Tab, app: App }) {
|
constructor(options: { tab: Tab, app: App }) {
|
||||||
super({
|
super({
|
||||||
|
|
@ -209,23 +210,7 @@ export class Files extends Model {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
break;
|
break;
|
||||||
} else if (type === "focus") {
|
} else if (type === "focus") {
|
||||||
let element = document.querySelector(".layout__wnd--active > .fn__flex > .layout-tab-bar > .item--focus") as HTMLElement;
|
selectOpenTab();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (type === "more") {
|
} else if (type === "more") {
|
||||||
|
|
@ -334,47 +319,37 @@ export class Files extends Model {
|
||||||
} else if (target.tagName === "LI") {
|
} else if (target.tagName === "LI") {
|
||||||
if (isOnlyMeta(event) && !event.altKey && !event.shiftKey) {
|
if (isOnlyMeta(event) && !event.altKey && !event.shiftKey) {
|
||||||
target.classList.toggle("b3-list-item--focus");
|
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 多选文档
|
// Shift+click 多选文档
|
||||||
event.preventDefault();
|
if (!this.lastSelectedElement) {
|
||||||
event.stopPropagation();
|
this.lastSelectedElement = this.element.querySelector(".b3-list-item--focus")||
|
||||||
|
this.element.querySelector(".b3-list-item");
|
||||||
if (!this.lastClickedFileItem) {
|
|
||||||
this.lastClickedFileItem = target;
|
|
||||||
this.setCurrent(target, false);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
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);
|
const endIndex = allFiles.indexOf(target);
|
||||||
|
|
||||||
if (startIndex === -1 || endIndex === -1) return;
|
|
||||||
|
|
||||||
// 确定选择范围
|
// 确定选择范围
|
||||||
const start = Math.min(startIndex, endIndex);
|
const start = Math.min(startIndex, endIndex);
|
||||||
const end = Math.max(startIndex, endIndex);
|
const end = Math.max(startIndex, endIndex)
|
||||||
|
|
||||||
// 清除现有选择
|
|
||||||
allFiles.forEach(file => {
|
|
||||||
(file as HTMLElement).classList.remove("b3-list-item--focus");
|
|
||||||
});
|
|
||||||
|
|
||||||
// 添加新选择
|
// 添加新选择
|
||||||
for (let i = start; i <= end; i++) {
|
for (let i = start; i <= end; i++) {
|
||||||
(allFiles[i] as HTMLElement).classList.add("b3-list-item--focus");
|
(allFiles[i] as HTMLElement).classList.add("b3-list-item--focus");
|
||||||
}
|
}
|
||||||
|
|
||||||
needFocus = false;
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
|
this.lastSelectedElement = target;
|
||||||
this.setCurrent(target, false);
|
this.setCurrent(target, false);
|
||||||
if (target.getAttribute("data-type") === "navigation-file") {
|
if (target.getAttribute("data-type") === "navigation-file") {
|
||||||
// 更新最后点击的文档项
|
// 更新最后点击的文档项
|
||||||
this.lastClickedFileItem = target;
|
|
||||||
needFocus = false;
|
needFocus = false;
|
||||||
if (target.getAttribute("data-opening")) {
|
if (target.getAttribute("data-opening")) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,13 @@ import {Tab} from "../Tab";
|
||||||
import {Graph} from "./Graph";
|
import {Graph} from "./Graph";
|
||||||
import {Outline} from "./Outline";
|
import {Outline} from "./Outline";
|
||||||
import {fixWndFlex1, getInstanceById, getWndByLayout, saveLayout, switchWnd} from "../util";
|
import {fixWndFlex1, getInstanceById, getWndByLayout, saveLayout, switchWnd} from "../util";
|
||||||
import {resizeTabs} from "../tabUtil";
|
import {getDockByType, resizeTabs} from "../tabUtil";
|
||||||
import {Backlink} from "./Backlink";
|
import {Backlink} from "./Backlink";
|
||||||
import {App} from "../../index";
|
import {App} from "../../index";
|
||||||
import {Wnd} from "../Wnd";
|
import {Wnd} from "../Wnd";
|
||||||
import {fetchSyncPost} from "../../util/fetch";
|
import {fetchSyncPost} from "../../util/fetch";
|
||||||
|
import {Files} from "./Files";
|
||||||
|
import {Editor} from "../../editor";
|
||||||
|
|
||||||
export const openBacklink = async (options: {
|
export const openBacklink = async (options: {
|
||||||
app: App,
|
app: App,
|
||||||
|
|
@ -234,3 +236,23 @@ export const clearOBG = () => {
|
||||||
item.render(undefined);
|
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);
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue