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:
parent
bfe84db7eb
commit
be41b6b5d7
@ -97,11 +97,6 @@ export interface DockTabCloseEvent {
|
|||||||
tabId: TabId; // closed tab id
|
tabId: TabId; // closed tab id
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DockTabsNumberEvent {
|
|
||||||
currentTabsNumber: number; // number of open tabs
|
|
||||||
previousTabsNumber: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
storage: StorageHelper<DockStorageState>
|
storage: StorageHelper<DockStorageState>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,12 +110,11 @@ export const DockTabs = ({ tabs, autoFocus, selectedTab, onChangeTab, dockStore
|
|||||||
window.addEventListener("resize", onWindowResize);
|
window.addEventListener("resize", onWindowResize);
|
||||||
|
|
||||||
// update scroll state if tabs numbers has changed
|
// update scroll state if tabs numbers has changed
|
||||||
const onTabsNumberChangedDisposer = reaction(() => dockStore.tabsNumber, updateStateValues);
|
reaction(() => dockStore.tabsNumber, updateStateValues, { fireImmediately: true });
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener("resize", onWindowResize);
|
window.removeEventListener("resize", onWindowResize);
|
||||||
elem.current.removeEventListener("scroll", updateScrollPosition);
|
elem.current.removeEventListener("scroll", updateScrollPosition);
|
||||||
onTabsNumberChangedDisposer();
|
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@ -36,10 +36,7 @@ interface Dependencies {
|
|||||||
dockStore: DockStore
|
dockStore: DockStore
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Direction {
|
type Direction = 1 | -1;
|
||||||
next = "next",
|
|
||||||
prev = "prev",
|
|
||||||
}
|
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
class NonInjectedDock extends React.Component<Props & Dependencies> {
|
class NonInjectedDock extends React.Component<Props & Dependencies> {
|
||||||
@ -72,11 +69,11 @@ class NonInjectedDock extends React.Component<Props & Dependencies> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ctrlKey && code === "Period") {
|
if(ctrlKey && code === "Period") {
|
||||||
this.nextTab(Direction.next);
|
this.nextTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ctrlKey && code === "Comma") {
|
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();
|
this.element?.current.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
nextTab = (direction: Direction) => {
|
nextTab = (direction: Direction = 1) => {
|
||||||
const { tabs, selectedTab } = this.props.dockStore;
|
const { tabs, selectedTab } = this.props.dockStore;
|
||||||
const currentIndex = tabs.indexOf(selectedTab);
|
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;
|
// check if moving to the next tab is possible.
|
||||||
if (direction === Direction.prev && currentIndex!== -1 && nextIndex < 0) return;
|
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];
|
const nextElement = tabs[nextIndex];
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user