🎨 Add shortcut keys for splitting the tab Fix https://github.com/siyuan-note/siyuan/issues/9470

This commit is contained in:
Vanessa 2023-10-21 22:33:20 +08:00
parent b63cc1839a
commit c7c23cc1ea
3 changed files with 34 additions and 1 deletions

View file

@ -10,7 +10,7 @@ import {
import {newFile} from "../../util/newFile";
import {Constants} from "../../constants";
import {openSetting} from "../../config";
import {getDockByType, getInstanceById} from "../../layout/util";
import {copyTab, getDockByType, getInstanceById, resizeTabs} from "../../layout/util";
import {Tab} from "../../layout/Tab";
import {Editor} from "../../editor";
import {setEditMode} from "../../protyle/util/setEditMode";
@ -1329,6 +1329,31 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
return;
}
if ((matchHotKey(window.siyuan.config.keymap.general.splitLR.custom, event) ||
matchHotKey(window.siyuan.config.keymap.general.splitMoveR.custom, event) ||
matchHotKey(window.siyuan.config.keymap.general.splitTB.custom, event) ||
matchHotKey(window.siyuan.config.keymap.general.splitMoveB.custom, event)) && !event.repeat) {
event.preventDefault();
const activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
if (activeTabElement) {
const tab = getInstanceById(activeTabElement.getAttribute("data-id")) as Tab;
if (tab) {
if (matchHotKey(window.siyuan.config.keymap.general.splitLR.custom, event)) {
tab.parent.split("lr").addTab(copyTab(app, tab));
} else if (matchHotKey(window.siyuan.config.keymap.general.splitTB.custom, event)) {
tab.parent.split("tb").addTab(copyTab(app, tab));
} else if (tab.parent.children.length > 1) {
const newWnd = tab.parent.split(matchHotKey(window.siyuan.config.keymap.general.splitMoveB.custom, event) ? "tb" : "lr");
newWnd.headersElement.append(tab.headElement);
newWnd.headersElement.parentElement.classList.remove("fn__none");
newWnd.moveTab(tab);
resizeTabs();
}
}
}
return;
}
if (matchHotKey(window.siyuan.config.keymap.general.stickSearch.custom, event)) {
if (getSelection().rangeCount > 0) {
const range = getSelection().getRangeAt(0);

View file

@ -256,6 +256,10 @@ export abstract class Constants {
move: {default: "", custom: ""},
selectOpen1: {default: "", custom: ""},
toggleDock: {default: "", custom: ""},
splitLR: {default: "", custom: ""},
splitMoveR: {default: "", custom: ""},
splitTB: {default: "", custom: ""},
splitMoveB: {default: "", custom: ""},
},
editor: {
general: {

View file

@ -119,6 +119,7 @@ const closeMenu = (tab: Tab) => {
const splitSubMenu = (app: App, tab: Tab) => {
const subMenus: IMenu[] = [{
icon: "iconSplitLR",
accelerator: window.siyuan.config.keymap.general.splitLR.custom,
label: window.siyuan.languages.splitLR,
click: () => {
tab.parent.split("lr").addTab(copyTab(app, tab));
@ -127,6 +128,7 @@ const splitSubMenu = (app: App, tab: Tab) => {
if (tab.parent.children.length > 1) {
subMenus.push({
icon: "iconLayoutRight",
accelerator: window.siyuan.config.keymap.general.splitMoveR.custom,
label: window.siyuan.languages.splitMoveR,
click: () => {
const newWnd = tab.parent.split("lr");
@ -139,6 +141,7 @@ const splitSubMenu = (app: App, tab: Tab) => {
}
subMenus.push({
icon: "iconSplitTB",
accelerator: window.siyuan.config.keymap.general.splitTB.custom,
label: window.siyuan.languages.splitTB,
click: () => {
tab.parent.split("tb").addTab(copyTab(app, tab));
@ -148,6 +151,7 @@ const splitSubMenu = (app: App, tab: Tab) => {
if (tab.parent.children.length > 1) {
subMenus.push({
icon: "iconLayoutBottom",
accelerator: window.siyuan.config.keymap.general.splitMoveB.custom,
label: window.siyuan.languages.splitMoveB,
click: () => {
const newWnd = tab.parent.split("tb");