Skip to content

Commit 14fae5b

Browse files
committed
FIXED: do not change active view in singleView mode
CLEANED-UP: winState.getActiveView(bool) -> winState.getActiveView/getInactiveView
1 parent c4544d4 commit 14fae5b

File tree

5 files changed

+48
-16
lines changed

5 files changed

+48
-16
lines changed

e2e/cypress/integration/keyboard.hotkeys.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ describe("keyboard hotkeys", () => {
1717
stubs.navHistory.push(cy.spy(cache, "navHistory"));
1818
}
1919
}
20+
21+
// activate splitView mode
22+
const winState = win.appState.winStates[0];
23+
winState.splitView = true;
2024
});
2125
}
2226

@@ -73,6 +77,18 @@ describe("keyboard hotkeys", () => {
7377
});
7478
});
7579

80+
it("should not change view in single view mode", () => {
81+
cy.get("#view_0").should("have.class", "active");
82+
cy.get("#view_1").should("not.have.class", "active");
83+
84+
cy.get('.data-cy-toggle-splitview')
85+
.click();
86+
87+
cy.triggerHotkey(`{ctrl}{shift}{rightarrow}`).then(() => {
88+
cy.get("#view_1").should("not.have.class", "active");
89+
cy.get("#view_0").should("have.class", "active");
90+
});
91+
});
7692
// it("should open devtools", () => {
7793
// cy.triggerHotkey(`{alt}${MOD_KEY}i`).then(() => {
7894
// expect(ipcRenderer.send).to.be.calledOnce;

src/components/shortcuts/KeyboardHotkeys.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ class KeyboardHotkeysClass extends React.Component<WithNamespaces> {
8383

8484
onNextView = () => {
8585
const winState = this.appState.winStates[0];
86-
const nextView = winState.getActiveView(false);
86+
// do nothing if single view
87+
if (winState.splitView) {
88+
// get the view that's not active
89+
const nextView = winState.getInactiveView();
8790

88-
winState.setActiveView(nextView.viewId);
91+
winState.setActiveView(nextView.viewId);
92+
}
8993
};
9094

9195
onBackwardHistory = () => {

src/components/shortcuts/MenuAccelerators.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,20 @@ class MenuAcceleratorsClass extends React.Component<IProps> {
131131
}
132132
};
133133

134-
onNextTab = () => {
134+
cycleTab = (direction: 1|-1) => {
135135
if (this.appState.isExplorer) {
136136
const winState = this.appState.winStates[0];
137137
const viewState = winState.getActiveView();
138-
viewState.cycleTab(1);
138+
viewState.cycleTab(direction);
139139
}
140+
}
141+
142+
onNextTab = () => {
143+
this.cycleTab(1);
140144
};
141145

142146
onPreviousTab = () => {
143-
if (this.appState.isExplorer) {
144-
const winState = this.appState.winStates[0];
145-
const viewState = winState.getActiveView();
146-
viewState.cycleTab(-1);
147-
}
147+
this.cycleTab(-1);
148148
};
149149

150150
onNewTab = () => {

src/state/appState.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export class AppState {
250250
}
251251

252252
getViewFromCache(cache: FileState) {
253-
const winState = this.winStates[0];
253+
const winState = this.winStates[0];
254254
const viewId = cache.viewId;
255255
return winState.getView(viewId);
256256
}
@@ -262,18 +262,18 @@ export class AppState {
262262
*/
263263
getInactiveViewVisibleCache(): FileState {
264264
const winState = this.winStates[0];
265-
const view = winState.getActiveView(false);
265+
const view = winState.getInactiveView();
266266
return view.caches.find(cache => cache.isVisible === true);
267267
}
268268

269269
getViewVisibleCache(viewId: number): FileState {
270-
const winState = this.winStates[0];
270+
const winState = this.winStates[0];
271271
const view = winState.getView(viewId);
272272
return view.caches.find(cache => cache.isVisible === true);
273273
}
274274

275275
getCachesForView(viewId: number) {
276-
const winState = this.winStates[0];
276+
const winState = this.winStates[0];
277277
const view = winState.getView(viewId);
278278
return view.caches;
279279
}
@@ -378,7 +378,7 @@ export class AppState {
378378

379379
getActiveCache(): FileState {
380380
const winState = this.winStates[0];
381-
const view = winState.getActiveView(true);
381+
const view = winState.getActiveView();
382382
return this.isExplorer
383383
? view.caches.find(cache => cache.isVisible === true)
384384
: null;

src/state/winState.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,25 @@ export class WinState {
8080
@action
8181
setActiveView(viewId: number) {
8282
console.log("setting active view", viewId);
83-
const previous = this.getActiveView(true);
83+
const previous = this.getActiveView();
8484
const next = this.getView(viewId);
8585
previous.isActive = false;
8686
next.isActive = true;
8787
}
8888

89-
getActiveView(isActive = true): ViewState {
89+
getActiveView():ViewState {
90+
return this.getViewByActive(true);
91+
}
92+
93+
getInactiveView():ViewState {
94+
return this.getViewByActive(false);
95+
}
96+
97+
/**
98+
* returns active or invactive view
99+
* @param isActive if set to true returns the active view, otherwise inactive one
100+
*/
101+
getViewByActive(isActive = true): ViewState {
90102
return this.views.find(view => view.isActive === isActive);
91103
}
92104

0 commit comments

Comments
 (0)