mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-17 12:10:22 -05:00
just move a single repository up
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
import { workspace, WorkspaceFoldersChangeEvent, Uri, window, Event, EventEmitter, QuickPickItem, Disposable, SourceControl, SourceControlResourceGroup, TextEditor, Memento, ConfigurationChangeEvent } from 'vscode';
|
||||
import { Repository, RepositoryState } from './repository';
|
||||
import { memoize, sequentialize, debounce } from './decorators';
|
||||
import { dispose, anyEvent, filterEvent, IDisposable, isDescendant } from './util';
|
||||
import { dispose, anyEvent, filterEvent, IDisposable, isDescendant, find, firstIndex } from './util';
|
||||
import { Git, GitErrorCodes } from './git';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
@@ -257,31 +257,13 @@ export class Model {
|
||||
}
|
||||
|
||||
const picks = this.openRepositories.map((e, index) => new RepositoryPick(e.repository, index));
|
||||
|
||||
// Sort picks such that repositories containing the active text editor
|
||||
// appear first.
|
||||
const active = window.activeTextEditor;
|
||||
if (active && active.document.fileName) {
|
||||
const hasActiveEditor = (root: string) => {
|
||||
const relative = path.relative(root, active.document.fileName);
|
||||
return !!relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
||||
};
|
||||
picks.sort((a, b) => {
|
||||
const aHas = hasActiveEditor(a.repository.root);
|
||||
const bHas = hasActiveEditor(b.repository.root);
|
||||
if (aHas !== bHas) {
|
||||
return aHas ? -1 : 1;
|
||||
}
|
||||
if (aHas && a.repository.root.length !== b.repository.root.length) {
|
||||
// Both a and b contain the active editor document, so one
|
||||
// is an ancestor of the other. We prefer to return the
|
||||
// child (likely a submodule) since the active editor will
|
||||
// be part of that repo. Child is the longer path.
|
||||
return b.repository.root.length - a.repository.root.length;
|
||||
}
|
||||
// Otherwise everything else is equal, so keeps the positions stable
|
||||
return a.index - b.index;
|
||||
});
|
||||
const repository = active && this.getRepository(active.document.fileName);
|
||||
const index = firstIndex(picks, pick => pick.repository === repository);
|
||||
|
||||
// Move repository pick containing the active text editor to appear first
|
||||
if (index > -1) {
|
||||
picks.unshift(...picks.splice(index, 1));
|
||||
}
|
||||
|
||||
const placeHolder = localize('pick repo', "Choose a repository");
|
||||
|
||||
@@ -195,6 +195,16 @@ export function uniqueFilter<T>(keyFn: (t: T) => string): (t: T) => boolean {
|
||||
};
|
||||
}
|
||||
|
||||
export function firstIndex<T>(array: T[], fn: (t: T) => boolean): number {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (fn(array[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
export function find<T>(array: T[], fn: (t: T) => boolean): T | undefined {
|
||||
let result: T | undefined = undefined;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user