1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

PR fixes and improvements

Signed-off-by: DmitriyNoa <dmytro.zharkov@gmail.com>
This commit is contained in:
DmitriyNoa 2022-01-31 14:20:17 +01:00
parent bfe84db7eb
commit be41b6b5d7
3 changed files with 11 additions and 17 deletions

View File

@ -97,11 +97,6 @@ export interface DockTabCloseEvent {
tabId: TabId; // closed tab id
}
export interface DockTabsNumberEvent {
currentTabsNumber: number; // number of open tabs
previousTabsNumber: number;
}
interface Dependencies {
storage: StorageHelper<DockStorageState>
}

View File

@ -110,12 +110,11 @@ export const DockTabs = ({ tabs, autoFocus, selectedTab, onChangeTab, dockStore
window.addEventListener("resize", onWindowResize);
// update scroll state if tabs numbers has changed
const onTabsNumberChangedDisposer = reaction(() => dockStore.tabsNumber, updateStateValues);
reaction(() => dockStore.tabsNumber, updateStateValues, { fireImmediately: true });
return () => {
window.removeEventListener("resize", onWindowResize);
elem.current.removeEventListener("scroll", updateScrollPosition);
onTabsNumberChangedDisposer();
};
}, []);

View File

@ -36,10 +36,7 @@ interface Dependencies {
dockStore: DockStore
}
enum Direction {
next = "next",
prev = "prev",
}
type Direction = 1 | -1;
@observer
class NonInjectedDock extends React.Component<Props & Dependencies> {
@ -72,11 +69,11 @@ class NonInjectedDock extends React.Component<Props & Dependencies> {
}
if(ctrlKey && code === "Period") {
this.nextTab(Direction.next);
this.nextTab();
}
if(ctrlKey && code === "Comma") {
this.nextTab(Direction.prev);
this.nextTab(-1);
}
};
@ -88,13 +85,16 @@ class NonInjectedDock extends React.Component<Props & Dependencies> {
this.element?.current.focus();
};
nextTab = (direction: Direction) => {
nextTab = (direction: Direction = 1) => {
const { tabs, selectedTab } = this.props.dockStore;
const currentIndex = tabs.indexOf(selectedTab);
const nextIndex = direction === Direction.next ? currentIndex + 1 : currentIndex - 1;
const nextIndex = currentIndex + direction;
if (direction === Direction.next && currentIndex!== -1 && nextIndex >= tabs.length) return;
if (direction === Direction.prev && currentIndex!== -1 && nextIndex < 0) return;
// check if moving to the next tab is possible.
if (direction === 1 && currentIndex!== -1 && nextIndex >= tabs.length) return;
// check if moving to the previous tab is possible
if (direction === -1 && currentIndex!== -1 && nextIndex < 0) return;
const nextElement = tabs[nextIndex];