SCM - use subject as the title of the multi-file diff editor (#269347)

This commit is contained in:
Ladislau Szomoru
2025-10-01 16:55:05 +02:00
committed by GitHub
parent d51431eb17
commit 597148770d
5 changed files with 13 additions and 16 deletions

View File

@@ -14,7 +14,7 @@ import { Model } from './model';
import { GitResourceGroup, Repository, Resource, ResourceGroupType } from './repository';
import { DiffEditorSelectionHunkToolbarContext, LineChange, applyLineChanges, getIndexDiffInformation, getModifiedRange, getWorkingTreeDiffInformation, intersectDiffWithRange, invertLineChange, toLineChanges, toLineRanges, compareLineChanges } from './staging';
import { fromGitUri, toGitUri, isGitUri, toMergeUris, toMultiFileDiffEditorUris } from './uri';
import { DiagnosticSeverityConfig, dispose, fromNow, grep, isDefined, isDescendant, isLinuxSnap, isRemote, isWindows, pathEquals, relativePath, toDiagnosticSeverity, truncate } from './util';
import { DiagnosticSeverityConfig, dispose, fromNow, grep, isDefined, isDescendant, isLinuxSnap, isRemote, isWindows, pathEquals, relativePath, subject, toDiagnosticSeverity, truncate } from './util';
import { GitTimelineItem } from './timelineProvider';
import { ApiRepository } from './api/api1';
import { getRemoteSourceActions, pickRemoteSource } from './remoteSource';
@@ -4906,7 +4906,7 @@ export class CommandCenter {
const changes = await repository.diffTrees(commitParentId, commit.hash);
const resources = changes.map(c => toMultiFileDiffEditorUris(c, commitParentId, commit.hash));
const title = `${item.shortRef} - ${truncate(commit.message)}`;
const title = `${item.shortRef} - ${subject(commit.message)}`;
const multiDiffSourceUri = Uri.from({ scheme: 'scm-history-item', path: `${repository.root}/${commitParentId}..${commit.hash}` });
const reveal = { modifiedUri: toGitUri(uri, commit.hash) };
@@ -5172,7 +5172,7 @@ export class CommandCenter {
const commitShortHashLength = config.get<number>('commitShortHashLength', 7);
const commit = await repository.getCommit(historyItemId);
const title = `${truncate(historyItemId, commitShortHashLength, false)} - ${truncate(commit.message)}`;
const title = `${truncate(historyItemId, commitShortHashLength, false)} - ${subject(commit.message)}`;
const historyItemParentId = commit.parents.length > 0 ? commit.parents[0] : await repository.getEmptyTree();
const multiDiffSourceUri = Uri.from({ scheme: 'scm-history-item', path: `${repository.root}/${historyItemParentId}..${historyItemId}` });

View File

@@ -6,7 +6,7 @@
import { CancellationToken, Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, SourceControlHistoryItem, SourceControlHistoryItemChange, SourceControlHistoryOptions, SourceControlHistoryProvider, ThemeIcon, Uri, window, LogOutputChannel, SourceControlHistoryItemRef, l10n, SourceControlHistoryItemRefsChangeEvent, workspace, ConfigurationChangeEvent } from 'vscode';
import { Repository, Resource } from './repository';
import { IDisposable, deltaHistoryItemRefs, dispose, filterEvent, truncate } from './util';
import { IDisposable, deltaHistoryItemRefs, dispose, filterEvent, subject, truncate } from './util';
import { toMultiFileDiffEditorUris } from './uri';
import { AvatarQuery, AvatarQueryCommit, Branch, LogOptions, Ref, RefType } from './api/git';
import { emojify, ensureEmojis } from './emoji';
@@ -290,18 +290,13 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
const messageWithLinks = await provideSourceControlHistoryItemMessageLinks(
this.historyItemDetailProviderRegistry, this.repository, message) ?? message;
const newLineIndex = message.indexOf('\n');
const subject = newLineIndex !== -1
? `${truncate(message, newLineIndex, false)}`
: message;
const avatarUrl = commitAvatars?.get(commit.hash);
const references = this._resolveHistoryItemRefs(commit);
historyItems.push({
id: commit.hash,
parentIds: commit.parents,
subject,
subject: subject(message),
message: messageWithLinks,
author: commit.authorName,
authorEmail: commit.authorEmail,

View File

@@ -295,6 +295,11 @@ export function truncate(value: string, maxLength = 20, ellipsis = true): string
return value.length <= maxLength ? value : `${value.substring(0, maxLength)}${ellipsis ? '\u2026' : ''}`;
}
export function subject(value: string): string {
const index = value.indexOf('\n');
return index === -1 ? value : truncate(value, index, false);
}
function normalizePath(path: string): string {
// Windows & Mac are currently being handled
// as case insensitive file systems in VS Code.

View File

@@ -1016,7 +1016,7 @@ class SCMHistoryTreeDragAndDrop implements ITreeDragAndDrop<TreeElement> {
private _getTreeElementLabel(element: TreeElement): string | undefined {
if (isSCMHistoryItemViewModelTreeElement(element)) {
const historyItem = element.historyItemViewModel.historyItem;
return getHistoryItemEditorTitle(historyItem);
return historyItem.displayId ?? historyItem.id;
}
return undefined;

View File

@@ -153,11 +153,8 @@ export function getRepositoryResourceCount(provider: ISCMProvider): number {
return provider.groups.reduce<number>((r, g) => r + g.resources.length, 0);
}
export function getHistoryItemEditorTitle(historyItem: ISCMHistoryItem, maxLength = 20): string {
const title = historyItem.subject.length <= maxLength ?
historyItem.subject : `${historyItem.subject.substring(0, maxLength)}\u2026`;
return `${historyItem.displayId ?? historyItem.id} - ${title}`;
export function getHistoryItemEditorTitle(historyItem: ISCMHistoryItem): string {
return `${historyItem.displayId ?? historyItem.id} - ${historyItem.subject}`;
}
export function getHistoryItemHoverContent(themeService: IThemeService, historyItem: ISCMHistoryItem): IManagedHoverTooltipMarkdownString {