1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.findMatches = exports.filterItems = exports.QuickInputService = exports.quickInputServicePath = exports.QuickInputHideReason = exports.QuickInputButton = exports.QuickPickSeparator = exports.QuickPickItem = exports.QuickPickService = exports.quickPickServicePath = void 0;
|
19 | const uri_1 = require("./uri");
|
20 | const fuzzy = require("fuzzy");
|
21 | const vscode_uri_1 = require("vscode-uri");
|
22 | exports.quickPickServicePath = '/services/quickPick';
|
23 | exports.QuickPickService = Symbol('QuickPickService');
|
24 | var QuickPickItem;
|
25 | (function (QuickPickItem) {
|
26 | function is(item) {
|
27 |
|
28 | return item.type !== 'separator';
|
29 | }
|
30 | QuickPickItem.is = is;
|
31 | })(QuickPickItem = exports.QuickPickItem || (exports.QuickPickItem = {}));
|
32 | var QuickPickSeparator;
|
33 | (function (QuickPickSeparator) {
|
34 | function is(item) {
|
35 | return item.type === 'separator';
|
36 | }
|
37 | QuickPickSeparator.is = is;
|
38 | })(QuickPickSeparator = exports.QuickPickSeparator || (exports.QuickPickSeparator = {}));
|
39 | var QuickInputButton;
|
40 | (function (QuickInputButton) {
|
41 | function normalize(button) {
|
42 | var _a;
|
43 | if (!button) {
|
44 | return button;
|
45 | }
|
46 | let iconPath = undefined;
|
47 | if (button.iconPath instanceof uri_1.default) {
|
48 | iconPath = { dark: button.iconPath['codeUri'] };
|
49 | }
|
50 | else if (button.iconPath && 'dark' in button.iconPath) {
|
51 | const dark = vscode_uri_1.URI.isUri(button.iconPath.dark) ? button.iconPath.dark : button.iconPath.dark['codeUri'];
|
52 | const light = vscode_uri_1.URI.isUri(button.iconPath.light) ? button.iconPath.light : (_a = button.iconPath.light) === null || _a === void 0 ? void 0 : _a['codeUri'];
|
53 | iconPath = { dark, light };
|
54 | }
|
55 | return {
|
56 | ...button,
|
57 | iconPath,
|
58 | };
|
59 | }
|
60 | QuickInputButton.normalize = normalize;
|
61 | })(QuickInputButton = exports.QuickInputButton || (exports.QuickInputButton = {}));
|
62 | var QuickInputHideReason;
|
63 | (function (QuickInputHideReason) {
|
64 | |
65 |
|
66 |
|
67 | QuickInputHideReason[QuickInputHideReason["Blur"] = 1] = "Blur";
|
68 | |
69 |
|
70 |
|
71 | QuickInputHideReason[QuickInputHideReason["Gesture"] = 2] = "Gesture";
|
72 | |
73 |
|
74 |
|
75 | QuickInputHideReason[QuickInputHideReason["Other"] = 3] = "Other";
|
76 | })(QuickInputHideReason = exports.QuickInputHideReason || (exports.QuickInputHideReason = {}));
|
77 | exports.quickInputServicePath = '/services/quickInput';
|
78 | exports.QuickInputService = Symbol('QuickInputService');
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | function filterItems(items, filter) {
|
91 | filter = filter.trim().toLowerCase();
|
92 | if (filter.length === 0) {
|
93 | for (const item of items) {
|
94 | if (item.type !== 'separator') {
|
95 | item.highlights = undefined;
|
96 | }
|
97 | }
|
98 | return items;
|
99 | }
|
100 | const filteredItems = [];
|
101 | for (const item of items) {
|
102 | if (item.type === 'separator') {
|
103 | filteredItems.push(item);
|
104 | }
|
105 | else if (fuzzy.test(filter, item.label) ||
|
106 | (item.description && fuzzy.test(filter, item.description)) ||
|
107 | (item.detail && fuzzy.test(filter, item.detail))) {
|
108 | item.highlights = {
|
109 | label: findMatches(item.label, filter),
|
110 | description: item.description ? findMatches(item.description, filter) : undefined,
|
111 | detail: item.detail ? findMatches(item.detail, filter) : undefined
|
112 | };
|
113 | filteredItems.push(item);
|
114 | }
|
115 | }
|
116 | return filteredItems;
|
117 | }
|
118 | exports.filterItems = filterItems;
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | function findMatches(word, pattern) {
|
126 | word = word.toLocaleLowerCase();
|
127 | pattern = pattern.toLocaleLowerCase();
|
128 | if (pattern.trim().length === 0) {
|
129 | return undefined;
|
130 | }
|
131 | const delimiter = '\u0000';
|
132 | const matchResult = fuzzy.match(pattern.replace(/\u0000/gu, ''), word, { pre: delimiter, post: delimiter });
|
133 | if (!matchResult) {
|
134 | return undefined;
|
135 | }
|
136 | const match = matchResult.rendered;
|
137 | const highlights = [];
|
138 | let lastIndex = 0;
|
139 |
|
140 | let offset = 0;
|
141 | while (true) {
|
142 | const start = match.indexOf(delimiter, lastIndex);
|
143 | if (start === -1) {
|
144 | break;
|
145 | }
|
146 | const end = match.indexOf(delimiter, start + 1);
|
147 | if (end === -1) {
|
148 | break;
|
149 | }
|
150 | highlights.push({
|
151 | start: start - offset++,
|
152 | end: end - offset++
|
153 | });
|
154 | lastIndex = end + 1;
|
155 | }
|
156 | return highlights.length > 0 ? highlights : undefined;
|
157 | }
|
158 | exports.findMatches = findMatches;
|
159 |
|
\ | No newline at end of file |