Skip to content

Commit

Permalink
SCM - Add support for filtering history item changes (#209327)
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru authored Apr 2, 2024
1 parent b3d006c commit 166a042
Showing 1 changed file with 68 additions and 55 deletions.
123 changes: 68 additions & 55 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,56 @@ registerColor('scm.historyItemSelectedStatisticsBorder', {
hcLight: transparent(listActiveSelectionForeground, 0.2)
}, localize('scm.historyItemSelectedStatisticsBorder', "History item selected statistics border color."));

function processResourceFilterData(uri: URI, filterData: FuzzyScore | LabelFuzzyScore | undefined): [IMatch[] | undefined, IMatch[] | undefined] {
if (!filterData) {
return [undefined, undefined];
}

if (!(filterData as LabelFuzzyScore).label) {
const matches = createMatches(filterData as FuzzyScore);
return [matches, undefined];
}

const fileName = basename(uri);
const label = (filterData as LabelFuzzyScore).label;
const pathLength = label.length - fileName.length;
const matches = createMatches((filterData as LabelFuzzyScore).score);

// FileName match
if (label === fileName) {
return [matches, undefined];
}

// FilePath match
const labelMatches: IMatch[] = [];
const descriptionMatches: IMatch[] = [];

for (const match of matches) {
if (match.start > pathLength) {
// Label match
labelMatches.push({
start: match.start - pathLength,
end: match.end - pathLength
});
} else if (match.end < pathLength) {
// Description match
descriptionMatches.push(match);
} else {
// Spanning match
labelMatches.push({
start: 0,
end: match.end - pathLength
});
descriptionMatches.push({
start: match.start,
end: pathLength
});
}
}

return [labelMatches, descriptionMatches];
}

interface ISCMLayout {
height: number | undefined;
width: number | undefined;
Expand Down Expand Up @@ -605,7 +655,7 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.resourceGroup.provider);
this._renderActionBar(template, resourceOrFolder, menus.getResourceMenu(resourceOrFolder));

[matches, descriptionMatches] = this._processFilterData(uri, node.filterData);
[matches, descriptionMatches] = processResourceFilterData(uri, node.filterData);
template.element.classList.toggle('faded', resourceOrFolder.decorations.faded);
strikethrough = resourceOrFolder.decorations.strikeThrough;
}
Expand Down Expand Up @@ -672,56 +722,6 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
template.actionBar.context = resourceOrFolder;
}

private _processFilterData(uri: URI, filterData: FuzzyScore | LabelFuzzyScore | undefined): [IMatch[] | undefined, IMatch[] | undefined] {
if (!filterData) {
return [undefined, undefined];
}

if (!(filterData as LabelFuzzyScore).label) {
const matches = createMatches(filterData as FuzzyScore);
return [matches, undefined];
}

const fileName = basename(uri);
const label = (filterData as LabelFuzzyScore).label;
const pathLength = label.length - fileName.length;
const matches = createMatches((filterData as LabelFuzzyScore).score);

// FileName match
if (label === fileName) {
return [matches, undefined];
}

// FilePath match
const labelMatches: IMatch[] = [];
const descriptionMatches: IMatch[] = [];

for (const match of matches) {
if (match.start > pathLength) {
// Label match
labelMatches.push({
start: match.start - pathLength,
end: match.end - pathLength
});
} else if (match.end < pathLength) {
// Description match
descriptionMatches.push(match);
} else {
// Spanning match
labelMatches.push({
start: 0,
end: match.end - pathLength
});
descriptionMatches.push({
start: match.start,
end: pathLength
});
}
}

return [labelMatches, descriptionMatches];
}

private onDidColorThemeChange(): void {
for (const [template, data] of this.renderedResources) {
this.renderIcon(template, data);
Expand Down Expand Up @@ -1017,7 +1017,7 @@ interface HistoryItemChangeTemplate {
readonly disposables: IDisposable;
}

class HistoryItemChangeRenderer implements ICompressibleTreeRenderer<SCMHistoryItemChangeTreeElement | IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>, void, HistoryItemChangeTemplate> {
class HistoryItemChangeRenderer implements ICompressibleTreeRenderer<SCMHistoryItemChangeTreeElement | IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>, FuzzyScore | LabelFuzzyScore, HistoryItemChangeTemplate> {

static readonly TEMPLATE_ID = 'historyItemChange';
get templateId(): string { return HistoryItemChangeRenderer.TEMPLATE_ID; }
Expand All @@ -1036,24 +1036,37 @@ class HistoryItemChangeRenderer implements ICompressibleTreeRenderer<SCMHistoryI
return { element, name, fileLabel, decorationIcon, disposables: new DisposableStore() };
}

renderElement(node: ITreeNode<SCMHistoryItemChangeTreeElement | IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>, void>, index: number, templateData: HistoryItemChangeTemplate, height: number | undefined): void {
renderElement(node: ITreeNode<SCMHistoryItemChangeTreeElement | IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>, FuzzyScore | LabelFuzzyScore>, index: number, templateData: HistoryItemChangeTemplate, height: number | undefined): void {
const historyItemChangeOrFolder = node.element;
const uri = ResourceTree.isResourceNode(historyItemChangeOrFolder) ? historyItemChangeOrFolder.element?.uri ?? historyItemChangeOrFolder.uri : historyItemChangeOrFolder.uri;
const fileKind = ResourceTree.isResourceNode(historyItemChangeOrFolder) ? FileKind.FOLDER : FileKind.FILE;
const hidePath = this.viewMode() === ViewMode.Tree;

templateData.fileLabel.setFile(uri, { fileDecorations: { colors: false, badges: true }, fileKind, hidePath, });
let matches: IMatch[] | undefined;
let descriptionMatches: IMatch[] | undefined;

if (ResourceTree.isResourceNode(historyItemChangeOrFolder)) {
if (!historyItemChangeOrFolder.element) {
matches = createMatches(node.filterData as FuzzyScore | undefined);
}
} else {
[matches, descriptionMatches] = processResourceFilterData(uri, node.filterData);
}

templateData.fileLabel.setFile(uri, { fileDecorations: { colors: false, badges: true }, fileKind, hidePath, matches, descriptionMatches });
}

renderCompressedElements(node: ITreeNode<ICompressedTreeNode<SCMHistoryItemChangeTreeElement | IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>>, void>, index: number, templateData: HistoryItemChangeTemplate, height: number | undefined): void {
renderCompressedElements(node: ITreeNode<ICompressedTreeNode<SCMHistoryItemChangeTreeElement | IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>>, FuzzyScore | LabelFuzzyScore>, index: number, templateData: HistoryItemChangeTemplate, height: number | undefined): void {
const compressed = node.element as ICompressedTreeNode<IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>>;

const folder = compressed.elements[compressed.elements.length - 1];
const label = compressed.elements.map(e => e.name);
const matches = createMatches(node.filterData as FuzzyScore | undefined);

templateData.fileLabel.setResource({ resource: folder.uri, name: label }, {
fileDecorations: { colors: false, badges: true },
fileKind: FileKind.FOLDER,
matches,
separator: this.labelService.getSeparator(folder.uri.scheme)
});
}
Expand Down

0 comments on commit 166a042

Please sign in to comment.