mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
new keybindings for switching tabs/blocks
This commit is contained in:
parent
4f74b232e2
commit
9f8042fb87
@ -86,6 +86,16 @@ function handleContextMenu(e: React.MouseEvent<HTMLDivElement>) {
|
|||||||
ContextMenuModel.showContextMenu(menu, e);
|
ContextMenuModel.showContextMenu(menu, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function switchTabAbs(index: number) {
|
||||||
|
const ws = globalStore.get(atoms.workspace);
|
||||||
|
const newTabIdx = index - 1;
|
||||||
|
if (newTabIdx < 0 || newTabIdx >= ws.tabids.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const newActiveTabId = ws.tabids[newTabIdx];
|
||||||
|
services.ObjectService.SetActiveTab(newActiveTabId);
|
||||||
|
}
|
||||||
|
|
||||||
function switchTab(offset: number) {
|
function switchTab(offset: number) {
|
||||||
const ws = globalStore.get(atoms.workspace);
|
const ws = globalStore.get(atoms.workspace);
|
||||||
const activeTabId = globalStore.get(atoms.tabAtom).oid;
|
const activeTabId = globalStore.get(atoms.tabAtom).oid;
|
||||||
@ -160,6 +170,24 @@ function findBlockAtPoint(m: Map<string, Bounds>, p: Point): string {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function switchBlockIdx(index: number) {
|
||||||
|
const tabId = globalStore.get(atoms.activeTabId);
|
||||||
|
const tabAtom = WOS.getWaveObjectAtom<Tab>(WOS.makeORef("tab", tabId));
|
||||||
|
const layoutTreeState = globalStore.get(getLayoutStateAtomForTab(tabId, tabAtom));
|
||||||
|
if (layoutTreeState?.leafs == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const newLeafIdx = index - 1;
|
||||||
|
if (newLeafIdx < 0 || newLeafIdx >= layoutTreeState.leafs.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const leaf = layoutTreeState.leafs[newLeafIdx];
|
||||||
|
if (leaf?.data?.blockId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setBlockFocus(leaf.data.blockId);
|
||||||
|
}
|
||||||
|
|
||||||
function switchBlock(tabId: string, offsetX: number, offsetY: number) {
|
function switchBlock(tabId: string, offsetX: number, offsetY: number) {
|
||||||
console.log("switch block", offsetX, offsetY);
|
console.log("switch block", offsetX, offsetY);
|
||||||
if (offsetY == 0 && offsetX == 0) {
|
if (offsetY == 0 && offsetX == 0) {
|
||||||
@ -339,14 +367,14 @@ const AppKeyHandlers = () => {
|
|||||||
|
|
||||||
function handleKeyUp(event: KeyboardEvent) {
|
function handleKeyUp(event: KeyboardEvent) {
|
||||||
const waveEvent = keyutil.adaptFromReactOrNativeKeyEvent(event);
|
const waveEvent = keyutil.adaptFromReactOrNativeKeyEvent(event);
|
||||||
if (waveEvent.key == "Meta" || waveEvent.key == "Shift") {
|
if (waveEvent.key == "Control" || waveEvent.key == "Shift") {
|
||||||
globalStore.set(simpleCmdShiftAtom, false);
|
globalStore.set(simpleCmdShiftAtom, false);
|
||||||
globalStore.set(atoms.cmdShiftDelayAtom, false);
|
globalStore.set(atoms.cmdShiftDelayAtom, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleKeyDown(waveEvent: WaveKeyboardEvent): boolean {
|
function handleKeyDown(waveEvent: WaveKeyboardEvent): boolean {
|
||||||
if ((waveEvent.key == "Meta" || waveEvent.key == "Shift") && waveEvent.cmd && waveEvent.shift) {
|
if ((waveEvent.key == "Control" || waveEvent.key == "Shift") && waveEvent.control && waveEvent.shift) {
|
||||||
globalStore.set(simpleCmdShiftAtom, true);
|
globalStore.set(simpleCmdShiftAtom, true);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const simpleState = globalStore.get(simpleCmdShiftAtom);
|
const simpleState = globalStore.get(simpleCmdShiftAtom);
|
||||||
@ -366,6 +394,21 @@ const AppKeyHandlers = () => {
|
|||||||
switchTab(-1);
|
switchTab(-1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
for (let idx = 1; idx <= 9; idx++) {
|
||||||
|
if (keyutil.checkKeyPressed(waveEvent, `Cmd:${idx}`)) {
|
||||||
|
switchTabAbs(idx);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let idx = 1; idx <= 9; idx++) {
|
||||||
|
if (
|
||||||
|
keyutil.checkKeyPressed(waveEvent, `Ctrl:Shift:c{Digit${idx}}`) ||
|
||||||
|
keyutil.checkKeyPressed(waveEvent, `Ctrl:Shift:c{Numpad${idx}}`)
|
||||||
|
) {
|
||||||
|
switchBlockIdx(idx);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowUp")) {
|
if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowUp")) {
|
||||||
switchBlock(tabId, 0, -1);
|
switchBlock(tabId, 0, -1);
|
||||||
return true;
|
return true;
|
||||||
|
@ -276,7 +276,7 @@
|
|||||||
&.is-layoutmode .block-mask-inner {
|
&.is-layoutmode .block-mask-inner {
|
||||||
margin-top: 35px; // TODO fix this magic
|
margin-top: 35px; // TODO fix this magic
|
||||||
background-color: rgba(0, 0, 0, 0.5);
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
height: 100%;
|
height: calc(100% - 35px);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
Loading…
Reference in New Issue
Block a user