mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
SCM - Add support for filtering history item changes (#209327)
This commit is contained in:
parent
b3d006c52c
commit
166a042fcc
|
@ -152,6 +152,56 @@ registerColor('scm.historyItemSelectedStatisticsBorder', {
|
||||||
hcLight: transparent(listActiveSelectionForeground, 0.2)
|
hcLight: transparent(listActiveSelectionForeground, 0.2)
|
||||||
}, localize('scm.historyItemSelectedStatisticsBorder', "History item selected statistics border color."));
|
}, 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 {
|
interface ISCMLayout {
|
||||||
height: number | undefined;
|
height: number | undefined;
|
||||||
width: number | undefined;
|
width: number | undefined;
|
||||||
|
@ -605,7 +655,7 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
|
||||||
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.resourceGroup.provider);
|
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.resourceGroup.provider);
|
||||||
this._renderActionBar(template, resourceOrFolder, menus.getResourceMenu(resourceOrFolder));
|
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);
|
template.element.classList.toggle('faded', resourceOrFolder.decorations.faded);
|
||||||
strikethrough = resourceOrFolder.decorations.strikeThrough;
|
strikethrough = resourceOrFolder.decorations.strikeThrough;
|
||||||
}
|
}
|
||||||
|
@ -672,56 +722,6 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
|
||||||
template.actionBar.context = resourceOrFolder;
|
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 {
|
private onDidColorThemeChange(): void {
|
||||||
for (const [template, data] of this.renderedResources) {
|
for (const [template, data] of this.renderedResources) {
|
||||||
this.renderIcon(template, data);
|
this.renderIcon(template, data);
|
||||||
|
@ -1017,7 +1017,7 @@ interface HistoryItemChangeTemplate {
|
||||||
readonly disposables: IDisposable;
|
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';
|
static readonly TEMPLATE_ID = 'historyItemChange';
|
||||||
get templateId(): string { return HistoryItemChangeRenderer.TEMPLATE_ID; }
|
get templateId(): string { return HistoryItemChangeRenderer.TEMPLATE_ID; }
|
||||||
|
@ -1036,24 +1036,37 @@ class HistoryItemChangeRenderer implements ICompressibleTreeRenderer<SCMHistoryI
|
||||||
return { element, name, fileLabel, decorationIcon, disposables: new DisposableStore() };
|
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 historyItemChangeOrFolder = node.element;
|
||||||
const uri = ResourceTree.isResourceNode(historyItemChangeOrFolder) ? historyItemChangeOrFolder.element?.uri ?? historyItemChangeOrFolder.uri : historyItemChangeOrFolder.uri;
|
const uri = ResourceTree.isResourceNode(historyItemChangeOrFolder) ? historyItemChangeOrFolder.element?.uri ?? historyItemChangeOrFolder.uri : historyItemChangeOrFolder.uri;
|
||||||
const fileKind = ResourceTree.isResourceNode(historyItemChangeOrFolder) ? FileKind.FOLDER : FileKind.FILE;
|
const fileKind = ResourceTree.isResourceNode(historyItemChangeOrFolder) ? FileKind.FOLDER : FileKind.FILE;
|
||||||
const hidePath = this.viewMode() === ViewMode.Tree;
|
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 compressed = node.element as ICompressedTreeNode<IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>>;
|
||||||
|
|
||||||
const folder = compressed.elements[compressed.elements.length - 1];
|
const folder = compressed.elements[compressed.elements.length - 1];
|
||||||
const label = compressed.elements.map(e => e.name);
|
const label = compressed.elements.map(e => e.name);
|
||||||
|
const matches = createMatches(node.filterData as FuzzyScore | undefined);
|
||||||
|
|
||||||
templateData.fileLabel.setResource({ resource: folder.uri, name: label }, {
|
templateData.fileLabel.setResource({ resource: folder.uri, name: label }, {
|
||||||
fileDecorations: { colors: false, badges: true },
|
fileDecorations: { colors: false, badges: true },
|
||||||
fileKind: FileKind.FOLDER,
|
fileKind: FileKind.FOLDER,
|
||||||
|
matches,
|
||||||
separator: this.labelService.getSeparator(folder.uri.scheme)
|
separator: this.labelService.getSeparator(folder.uri.scheme)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue