mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add change tab on keydown
Signed-off-by: DmitriyNoa <dmytro.zharkov@gmail.com>
This commit is contained in:
parent
61345aaf72
commit
4eac1b180b
@ -36,6 +36,11 @@ interface Dependencies {
|
|||||||
dockStore: DockStore
|
dockStore: DockStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Direction {
|
||||||
|
next = "next",
|
||||||
|
prev = "prev",
|
||||||
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
class NonInjectedDock extends React.Component<Props & Dependencies> {
|
class NonInjectedDock extends React.Component<Props & Dependencies> {
|
||||||
private element = React.createRef<HTMLDivElement>();
|
private element = React.createRef<HTMLDivElement>();
|
||||||
@ -51,6 +56,7 @@ class NonInjectedDock extends React.Component<Props & Dependencies> {
|
|||||||
onKeyDown = (evt: KeyboardEvent) => {
|
onKeyDown = (evt: KeyboardEvent) => {
|
||||||
const { close, selectedTab, closeTab } = this.props.dockStore;
|
const { close, selectedTab, closeTab } = this.props.dockStore;
|
||||||
const { code, ctrlKey, metaKey, shiftKey } = evt;
|
const { code, ctrlKey, metaKey, shiftKey } = evt;
|
||||||
|
|
||||||
// Determine if user working inside <Dock/> or using any other areas in app
|
// Determine if user working inside <Dock/> or using any other areas in app
|
||||||
const dockIsFocused = this.element?.current.contains(document.activeElement);
|
const dockIsFocused = this.element?.current.contains(document.activeElement);
|
||||||
|
|
||||||
@ -64,6 +70,14 @@ class NonInjectedDock extends React.Component<Props & Dependencies> {
|
|||||||
closeTab(selectedTab.id);
|
closeTab(selectedTab.id);
|
||||||
this.element?.current.focus(); // Avoid loosing focus when closing tab
|
this.element?.current.focus(); // Avoid loosing focus when closing tab
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ctrlKey && code === "Period") {
|
||||||
|
this.nextTab(Direction.next);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ctrlKey && code === "Comma") {
|
||||||
|
this.nextTab(Direction.prev);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onChangeTab = (tab: DockTab) => {
|
onChangeTab = (tab: DockTab) => {
|
||||||
@ -74,6 +88,19 @@ class NonInjectedDock extends React.Component<Props & Dependencies> {
|
|||||||
this.element?.current.focus();
|
this.element?.current.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
nextTab = (direction: Direction) => {
|
||||||
|
const { tabs, selectedTab } = this.props.dockStore;
|
||||||
|
const currentIndex = tabs.indexOf(selectedTab);
|
||||||
|
const nextIndex = direction === Direction.next ? currentIndex + 1 : currentIndex - 1;
|
||||||
|
|
||||||
|
if (direction === Direction.next && currentIndex!== -1 && nextIndex >= tabs.length) return;
|
||||||
|
if (direction === Direction.prev && currentIndex!== -1 && nextIndex < 0) return;
|
||||||
|
|
||||||
|
const nextElement = tabs[nextIndex];
|
||||||
|
|
||||||
|
this.onChangeTab(nextElement);
|
||||||
|
};
|
||||||
|
|
||||||
renderTab(tab: DockTab) {
|
renderTab(tab: DockTab) {
|
||||||
switch (tab.kind) {
|
switch (tab.kind) {
|
||||||
case TabKind.CREATE_RESOURCE:
|
case TabKind.CREATE_RESOURCE:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user