Skip to content

Commit

Permalink
🎨 Add shortcut keys for splitting the tab Fix #9470
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Oct 21, 2023
1 parent b63cc18 commit c7c23cc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
27 changes: 26 additions & 1 deletion app/src/boot/globalEvent/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 4 additions & 0 deletions app/src/menus/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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");
Expand All @@ -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));
Expand All @@ -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");
Expand Down

0 comments on commit c7c23cc

Please sign in to comment.