Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1001 from mkenne11/circular_next_prev_pane
Browse files Browse the repository at this point in the history
Allow wrap around when advancing next & previous pane
  • Loading branch information
drew-gross authored Mar 25, 2017
2 parents 70e8b42 + c2782bb commit 7b66ee5
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/utils/PaneTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ export abstract class PaneList {
}
}

/**
* Returns the pane previous to the 'pane' argument provided.
* @param {Pane} pane The reference pane.
* @returns {Pane}
*/
previous(pane: Pane): Pane {
const firstPaneIndex = 0;
const lastPaneIndex = this.size - 1;
let paneIndex = 0;

this.forEach((current, index) => {
Expand All @@ -89,15 +96,25 @@ export abstract class PaneList {
let previous = pane;

this.forEach((current, index) => {
if (index === paneIndex - 1) {
if (paneIndex === firstPaneIndex) {
if (index === lastPaneIndex)
previous = current;
} else if (index === paneIndex - 1) {
previous = current;
}
});

return previous;
}

/**
* Returns the pane next after the 'pane' argument provided.
* @param {Pane} pane The reference pane.
* @returns {Pane}
*/
next(pane: Pane): Pane {
const firstPaneIndex = 0;
const lastPaneIndex = this.size - 1;
let paneIndex = 0;

this.forEach((current, index) => {
Expand All @@ -109,7 +126,10 @@ export abstract class PaneList {
let next = pane;

this.forEach((current, index) => {
if (index === paneIndex + 1) {
if (paneIndex === lastPaneIndex) {
if (index === firstPaneIndex)
next = current;
} else if (index === paneIndex + 1) {
next = current;
}
});
Expand Down

0 comments on commit 7b66ee5

Please sign in to comment.