Skip to content

Commit 55b7da2

Browse files
committed
Sort branches to ensure current branch listed first
1 parent 6009bae commit 55b7da2

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/components/NewBranchDialog.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,26 @@ export class NewBranchDialog extends React.Component<
172172
* @returns fragment array
173173
*/
174174
private _renderItems() {
175-
return this.state.branches.map(this._renderItem, this);
175+
const current = this.props.model.currentBranch.name;
176+
return this.state.branches
177+
.slice()
178+
.sort(comparator)
179+
.map(this._renderItem, this);
180+
181+
/**
182+
* Comparator function for sorting branches.
183+
*
184+
* @private
185+
* @param a - first branch
186+
* @param b - second branch
187+
* @returns integer indicating sort order
188+
*/
189+
function comparator(a: Git.IBranch, b: Git.IBranch): number {
190+
if (a.name === current) {
191+
return -1;
192+
}
193+
return 0;
194+
}
176195
}
177196

178197
/**
@@ -183,10 +202,6 @@ export class NewBranchDialog extends React.Component<
183202
* @returns fragment
184203
*/
185204
private _renderItem(branch: Git.IBranch, idx: number) {
186-
// TODO: consider allowing users to branch from any branch, rather than just the current branch...
187-
if (branch.name !== this.state.current) {
188-
return null;
189-
}
190205
return (
191206
<ListItem
192207
button

0 commit comments

Comments
 (0)