mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Refresh master with initial release/0.24 snapshot (#332)
* Initial port of release/0.24 source code * Fix additional headers * Fix a typo in launch.json
This commit is contained in:
@@ -10,13 +10,10 @@ import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import types = require('vs/base/common/types');
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { ITree, IActionProvider } from 'vs/base/parts/tree/browser/tree';
|
||||
import filters = require('vs/base/common/filters');
|
||||
import strings = require('vs/base/common/strings');
|
||||
import paths = require('vs/base/common/paths');
|
||||
import { IconLabel, IIconLabelOptions } from 'vs/base/browser/ui/iconLabel/iconLabel';
|
||||
import { IQuickNavigateConfiguration, IModel, IDataSource, IFilter, IAccessiblityProvider, IRenderer, IRunner, Mode } from 'vs/base/parts/quickopen/common/quickOpen';
|
||||
import { Action, IAction, IActionRunner } from 'vs/base/common/actions';
|
||||
import { compareAnything, compareByScore as doCompareByScore } from 'vs/base/common/comparers';
|
||||
import { compareAnything } from 'vs/base/common/comparers';
|
||||
import { ActionBar, IActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { HighlightedLabel } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
|
||||
import DOM = require('vs/base/browser/dom');
|
||||
@@ -24,6 +21,7 @@ import { IQuickOpenStyles } from 'vs/base/parts/quickopen/browser/quickOpenWidge
|
||||
import { KeybindingLabel } from 'vs/base/browser/ui/keybindingLabel/keybindingLabel';
|
||||
import { OS } from 'vs/base/common/platform';
|
||||
import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { IItemAccessor } from 'vs/base/parts/quickopen/common/quickOpenScorer';
|
||||
|
||||
export interface IContext {
|
||||
event: any;
|
||||
@@ -37,18 +35,25 @@ export interface IHighlight {
|
||||
|
||||
let IDS = 0;
|
||||
|
||||
class EntryAccessor {
|
||||
export class QuickOpenItemAccessorClass implements IItemAccessor<QuickOpenEntry> {
|
||||
|
||||
public static getLabel(entry: QuickOpenEntry) {
|
||||
public getItemLabel(entry: QuickOpenEntry): string {
|
||||
return entry.getLabel();
|
||||
}
|
||||
|
||||
public static getResourcePath(entry: QuickOpenEntry) {
|
||||
public getItemDescription(entry: QuickOpenEntry): string {
|
||||
return entry.getDescription();
|
||||
}
|
||||
|
||||
public getItemPath(entry: QuickOpenEntry): string {
|
||||
const resource = entry.getResource();
|
||||
return resource && resource.fsPath;
|
||||
|
||||
return resource ? resource.fsPath : void 0;
|
||||
}
|
||||
}
|
||||
|
||||
export const QuickOpenItemAccessor = new QuickOpenItemAccessorClass();
|
||||
|
||||
export class QuickOpenEntry {
|
||||
private id: string;
|
||||
private labelHighlights: IHighlight[];
|
||||
@@ -166,116 +171,6 @@ export class QuickOpenEntry {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A good default sort implementation for quick open entries respecting highlight information
|
||||
* as well as associated resources.
|
||||
*/
|
||||
public static compare(elementA: QuickOpenEntry, elementB: QuickOpenEntry, lookFor: string): number {
|
||||
|
||||
// Give matches with label highlights higher priority over
|
||||
// those with only description highlights
|
||||
const labelHighlightsA = elementA.getHighlights()[0] || [];
|
||||
const labelHighlightsB = elementB.getHighlights()[0] || [];
|
||||
if (labelHighlightsA.length && !labelHighlightsB.length) {
|
||||
return -1;
|
||||
} else if (!labelHighlightsA.length && labelHighlightsB.length) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Fallback to the full path if labels are identical and we have associated resources
|
||||
let nameA = elementA.getLabel();
|
||||
let nameB = elementB.getLabel();
|
||||
if (nameA === nameB) {
|
||||
const resourceA = elementA.getResource();
|
||||
const resourceB = elementB.getResource();
|
||||
|
||||
if (resourceA && resourceB) {
|
||||
nameA = resourceA.fsPath;
|
||||
nameB = resourceB.fsPath;
|
||||
}
|
||||
}
|
||||
|
||||
return compareAnything(nameA, nameB, lookFor);
|
||||
}
|
||||
|
||||
public static compareByScore(elementA: QuickOpenEntry, elementB: QuickOpenEntry, lookFor: string, lookForNormalizedLower: string, scorerCache?: { [key: string]: number }): number {
|
||||
return doCompareByScore(elementA, elementB, EntryAccessor, lookFor, lookForNormalizedLower, scorerCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* A good default highlight implementation for an entry with label and description.
|
||||
*/
|
||||
public static highlight(entry: QuickOpenEntry, lookFor: string, fuzzyHighlight = false): { labelHighlights: IHighlight[], descriptionHighlights: IHighlight[] } {
|
||||
let labelHighlights: IHighlight[] = [];
|
||||
const descriptionHighlights: IHighlight[] = [];
|
||||
|
||||
const normalizedLookFor = strings.stripWildcards(lookFor);
|
||||
const label = entry.getLabel();
|
||||
const description = entry.getDescription();
|
||||
|
||||
// Highlight file aware
|
||||
if (entry.getResource()) {
|
||||
|
||||
// Highlight entire label and description if searching for full absolute path
|
||||
const fsPath = entry.getResource().fsPath;
|
||||
if (lookFor.length === fsPath.length && lookFor.toLowerCase() === fsPath.toLowerCase()) {
|
||||
labelHighlights.push({ start: 0, end: label.length });
|
||||
descriptionHighlights.push({ start: 0, end: description.length });
|
||||
}
|
||||
|
||||
// Fuzzy/Full-Path: Highlight is special
|
||||
else if (fuzzyHighlight || lookFor.indexOf(paths.nativeSep) >= 0) {
|
||||
const candidateLabelHighlights = filters.matchesFuzzy(lookFor, label, fuzzyHighlight);
|
||||
if (!candidateLabelHighlights) {
|
||||
const pathPrefix = description ? (description + paths.nativeSep) : '';
|
||||
const pathPrefixLength = pathPrefix.length;
|
||||
|
||||
// If there are no highlights in the label, build a path out of description and highlight and match on both,
|
||||
// then extract the individual label and description highlights back to the original positions
|
||||
let pathHighlights = filters.matchesFuzzy(lookFor, pathPrefix + label, fuzzyHighlight);
|
||||
if (!pathHighlights && lookFor !== normalizedLookFor) {
|
||||
pathHighlights = filters.matchesFuzzy(normalizedLookFor, pathPrefix + label, fuzzyHighlight);
|
||||
}
|
||||
|
||||
if (pathHighlights) {
|
||||
pathHighlights.forEach(h => {
|
||||
|
||||
// Match overlaps label and description part, we need to split it up
|
||||
if (h.start < pathPrefixLength && h.end > pathPrefixLength) {
|
||||
labelHighlights.push({ start: 0, end: h.end - pathPrefixLength });
|
||||
descriptionHighlights.push({ start: h.start, end: pathPrefixLength });
|
||||
}
|
||||
|
||||
// Match on label part
|
||||
else if (h.start >= pathPrefixLength) {
|
||||
labelHighlights.push({ start: h.start - pathPrefixLength, end: h.end - pathPrefixLength });
|
||||
}
|
||||
|
||||
// Match on description part
|
||||
else {
|
||||
descriptionHighlights.push(h);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
labelHighlights = candidateLabelHighlights;
|
||||
}
|
||||
}
|
||||
|
||||
// Highlight only inside label
|
||||
else {
|
||||
labelHighlights = filters.matchesFuzzy(lookFor, label);
|
||||
}
|
||||
}
|
||||
|
||||
// Highlight by label otherwise
|
||||
else {
|
||||
labelHighlights = filters.matchesFuzzy(lookFor, label);
|
||||
}
|
||||
|
||||
return { labelHighlights, descriptionHighlights };
|
||||
}
|
||||
|
||||
public isFile(): boolean {
|
||||
return false; // TODO@Ben debt with editor history merging
|
||||
}
|
||||
@@ -686,3 +581,37 @@ export class QuickOpenModel implements
|
||||
return entry.run(mode, context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A good default sort implementation for quick open entries respecting highlight information
|
||||
* as well as associated resources.
|
||||
*/
|
||||
export function compareEntries(elementA: QuickOpenEntry, elementB: QuickOpenEntry, lookFor: string): number {
|
||||
|
||||
// Give matches with label highlights higher priority over
|
||||
// those with only description highlights
|
||||
const labelHighlightsA = elementA.getHighlights()[0] || [];
|
||||
const labelHighlightsB = elementB.getHighlights()[0] || [];
|
||||
if (labelHighlightsA.length && !labelHighlightsB.length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!labelHighlightsA.length && labelHighlightsB.length) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Fallback to the full path if labels are identical and we have associated resources
|
||||
let nameA = elementA.getLabel();
|
||||
let nameB = elementB.getLabel();
|
||||
if (nameA === nameB) {
|
||||
const resourceA = elementA.getResource();
|
||||
const resourceB = elementB.getResource();
|
||||
|
||||
if (resourceA && resourceB) {
|
||||
nameA = resourceA.fsPath;
|
||||
nameB = resourceB.fsPath;
|
||||
}
|
||||
}
|
||||
|
||||
return compareAnything(nameA, nameB, lookFor);
|
||||
}
|
||||
Reference in New Issue
Block a user