Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/vs/workbench/contrib/scm/browser/scmHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { asCssVariable, ColorIdentifier, registerColor, transparent } from '../.
import { ISCMHistoryItem, ISCMHistoryItemGraphNode, ISCMHistoryItemRef, ISCMHistoryItemViewModel } from '../common/history.js';
import { rot } from '../../../../base/common/numbers.js';
import { svgElem } from '../../../../base/browser/dom.js';
import { compareHistoryItemRefs } from './util.js';

export const SWIMLANE_HEIGHT = 22;
export const SWIMLANE_WIDTH = 11;
Expand Down Expand Up @@ -256,7 +257,9 @@ export function renderSCMHistoryGraphPlaceholder(columns: ISCMHistoryItemGraphNo
export function toISCMHistoryItemViewModelArray(
historyItems: ISCMHistoryItem[],
colorMap = new Map<string, ColorIdentifier | undefined>(),
currentHistoryItemRef?: ISCMHistoryItemRef
currentHistoryItemRef?: ISCMHistoryItemRef,
currentHistoryItemRemoteRef?: ISCMHistoryItemRef,
currentHistoryItemBaseRef?: ISCMHistoryItemRef
): ISCMHistoryItemViewModel[] {
let colorIndex = -1;
const viewModels: ISCMHistoryItemViewModel[] = [];
Expand Down Expand Up @@ -333,6 +336,10 @@ export function toISCMHistoryItemViewModelArray(
return { ...ref, color };
});

// Sort references
references.sort((ref1, ref2) =>
compareHistoryItemRefs(ref1, ref2, currentHistoryItemRef, currentHistoryItemRemoteRef, currentHistoryItemBaseRef));

viewModels.push({
historyItem: {
...historyItem,
Expand Down
34 changes: 33 additions & 1 deletion src/vs/workbench/contrib/scm/browser/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ISCMHistoryItem, SCMHistoryItemLoadMoreTreeElement, SCMHistoryItemViewModelTreeElement } from '../common/history.js';
import { ISCMHistoryItem, ISCMHistoryItemRef, SCMHistoryItemLoadMoreTreeElement, SCMHistoryItemViewModelTreeElement } from '../common/history.js';
import { ISCMResource, ISCMRepository, ISCMResourceGroup, ISCMInput, ISCMActionButton, ISCMViewService, ISCMProvider } from '../common/scm.js';
import { IMenu, MenuItemAction } from '../../../../platform/actions/common/actions.js';
import { ActionBar, IActionViewItemProvider } from '../../../../base/browser/ui/actionbar/actionbar.js';
Expand Down Expand Up @@ -154,3 +154,35 @@ export function getHistoryItemEditorTitle(historyItem: ISCMHistoryItem, maxLengt

return `${historyItem.displayId ?? historyItem.id} - ${title}`;
}

export function compareHistoryItemRefs(
ref1: ISCMHistoryItemRef,
ref2: ISCMHistoryItemRef,
currentHistoryItemRef?: ISCMHistoryItemRef,
currentHistoryItemRemoteRef?: ISCMHistoryItemRef,
currentHistoryItemBaseRef?: ISCMHistoryItemRef
): number {
const getHistoryItemRefPriority = (ref: ISCMHistoryItemRef) => {
if (ref.id === currentHistoryItemRef?.id) {
return 1;
} else if (ref.id === currentHistoryItemRemoteRef?.id) {
return 2;
} else if (ref.id === currentHistoryItemBaseRef?.id) {
return 3;
} else if (ref.color !== undefined) {
return 4;
}

return 99;
};

// Assign priority (current > remote > base > color > name)
const ref1Priority = getHistoryItemRefPriority(ref1);
const ref2Priority = getHistoryItemRefPriority(ref2);

if (ref1Priority !== ref2Priority) {
return ref1Priority - ref2Priority;
} else {
return ref1.name.localeCompare(ref2.name);
}
}