mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
🐛 当前页签没有激活时编辑器没有初始化
This commit is contained in:
parent
bf2bd552ff
commit
6cd50643c6
2 changed files with 42 additions and 43 deletions
|
|
@ -23,7 +23,7 @@ export class Menus {
|
||||||
const dataType = target.getAttribute("data-type");
|
const dataType = target.getAttribute("data-type");
|
||||||
if (dataType === "tab-header") {
|
if (dataType === "tab-header") {
|
||||||
this.unselect();
|
this.unselect();
|
||||||
initTabMenu(dataType, (getInstanceById(target.getAttribute("data-id")) as Tab).model).popup({
|
initTabMenu((getInstanceById(target.getAttribute("data-id")) as Tab)).popup({
|
||||||
x: event.clientX,
|
x: event.clientX,
|
||||||
y: event.clientY
|
y: event.clientY
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,18 @@ import {copyTab} from "../layout/util";
|
||||||
import {copySubMenu} from "./commonMenuItem";
|
import {copySubMenu} from "./commonMenuItem";
|
||||||
import {Model} from "../layout/Model";
|
import {Model} from "../layout/Model";
|
||||||
|
|
||||||
const closeMenu = (model: Model) => {
|
const closeMenu = (tab: Tab) => {
|
||||||
const currentTab = model.parent;
|
|
||||||
const allTabs: Tab[] = [];
|
const allTabs: Tab[] = [];
|
||||||
const unmodifiedTabs: Tab[] = [];
|
const unmodifiedTabs: Tab[] = [];
|
||||||
const leftTabs: Tab[] = [];
|
const leftTabs: Tab[] = [];
|
||||||
const rightTabs: Tab[] = [];
|
const rightTabs: Tab[] = [];
|
||||||
let midIndex = -1;
|
let midIndex = -1;
|
||||||
currentTab.parent.children.forEach((item: Tab, index: number) => {
|
tab.parent.children.forEach((item: Tab, index: number) => {
|
||||||
const editor = item.model as Editor;
|
const editor = item.model as Editor;
|
||||||
if (!editor || (editor.editor?.protyle && !editor.editor?.protyle.updated)) {
|
if (!editor || (editor.editor?.protyle && !editor.editor?.protyle.updated)) {
|
||||||
unmodifiedTabs.push(item);
|
unmodifiedTabs.push(item);
|
||||||
}
|
}
|
||||||
if (item.id === currentTab.id) {
|
if (item.id === tab.id) {
|
||||||
midIndex = index;
|
midIndex = index;
|
||||||
}
|
}
|
||||||
if (midIndex === -1) {
|
if (midIndex === -1) {
|
||||||
|
|
@ -33,7 +32,7 @@ const closeMenu = (model: Model) => {
|
||||||
label: window.siyuan.languages.close,
|
label: window.siyuan.languages.close,
|
||||||
accelerator: window.siyuan.config.keymap.general.closeTab.custom,
|
accelerator: window.siyuan.config.keymap.general.closeTab.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
currentTab.parent.removeTab(currentTab.id);
|
tab.parent.removeTab(tab.id);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
if (allTabs.length > 1) {
|
if (allTabs.length > 1) {
|
||||||
|
|
@ -41,12 +40,12 @@ const closeMenu = (model: Model) => {
|
||||||
label: window.siyuan.languages.closeOthers,
|
label: window.siyuan.languages.closeOthers,
|
||||||
click: async () => {
|
click: async () => {
|
||||||
for (let index = 0; index < allTabs.length; index++) {
|
for (let index = 0; index < allTabs.length; index++) {
|
||||||
if (allTabs[index].id !== currentTab.id && !allTabs[index].headElement.classList.contains("item--pin")) {
|
if (allTabs[index].id !== tab.id && !allTabs[index].headElement.classList.contains("item--pin")) {
|
||||||
await allTabs[index].parent.removeTab(allTabs[index].id, true);
|
await allTabs[index].parent.removeTab(allTabs[index].id, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!currentTab.headElement.parentElement.querySelector(".item--focus")) {
|
if (!tab.headElement.parentElement.querySelector(".item--focus")) {
|
||||||
currentTab.parent.switchTab(currentTab.headElement, true);
|
tab.parent.switchTab(tab.headElement, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -72,8 +71,8 @@ const closeMenu = (model: Model) => {
|
||||||
await leftTabs[index].parent.removeTab(leftTabs[index].id);
|
await leftTabs[index].parent.removeTab(leftTabs[index].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!currentTab.headElement.parentElement.querySelector(".item--focus")) {
|
if (!tab.headElement.parentElement.querySelector(".item--focus")) {
|
||||||
currentTab.parent.switchTab(currentTab.headElement, true);
|
tab.parent.switchTab(tab.headElement, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -87,8 +86,8 @@ const closeMenu = (model: Model) => {
|
||||||
await rightTabs[index].parent.removeTab(rightTabs[index].id);
|
await rightTabs[index].parent.removeTab(rightTabs[index].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!currentTab.headElement.parentElement.querySelector(".item--focus")) {
|
if (!tab.headElement.parentElement.querySelector(".item--focus")) {
|
||||||
currentTab.parent.switchTab(currentTab.headElement, true);
|
tab.parent.switchTab(tab.headElement, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -102,8 +101,8 @@ const closeMenu = (model: Model) => {
|
||||||
await unmodifiedTabs[index].parent.removeTab(unmodifiedTabs[index].id);
|
await unmodifiedTabs[index].parent.removeTab(unmodifiedTabs[index].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currentTab.headElement.parentElement && !currentTab.headElement.parentElement.querySelector(".item--focus")) {
|
if (tab.headElement.parentElement && !tab.headElement.parentElement.querySelector(".item--focus")) {
|
||||||
currentTab.parent.switchTab(currentTab.headElement, true);
|
tab.parent.switchTab(tab.headElement, true);
|
||||||
} else if (allTabs[0].headElement.parentElement) {
|
} else if (allTabs[0].headElement.parentElement) {
|
||||||
allTabs[0].parent.switchTab(allTabs[0].headElement, true);
|
allTabs[0].parent.switchTab(allTabs[0].headElement, true);
|
||||||
}
|
}
|
||||||
|
|
@ -114,24 +113,22 @@ const closeMenu = (model: Model) => {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
};
|
};
|
||||||
|
|
||||||
const splitSubMenu = (model: Model) => {
|
const splitSubMenu = (tab: Tab) => {
|
||||||
const subMenus: IMenu[] = [{
|
const subMenus: IMenu[] = [{
|
||||||
icon: "iconSplitLR",
|
icon: "iconSplitLR",
|
||||||
label: window.siyuan.languages.splitLR,
|
label: window.siyuan.languages.splitLR,
|
||||||
click: () => {
|
click: () => {
|
||||||
const currentTab = model.parent;
|
tab.parent.split("lr").addTab(copyTab(tab));
|
||||||
currentTab.parent.split("lr").addTab(copyTab(currentTab));
|
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
const currentTab = model.parent;
|
if (tab.parent.children.length > 1) {
|
||||||
if (currentTab.parent.children.length > 1) {
|
|
||||||
subMenus.push({
|
subMenus.push({
|
||||||
icon: "iconRight",
|
icon: "iconRight",
|
||||||
label: window.siyuan.languages.splitMoveR,
|
label: window.siyuan.languages.splitMoveR,
|
||||||
click: () => {
|
click: () => {
|
||||||
const newWnd = currentTab.parent.split("lr");
|
const newWnd = tab.parent.split("lr");
|
||||||
newWnd.headersElement.append(currentTab.headElement);
|
newWnd.headersElement.append(tab.headElement);
|
||||||
newWnd.moveTab(currentTab);
|
newWnd.moveTab(tab);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -139,31 +136,32 @@ const splitSubMenu = (model: Model) => {
|
||||||
icon: "iconSplitTB",
|
icon: "iconSplitTB",
|
||||||
label: window.siyuan.languages.splitTB,
|
label: window.siyuan.languages.splitTB,
|
||||||
click: () => {
|
click: () => {
|
||||||
const currentTab = model.parent;
|
tab.parent.split("tb").addTab(copyTab(tab));
|
||||||
currentTab.parent.split("tb").addTab(copyTab(currentTab));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (currentTab.parent.children.length > 1) {
|
if (tab.parent.children.length > 1) {
|
||||||
subMenus.push({
|
subMenus.push({
|
||||||
icon: "iconDown",
|
icon: "iconDown",
|
||||||
label: window.siyuan.languages.splitMoveB,
|
label: window.siyuan.languages.splitMoveB,
|
||||||
click: () => {
|
click: () => {
|
||||||
const newWnd = currentTab.parent.split("tb");
|
const newWnd = tab.parent.split("tb");
|
||||||
newWnd.headersElement.append(currentTab.headElement);
|
newWnd.headersElement.append(tab.headElement);
|
||||||
newWnd.moveTab(currentTab);
|
newWnd.moveTab(tab);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return subMenus;
|
return subMenus;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initTabMenu = (type: string, model: Model) => {
|
export const initTabMenu = (tab: Tab) => {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
closeMenu(model);
|
closeMenu(tab);
|
||||||
|
const model = tab.model;
|
||||||
|
if (model) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
label: window.siyuan.languages.split,
|
label: window.siyuan.languages.split,
|
||||||
submenu: splitSubMenu(model)
|
submenu: splitSubMenu(tab)
|
||||||
}).element);
|
}).element);
|
||||||
if (model instanceof Editor) {
|
if (model instanceof Editor) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
@ -173,12 +171,13 @@ export const initTabMenu = (type: string, model: Model) => {
|
||||||
submenu: copySubMenu(model.editor.protyle.block.rootID, "", false)
|
submenu: copySubMenu(model.editor.protyle.block.rootID, "", false)
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
if (model.parent.headElement.classList.contains("item--pin")) {
|
}
|
||||||
|
if (tab.headElement.classList.contains("item--pin")) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
label: window.siyuan.languages.unpin,
|
label: window.siyuan.languages.unpin,
|
||||||
icon: "iconPin",
|
icon: "iconPin",
|
||||||
click: () => {
|
click: () => {
|
||||||
model.parent.unpin();
|
tab.unpin();
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -186,7 +185,7 @@ export const initTabMenu = (type: string, model: Model) => {
|
||||||
label: window.siyuan.languages.pin,
|
label: window.siyuan.languages.pin,
|
||||||
icon: "iconPin",
|
icon: "iconPin",
|
||||||
click: () => {
|
click: () => {
|
||||||
model.parent.pin();
|
tab.pin();
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue