custom-electron-titlebar 3.2.6 → 3.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/README.md +15 -24
  3. package/_config.yml +1 -0
  4. package/{lib → build}/browser/browser.d.ts +0 -0
  5. package/{lib → build}/browser/browser.js +0 -0
  6. package/{lib → build}/browser/browser.js.map +0 -0
  7. package/{lib → build}/browser/event.d.ts +0 -0
  8. package/{lib → build}/browser/event.js +2 -1
  9. package/{lib → build}/browser/event.js.map +1 -1
  10. package/{lib → build}/browser/iframe.d.ts +0 -0
  11. package/{lib → build}/browser/iframe.js +0 -0
  12. package/{lib → build}/browser/iframe.js.map +0 -0
  13. package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
  14. package/{lib → build}/browser/keyboardEvent.js +0 -0
  15. package/{lib → build}/browser/keyboardEvent.js.map +0 -0
  16. package/{lib → build}/browser/mouseEvent.d.ts +0 -0
  17. package/{lib → build}/browser/mouseEvent.js +0 -0
  18. package/{lib → build}/browser/mouseEvent.js.map +0 -0
  19. package/{lib → build}/common/arrays.d.ts +0 -0
  20. package/{lib → build}/common/arrays.js +0 -0
  21. package/{lib → build}/common/arrays.js.map +0 -0
  22. package/{lib → build}/common/async.d.ts +0 -0
  23. package/{lib → build}/common/async.js +0 -0
  24. package/{lib → build}/common/async.js.map +0 -0
  25. package/{lib → build}/common/charCode.d.ts +0 -0
  26. package/{lib → build}/common/charCode.js +0 -0
  27. package/{lib → build}/common/charCode.js.map +0 -0
  28. package/{lib → build}/common/color.d.ts +0 -0
  29. package/{lib → build}/common/color.js +0 -0
  30. package/{lib → build}/common/color.js.map +0 -0
  31. package/{lib → build}/common/dom.d.ts +0 -0
  32. package/{lib → build}/common/dom.js +16 -14
  33. package/build/common/dom.js.map +1 -0
  34. package/{lib → build}/common/event.d.ts +0 -0
  35. package/{lib → build}/common/event.js +1 -1
  36. package/build/common/event.js.map +1 -0
  37. package/{lib → build}/common/iterator.d.ts +0 -0
  38. package/{lib → build}/common/iterator.js +0 -0
  39. package/{lib → build}/common/iterator.js.map +0 -0
  40. package/{lib → build}/common/keyCodes.d.ts +0 -0
  41. package/{lib → build}/common/keyCodes.js +0 -0
  42. package/{lib → build}/common/keyCodes.js.map +0 -0
  43. package/{lib → build}/common/lifecycle.d.ts +0 -0
  44. package/{lib → build}/common/lifecycle.js +0 -0
  45. package/{lib → build}/common/lifecycle.js.map +0 -0
  46. package/{lib → build}/common/linkedList.d.ts +0 -0
  47. package/{lib → build}/common/linkedList.js +0 -0
  48. package/{lib → build}/common/linkedList.js.map +0 -0
  49. package/{lib → build}/common/platform.d.ts +0 -0
  50. package/{lib → build}/common/platform.js +0 -0
  51. package/{lib → build}/common/platform.js.map +0 -0
  52. package/{lib → build}/index.d.ts +0 -0
  53. package/{lib → build}/index.js +0 -0
  54. package/{lib → build}/index.js.map +0 -0
  55. package/{lib → build}/menu/menu.d.ts +0 -0
  56. package/{lib → build}/menu/menu.js +38 -38
  57. package/build/menu/menu.js.map +1 -0
  58. package/{lib → build}/menu/menuitem.d.ts +10 -2
  59. package/{lib → build}/menu/menuitem.js +70 -34
  60. package/build/menu/menuitem.js.map +1 -0
  61. package/{lib → build}/menubar.d.ts +0 -0
  62. package/{lib → build}/menubar.js +29 -30
  63. package/build/menubar.js.map +1 -0
  64. package/{lib → build}/themebar.d.ts +0 -0
  65. package/{lib → build}/themebar.js +2 -2
  66. package/build/themebar.js.map +1 -0
  67. package/{lib → build}/titlebar.d.ts +0 -0
  68. package/{lib → build}/titlebar.js +61 -58
  69. package/build/titlebar.js.map +1 -0
  70. package/package.json +13 -7
  71. package/lib/common/dom.js.map +0 -1
  72. package/lib/common/enableNativeMenuCommands.d.ts +0 -1
  73. package/lib/common/enableNativeMenuCommands.js +0 -32
  74. package/lib/common/enableNativeMenuCommands.js.map +0 -1
  75. package/lib/common/event.js.map +0 -1
  76. package/lib/main.d.ts +0 -1
  77. package/lib/main.js +0 -14
  78. package/lib/main.js.map +0 -1
  79. package/lib/menu/menu.js.map +0 -1
  80. package/lib/menu/menuitem.js.map +0 -1
  81. package/lib/menubar.js.map +0 -1
  82. package/lib/themebar.js.map +0 -1
  83. package/lib/titlebar.js.map +0 -1
  84. package/lib/vs/base/browser/browser.js +0 -150
  85. package/lib/vs/base/browser/canIUse.js +0 -58
  86. package/lib/vs/base/browser/codicons.js +0 -37
  87. package/lib/vs/base/browser/contextmenu.js +0 -9
  88. package/lib/vs/base/browser/dnd.js +0 -113
  89. package/lib/vs/base/browser/dom.js +0 -1417
  90. package/lib/vs/base/browser/event.js +0 -36
  91. package/lib/vs/base/browser/fastDomNode.js +0 -265
  92. package/lib/vs/base/browser/formattedTextRenderer.js +0 -248
  93. package/lib/vs/base/browser/globalMouseMoveMonitor.js +0 -137
  94. package/lib/vs/base/browser/history.js +0 -9
  95. package/lib/vs/base/browser/iframe.js +0 -126
  96. package/lib/vs/base/browser/keyboardEvent.js +0 -599
  97. package/lib/vs/base/browser/mouseEvent.js +0 -155
  98. package/lib/vs/base/browser/touch.js +0 -315
  99. package/lib/vs/base/browser/ui/actionbar/actionViewItems.js +0 -397
  100. package/lib/vs/base/browser/ui/actionbar/actionbar.js +0 -583
  101. package/lib/vs/base/browser/ui/checkbox/checkbox.js +0 -251
  102. package/lib/vs/base/browser/ui/codicons/codiconLabel.js +0 -31
  103. package/lib/vs/base/browser/ui/codicons/codiconStyles.js +0 -47
  104. package/lib/vs/base/browser/ui/contextview/contextview.js +0 -367
  105. package/lib/vs/base/browser/ui/dropdown/dropdown.js +0 -256
  106. package/lib/vs/base/browser/ui/dropdown/dropdownActionViewItem.js +0 -120
  107. package/lib/vs/base/browser/ui/keybindingLabel/keybindingLabel.js +0 -118
  108. package/lib/vs/base/browser/ui/list/list.js +0 -54
  109. package/lib/vs/base/browser/ui/list/listPaging.js +0 -322
  110. package/lib/vs/base/browser/ui/list/listView.js +0 -1388
  111. package/lib/vs/base/browser/ui/list/listWidget.js +0 -1709
  112. package/lib/vs/base/browser/ui/list/rangeMap.js +0 -223
  113. package/lib/vs/base/browser/ui/list/rowCache.js +0 -113
  114. package/lib/vs/base/browser/ui/list/splice.js +0 -23
  115. package/lib/vs/base/browser/ui/menu/menu.js +0 -1371
  116. package/lib/vs/base/browser/ui/menu/menubar.js +0 -1139
  117. package/lib/vs/base/browser/ui/scrollbar/abstractScrollbar.js +0 -278
  118. package/lib/vs/base/browser/ui/scrollbar/horizontalScrollbar.js +0 -115
  119. package/lib/vs/base/browser/ui/scrollbar/scrollableElement.js +0 -646
  120. package/lib/vs/base/browser/ui/scrollbar/scrollableElementOptions.js +0 -9
  121. package/lib/vs/base/browser/ui/scrollbar/scrollbarArrow.js +0 -106
  122. package/lib/vs/base/browser/ui/scrollbar/scrollbarState.js +0 -184
  123. package/lib/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.js +0 -116
  124. package/lib/vs/base/browser/ui/scrollbar/verticalScrollbar.js +0 -114
  125. package/lib/vs/base/browser/ui/selectBox/selectBox.js +0 -85
  126. package/lib/vs/base/browser/ui/selectBox/selectBoxCustom.js +0 -985
  127. package/lib/vs/base/browser/ui/selectBox/selectBoxNative.js +0 -188
  128. package/lib/vs/base/browser/ui/toolbar/toolbar.js +0 -206
  129. package/lib/vs/base/browser/ui/widget.js +0 -69
  130. package/lib/vs/base/common/actions.js +0 -224
  131. package/lib/vs/base/common/amd.js +0 -31
  132. package/lib/vs/base/common/arrays.js +0 -641
  133. package/lib/vs/base/common/assert.js +0 -21
  134. package/lib/vs/base/common/async.js +0 -966
  135. package/lib/vs/base/common/buffer.js +0 -250
  136. package/lib/vs/base/common/cache.js +0 -40
  137. package/lib/vs/base/common/cancellation.js +0 -146
  138. package/lib/vs/base/common/charCode.js +0 -9
  139. package/lib/vs/base/common/codicon.js +0 -136
  140. package/lib/vs/base/common/codicons.js +0 -1378
  141. package/lib/vs/base/common/collections.js +0 -133
  142. package/lib/vs/base/common/color.js +0 -716
  143. package/lib/vs/base/common/comparers.js +0 -280
  144. package/lib/vs/base/common/console.js +0 -142
  145. package/lib/vs/base/common/date.js +0 -113
  146. package/lib/vs/base/common/decorators.js +0 -169
  147. package/lib/vs/base/common/errorMessage.js +0 -93
  148. package/lib/vs/base/common/errors.js +0 -213
  149. package/lib/vs/base/common/errorsWithActions.js +0 -28
  150. package/lib/vs/base/common/event.js +0 -873
  151. package/lib/vs/base/common/extpath.js +0 -401
  152. package/lib/vs/base/common/filters.js +0 -948
  153. package/lib/vs/base/common/functional.js +0 -28
  154. package/lib/vs/base/common/fuzzyScorer.js +0 -811
  155. package/lib/vs/base/common/glob.js +0 -696
  156. package/lib/vs/base/common/hash.js +0 -359
  157. package/lib/vs/base/common/history.js +0 -116
  158. package/lib/vs/base/common/htmlContent.js +0 -162
  159. package/lib/vs/base/common/idGenerator.js +0 -25
  160. package/lib/vs/base/common/iterator.js +0 -118
  161. package/lib/vs/base/common/json.js +0 -1624
  162. package/lib/vs/base/common/jsonEdit.js +0 -272
  163. package/lib/vs/base/common/jsonErrorMessages.js +0 -69
  164. package/lib/vs/base/common/jsonFormatter.js +0 -316
  165. package/lib/vs/base/common/jsonSchema.js +0 -9
  166. package/lib/vs/base/common/keyCodes.js +0 -591
  167. package/lib/vs/base/common/keybindingLabels.js +0 -231
  168. package/lib/vs/base/common/keybindingParser.js +0 -142
  169. package/lib/vs/base/common/labels.js +0 -430
  170. package/lib/vs/base/common/lazy.js +0 -71
  171. package/lib/vs/base/common/lifecycle.js +0 -308
  172. package/lib/vs/base/common/linkedList.js +0 -152
  173. package/lib/vs/base/common/linkedText.js +0 -73
  174. package/lib/vs/base/common/map.js +0 -1108
  175. package/lib/vs/base/common/marshalling.js +0 -80
  176. package/lib/vs/base/common/mime.js +0 -321
  177. package/lib/vs/base/common/navigator.js +0 -50
  178. package/lib/vs/base/common/network.js +0 -160
  179. package/lib/vs/base/common/normalization.js +0 -78
  180. package/lib/vs/base/common/numbers.js +0 -55
  181. package/lib/vs/base/common/objects.js +0 -268
  182. package/lib/vs/base/common/paging.js +0 -190
  183. package/lib/vs/base/common/parsers.js +0 -78
  184. package/lib/vs/base/common/path.js +0 -1550
  185. package/lib/vs/base/common/platform.js +0 -245
  186. package/lib/vs/base/common/process.js +0 -52
  187. package/lib/vs/base/common/processes.js +0 -32
  188. package/lib/vs/base/common/range.js +0 -79
  189. package/lib/vs/base/common/resourceTree.js +0 -185
  190. package/lib/vs/base/common/resources.js +0 -421
  191. package/lib/vs/base/common/scanCode.js +0 -1472
  192. package/lib/vs/base/common/scrollable.js +0 -397
  193. package/lib/vs/base/common/search.js +0 -55
  194. package/lib/vs/base/common/sequence.js +0 -64
  195. package/lib/vs/base/common/severity.js +0 -55
  196. package/lib/vs/base/common/skipList.js +0 -234
  197. package/lib/vs/base/common/stopwatch.js +0 -45
  198. package/lib/vs/base/common/stream.js +0 -418
  199. package/lib/vs/base/common/strings.js +0 -1283
  200. package/lib/vs/base/common/styler.js +0 -9
  201. package/lib/vs/base/common/types.js +0 -296
  202. package/lib/vs/base/common/uint.js +0 -46
  203. package/lib/vs/base/common/uri.js +0 -756
  204. package/lib/vs/base/common/uriIpc.js +0 -154
  205. package/lib/vs/base/common/uuid.js +0 -70
  206. package/lib/vs/nls.mock.js +0 -31
  207. package/lib/vs/platform/actions/browser/menuEntryActionViewItem.js +0 -342
  208. package/lib/vs/platform/actions/common/actions.js +0 -456
  209. package/lib/vs/platform/actions/common/menuService.js +0 -194
  210. package/lib/vs/platform/clipboard/browser/clipboardService.js +0 -99
  211. package/lib/vs/platform/clipboard/common/clipboardService.js +0 -14
  212. package/lib/vs/platform/contextkey/common/contextkey.js +0 -1210
  213. package/lib/vs/platform/contextkey/common/contextkeys.js +0 -23
  214. package/lib/vs/platform/contextview/browser/contextView.js +0 -15
  215. package/lib/vs/platform/contextview/browser/contextViewService.js +0 -96
  216. package/lib/vs/platform/environment/common/argv.js +0 -9
  217. package/lib/vs/platform/environment/common/environment.js +0 -15
  218. package/lib/vs/platform/instantiation/common/descriptors.js +0 -25
  219. package/lib/vs/platform/instantiation/common/extensions.js +0 -26
  220. package/lib/vs/platform/instantiation/common/graph.js +0 -93
  221. package/lib/vs/platform/instantiation/common/instantiation.js +0 -84
  222. package/lib/vs/platform/instantiation/common/instantiationService.js +0 -361
  223. package/lib/vs/platform/instantiation/common/serviceCollection.js +0 -39
  224. package/lib/vs/platform/keybinding/common/baseResolvedKeybinding.js +0 -73
  225. package/lib/vs/platform/keybinding/common/keybinding.js +0 -14
  226. package/lib/vs/platform/keybinding/common/keybindingResolver.js +0 -391
  227. package/lib/vs/platform/keybinding/common/keybindingsRegistry.js +0 -229
  228. package/lib/vs/platform/keybinding/common/resolvedKeybindingItem.js +0 -47
  229. package/lib/vs/platform/keybinding/common/usLayoutResolvedKeybinding.js +0 -160
  230. package/lib/vs/platform/layout/browser/layoutService.js +0 -14
  231. package/lib/vs/platform/menubar/common/menubar.js +0 -34
  232. package/lib/vs/platform/registry/common/platform.js +0 -38
  233. package/lib/vs/platform/theme/browser/checkbox.js +0 -32
  234. package/lib/vs/platform/theme/common/colorRegistry.js +0 -1154
  235. package/lib/vs/platform/theme/common/styler.js +0 -290
  236. package/lib/vs/platform/theme/common/theme.js +0 -21
  237. package/lib/vs/platform/theme/common/themeService.js +0 -176
  238. package/lib/vs/platform/theme/common/tokenClassificationRegistry.js +0 -540
  239. package/lib/vs/platform/theme/test/common/testThemeService.js +0 -98
@@ -1,811 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.pieceToQuery = exports.prepareQuery = exports.compareItemsByFuzzyScore = exports.scoreItemFuzzy = exports.scoreFuzzy2 = exports.scoreFuzzy = void 0;
11
-
12
- const comparers_1 = require("./comparers");
13
-
14
- const filters_1 = require("./filters");
15
-
16
- const path_1 = require("./path");
17
-
18
- const platform_1 = require("./platform");
19
-
20
- const strings_1 = require("./strings");
21
-
22
- const NO_MATCH = 0;
23
- const NO_SCORE = [NO_MATCH, []]; // const DEBUG = false;
24
- // const DEBUG_MATRIX = false;
25
-
26
- function scoreFuzzy(target, query, queryLower, fuzzy) {
27
- if (!target || !query) {
28
- return NO_SCORE; // return early if target or query are undefined
29
- }
30
-
31
- const targetLength = target.length;
32
- const queryLength = query.length;
33
-
34
- if (targetLength < queryLength) {
35
- return NO_SCORE; // impossible for query to be contained in target
36
- } // if (DEBUG) {
37
- // console.group(`Target: ${target}, Query: ${query}`);
38
- // }
39
-
40
-
41
- const targetLower = target.toLowerCase(); // When not searching fuzzy, we require the query to be contained fully
42
- // in the target string contiguously.
43
-
44
- if (!fuzzy) {
45
- if (!targetLower.includes(queryLower)) {
46
- // if (DEBUG) {
47
- // console.log(`Characters not matching consecutively ${queryLower} within ${targetLower}`);
48
- // }
49
- return NO_SCORE;
50
- }
51
- }
52
-
53
- const res = doScoreFuzzy(query, queryLower, queryLength, target, targetLower, targetLength); // if (DEBUG) {
54
- // console.log(`%cFinal Score: ${res[0]}`, 'font-weight: bold');
55
- // console.groupEnd();
56
- // }
57
-
58
- return res;
59
- }
60
-
61
- exports.scoreFuzzy = scoreFuzzy;
62
-
63
- function doScoreFuzzy(query, queryLower, queryLength, target, targetLower, targetLength) {
64
- const scores = [];
65
- const matches = []; //
66
- // Build Scorer Matrix:
67
- //
68
- // The matrix is composed of query q and target t. For each index we score
69
- // q[i] with t[i] and compare that with the previous score. If the score is
70
- // equal or larger, we keep the match. In addition to the score, we also keep
71
- // the length of the consecutive matches to use as boost for the score.
72
- //
73
- // t a r g e t
74
- // q
75
- // u
76
- // e
77
- // r
78
- // y
79
- //
80
-
81
- for (let queryIndex = 0; queryIndex < queryLength; queryIndex++) {
82
- const queryIndexOffset = queryIndex * targetLength;
83
- const queryIndexPreviousOffset = queryIndexOffset - targetLength;
84
- const queryIndexGtNull = queryIndex > 0;
85
- const queryCharAtIndex = query[queryIndex];
86
- const queryLowerCharAtIndex = queryLower[queryIndex];
87
-
88
- for (let targetIndex = 0; targetIndex < targetLength; targetIndex++) {
89
- const targetIndexGtNull = targetIndex > 0;
90
- const currentIndex = queryIndexOffset + targetIndex;
91
- const leftIndex = currentIndex - 1;
92
- const diagIndex = queryIndexPreviousOffset + targetIndex - 1;
93
- const leftScore = targetIndexGtNull ? scores[leftIndex] : 0;
94
- const diagScore = queryIndexGtNull && targetIndexGtNull ? scores[diagIndex] : 0;
95
- const matchesSequenceLength = queryIndexGtNull && targetIndexGtNull ? matches[diagIndex] : 0; // If we are not matching on the first query character any more, we only produce a
96
- // score if we had a score previously for the last query index (by looking at the diagScore).
97
- // This makes sure that the query always matches in sequence on the target. For example
98
- // given a target of "ede" and a query of "de", we would otherwise produce a wrong high score
99
- // for query[1] ("e") matching on target[0] ("e") because of the "beginning of word" boost.
100
-
101
- let score;
102
-
103
- if (!diagScore && queryIndexGtNull) {
104
- score = 0;
105
- } else {
106
- score = computeCharScore(queryCharAtIndex, queryLowerCharAtIndex, target, targetLower, targetIndex, matchesSequenceLength);
107
- } // We have a score and its equal or larger than the left score
108
- // Match: sequence continues growing from previous diag value
109
- // Score: increases by diag score value
110
-
111
-
112
- if (score && diagScore + score >= leftScore) {
113
- matches[currentIndex] = matchesSequenceLength + 1;
114
- scores[currentIndex] = diagScore + score;
115
- } // We either have no score or the score is lower than the left score
116
- // Match: reset to 0
117
- // Score: pick up from left hand side
118
- else {
119
- matches[currentIndex] = NO_MATCH;
120
- scores[currentIndex] = leftScore;
121
- }
122
- }
123
- } // Restore Positions (starting from bottom right of matrix)
124
-
125
-
126
- const positions = [];
127
- let queryIndex = queryLength - 1;
128
- let targetIndex = targetLength - 1;
129
-
130
- while (queryIndex >= 0 && targetIndex >= 0) {
131
- const currentIndex = queryIndex * targetLength + targetIndex;
132
- const match = matches[currentIndex];
133
-
134
- if (match === NO_MATCH) {
135
- targetIndex--; // go left
136
- } else {
137
- positions.push(targetIndex); // go up and left
138
-
139
- queryIndex--;
140
- targetIndex--;
141
- }
142
- } // Print matrix
143
- // if (DEBUG_MATRIX) {
144
- // printMatrix(query, target, matches, scores);
145
- // }
146
-
147
-
148
- return [scores[queryLength * targetLength - 1], positions.reverse()];
149
- }
150
-
151
- function computeCharScore(queryCharAtIndex, queryLowerCharAtIndex, target, targetLower, targetIndex, matchesSequenceLength) {
152
- let score = 0;
153
-
154
- if (!considerAsEqual(queryLowerCharAtIndex, targetLower[targetIndex])) {
155
- return score; // no match of characters
156
- } // Character match bonus
157
-
158
-
159
- score += 1; // if (DEBUG) {
160
- // console.groupCollapsed(`%cCharacter match bonus: +1 (char: ${queryLowerCharAtIndex} at index ${targetIndex}, total score: ${score})`, 'font-weight: normal');
161
- // }
162
- // Consecutive match bonus
163
-
164
- if (matchesSequenceLength > 0) {
165
- score += matchesSequenceLength * 5; // if (DEBUG) {
166
- // console.log(`Consecutive match bonus: +${matchesSequenceLength * 5}`);
167
- // }
168
- } // Same case bonus
169
-
170
-
171
- if (queryCharAtIndex === target[targetIndex]) {
172
- score += 1; // if (DEBUG) {
173
- // console.log('Same case bonus: +1');
174
- // }
175
- } // Start of word bonus
176
-
177
-
178
- if (targetIndex === 0) {
179
- score += 8; // if (DEBUG) {
180
- // console.log('Start of word bonus: +8');
181
- // }
182
- } else {
183
- // After separator bonus
184
- const separatorBonus = scoreSeparatorAtPos(target.charCodeAt(targetIndex - 1));
185
-
186
- if (separatorBonus) {
187
- score += separatorBonus; // if (DEBUG) {
188
- // console.log(`After separtor bonus: +${separatorBonus}`);
189
- // }
190
- } // Inside word upper case bonus (camel case)
191
- else if (filters_1.isUpper(target.charCodeAt(targetIndex))) {
192
- score += 2; // if (DEBUG) {
193
- // console.log('Inside word upper case bonus: +2');
194
- // }
195
- }
196
- } // if (DEBUG) {
197
- // console.groupEnd();
198
- // }
199
-
200
-
201
- return score;
202
- }
203
-
204
- function considerAsEqual(a, b) {
205
- if (a === b) {
206
- return true;
207
- } // Special case path spearators: ignore platform differences
208
-
209
-
210
- if (a === '/' || a === '\\') {
211
- return b === '/' || b === '\\';
212
- }
213
-
214
- return false;
215
- }
216
-
217
- function scoreSeparatorAtPos(charCode) {
218
- switch (charCode) {
219
- case 47
220
- /* Slash */
221
- :
222
- case 92
223
- /* Backslash */
224
- :
225
- return 5;
226
- // prefer path separators...
227
-
228
- case 95
229
- /* Underline */
230
- :
231
- case 45
232
- /* Dash */
233
- :
234
- case 46
235
- /* Period */
236
- :
237
- case 32
238
- /* Space */
239
- :
240
- case 39
241
- /* SingleQuote */
242
- :
243
- case 34
244
- /* DoubleQuote */
245
- :
246
- case 58
247
- /* Colon */
248
- :
249
- return 4;
250
- // ...over other separators
251
-
252
- default:
253
- return 0;
254
- }
255
- }
256
-
257
- const NO_SCORE2 = [undefined, []];
258
-
259
- function scoreFuzzy2(target, query, patternStart = 0, wordStart = 0) {
260
- // Score: multiple inputs
261
- const preparedQuery = query;
262
-
263
- if (preparedQuery.values && preparedQuery.values.length > 1) {
264
- return doScoreFuzzy2Multiple(target, preparedQuery.values, patternStart, wordStart);
265
- } // Score: single input
266
-
267
-
268
- return doScoreFuzzy2Single(target, query, patternStart, wordStart);
269
- }
270
-
271
- exports.scoreFuzzy2 = scoreFuzzy2;
272
-
273
- function doScoreFuzzy2Multiple(target, query, patternStart, wordStart) {
274
- let totalScore = 0;
275
- const totalMatches = [];
276
-
277
- for (const queryPiece of query) {
278
- const [score, matches] = doScoreFuzzy2Single(target, queryPiece, patternStart, wordStart);
279
-
280
- if (typeof score !== 'number') {
281
- // if a single query value does not match, return with
282
- // no score entirely, we require all queries to match
283
- return NO_SCORE2;
284
- }
285
-
286
- totalScore += score;
287
- totalMatches.push(...matches);
288
- } // if we have a score, ensure that the positions are
289
- // sorted in ascending order and distinct
290
-
291
-
292
- return [totalScore, normalizeMatches(totalMatches)];
293
- }
294
-
295
- function doScoreFuzzy2Single(target, query, patternStart, wordStart) {
296
- const score = filters_1.fuzzyScore(query.original, query.originalLowercase, patternStart, target, target.toLowerCase(), wordStart, true);
297
-
298
- if (!score) {
299
- return NO_SCORE2;
300
- }
301
-
302
- return [score[0], filters_1.createMatches(score)];
303
- }
304
-
305
- const NO_ITEM_SCORE = Object.freeze({
306
- score: 0
307
- });
308
- const PATH_IDENTITY_SCORE = 1 << 18;
309
- const LABEL_PREFIX_SCORE_THRESHOLD = 1 << 17;
310
- const LABEL_SCORE_THRESHOLD = 1 << 16;
311
-
312
- function scoreItemFuzzy(item, query, fuzzy, accessor, cache) {
313
- if (!item || !query.normalized) {
314
- return NO_ITEM_SCORE; // we need an item and query to score on at least
315
- }
316
-
317
- const label = accessor.getItemLabel(item);
318
-
319
- if (!label) {
320
- return NO_ITEM_SCORE; // we need a label at least
321
- }
322
-
323
- const description = accessor.getItemDescription(item); // in order to speed up scoring, we cache the score with a unique hash based on:
324
- // - label
325
- // - description (if provided)
326
- // - query (normalized)
327
- // - number of query pieces (i.e. 'hello world' and 'helloworld' are different)
328
- // - wether fuzzy matching is enabled or not
329
-
330
- let cacheHash;
331
-
332
- if (description) {
333
- cacheHash = `${label}${description}${query.normalized}${Array.isArray(query.values) ? query.values.length : ''}${fuzzy}`;
334
- } else {
335
- cacheHash = `${label}${query.normalized}${Array.isArray(query.values) ? query.values.length : ''}${fuzzy}`;
336
- }
337
-
338
- const cached = cache[cacheHash];
339
-
340
- if (cached) {
341
- return cached;
342
- }
343
-
344
- const itemScore = doScoreItemFuzzy(label, description, accessor.getItemPath(item), query, fuzzy);
345
- cache[cacheHash] = itemScore;
346
- return itemScore;
347
- }
348
-
349
- exports.scoreItemFuzzy = scoreItemFuzzy;
350
-
351
- function doScoreItemFuzzy(label, description, path, query, fuzzy) {
352
- const preferLabelMatches = !path || !query.containsPathSeparator; // Treat identity matches on full path highest
353
-
354
- if (path && (platform_1.isLinux ? query.pathNormalized === path : strings_1.equalsIgnoreCase(query.pathNormalized, path))) {
355
- return {
356
- score: PATH_IDENTITY_SCORE,
357
- labelMatch: [{
358
- start: 0,
359
- end: label.length
360
- }],
361
- descriptionMatch: description ? [{
362
- start: 0,
363
- end: description.length
364
- }] : undefined
365
- };
366
- } // Score: multiple inputs
367
-
368
-
369
- if (query.values && query.values.length > 1) {
370
- return doScoreItemFuzzyMultiple(label, description, path, query.values, preferLabelMatches, fuzzy);
371
- } // Score: single input
372
-
373
-
374
- return doScoreItemFuzzySingle(label, description, path, query, preferLabelMatches, fuzzy);
375
- }
376
-
377
- function doScoreItemFuzzyMultiple(label, description, path, query, preferLabelMatches, fuzzy) {
378
- let totalScore = 0;
379
- const totalLabelMatches = [];
380
- const totalDescriptionMatches = [];
381
-
382
- for (const queryPiece of query) {
383
- const {
384
- score,
385
- labelMatch,
386
- descriptionMatch
387
- } = doScoreItemFuzzySingle(label, description, path, queryPiece, preferLabelMatches, fuzzy);
388
-
389
- if (score === NO_MATCH) {
390
- // if a single query value does not match, return with
391
- // no score entirely, we require all queries to match
392
- return NO_ITEM_SCORE;
393
- }
394
-
395
- totalScore += score;
396
-
397
- if (labelMatch) {
398
- totalLabelMatches.push(...labelMatch);
399
- }
400
-
401
- if (descriptionMatch) {
402
- totalDescriptionMatches.push(...descriptionMatch);
403
- }
404
- } // if we have a score, ensure that the positions are
405
- // sorted in ascending order and distinct
406
-
407
-
408
- return {
409
- score: totalScore,
410
- labelMatch: normalizeMatches(totalLabelMatches),
411
- descriptionMatch: normalizeMatches(totalDescriptionMatches)
412
- };
413
- }
414
-
415
- function doScoreItemFuzzySingle(label, description, path, query, preferLabelMatches, fuzzy) {
416
- // Prefer label matches if told so or we have no description
417
- if (preferLabelMatches || !description) {
418
- const [labelScore, labelPositions] = scoreFuzzy(label, query.normalized, query.normalizedLowercase, fuzzy);
419
-
420
- if (labelScore) {
421
- // If we have a prefix match on the label, we give a much
422
- // higher baseScore to elevate these matches over others
423
- // This ensures that typing a file name wins over results
424
- // that are present somewhere in the label, but not the
425
- // beginning.
426
- const labelPrefixMatch = filters_1.matchesPrefix(query.normalized, label);
427
- let baseScore;
428
-
429
- if (labelPrefixMatch) {
430
- baseScore = LABEL_PREFIX_SCORE_THRESHOLD; // We give another boost to labels that are short, e.g. given
431
- // files "window.ts" and "windowActions.ts" and a query of
432
- // "window", we want "window.ts" to receive a higher score.
433
- // As such we compute the percentage the query has within the
434
- // label and add that to the baseScore.
435
-
436
- const prefixLengthBoost = Math.round(query.normalized.length / label.length * 100);
437
- baseScore += prefixLengthBoost;
438
- } else {
439
- baseScore = LABEL_SCORE_THRESHOLD;
440
- }
441
-
442
- return {
443
- score: baseScore + labelScore,
444
- labelMatch: labelPrefixMatch || createMatches(labelPositions)
445
- };
446
- }
447
- } // Finally compute description + label scores if we have a description
448
-
449
-
450
- if (description) {
451
- let descriptionPrefix = description;
452
-
453
- if (!!path) {
454
- descriptionPrefix = `${description}${path_1.sep}`; // assume this is a file path
455
- }
456
-
457
- const descriptionPrefixLength = descriptionPrefix.length;
458
- const descriptionAndLabel = `${descriptionPrefix}${label}`;
459
- const [labelDescriptionScore, labelDescriptionPositions] = scoreFuzzy(descriptionAndLabel, query.normalized, query.normalizedLowercase, fuzzy);
460
-
461
- if (labelDescriptionScore) {
462
- const labelDescriptionMatches = createMatches(labelDescriptionPositions);
463
- const labelMatch = [];
464
- const descriptionMatch = []; // We have to split the matches back onto the label and description portions
465
-
466
- labelDescriptionMatches.forEach(h => {
467
- // Match overlaps label and description part, we need to split it up
468
- if (h.start < descriptionPrefixLength && h.end > descriptionPrefixLength) {
469
- labelMatch.push({
470
- start: 0,
471
- end: h.end - descriptionPrefixLength
472
- });
473
- descriptionMatch.push({
474
- start: h.start,
475
- end: descriptionPrefixLength
476
- });
477
- } // Match on label part
478
- else if (h.start >= descriptionPrefixLength) {
479
- labelMatch.push({
480
- start: h.start - descriptionPrefixLength,
481
- end: h.end - descriptionPrefixLength
482
- });
483
- } // Match on description part
484
- else {
485
- descriptionMatch.push(h);
486
- }
487
- });
488
- return {
489
- score: labelDescriptionScore,
490
- labelMatch,
491
- descriptionMatch
492
- };
493
- }
494
- }
495
-
496
- return NO_ITEM_SCORE;
497
- }
498
-
499
- function createMatches(offsets) {
500
- const ret = [];
501
-
502
- if (!offsets) {
503
- return ret;
504
- }
505
-
506
- let last;
507
-
508
- for (const pos of offsets) {
509
- if (last && last.end === pos) {
510
- last.end += 1;
511
- } else {
512
- last = {
513
- start: pos,
514
- end: pos + 1
515
- };
516
- ret.push(last);
517
- }
518
- }
519
-
520
- return ret;
521
- }
522
-
523
- function normalizeMatches(matches) {
524
- // sort matches by start to be able to normalize
525
- const sortedMatches = matches.sort((matchA, matchB) => {
526
- return matchA.start - matchB.start;
527
- }); // merge matches that overlap
528
-
529
- const normalizedMatches = [];
530
- let currentMatch = undefined;
531
-
532
- for (const match of sortedMatches) {
533
- // if we have no current match or the matches
534
- // do not overlap, we take it as is and remember
535
- // it for future merging
536
- if (!currentMatch || !matchOverlaps(currentMatch, match)) {
537
- currentMatch = match;
538
- normalizedMatches.push(match);
539
- } // otherwise we merge the matches
540
- else {
541
- currentMatch.start = Math.min(currentMatch.start, match.start);
542
- currentMatch.end = Math.max(currentMatch.end, match.end);
543
- }
544
- }
545
-
546
- return normalizedMatches;
547
- }
548
-
549
- function matchOverlaps(matchA, matchB) {
550
- if (matchA.end < matchB.start) {
551
- return false; // A ends before B starts
552
- }
553
-
554
- if (matchB.end < matchA.start) {
555
- return false; // B ends before A starts
556
- }
557
-
558
- return true;
559
- } //#endregion
560
- //#region Comparers
561
-
562
-
563
- function compareItemsByFuzzyScore(itemA, itemB, query, fuzzy, accessor, cache) {
564
- const itemScoreA = scoreItemFuzzy(itemA, query, fuzzy, accessor, cache);
565
- const itemScoreB = scoreItemFuzzy(itemB, query, fuzzy, accessor, cache);
566
- const scoreA = itemScoreA.score;
567
- const scoreB = itemScoreB.score; // 1.) identity matches have highest score
568
-
569
- if (scoreA === PATH_IDENTITY_SCORE || scoreB === PATH_IDENTITY_SCORE) {
570
- if (scoreA !== scoreB) {
571
- return scoreA === PATH_IDENTITY_SCORE ? -1 : 1;
572
- }
573
- } // 2.) matches on label are considered higher compared to label+description matches
574
-
575
-
576
- if (scoreA > LABEL_SCORE_THRESHOLD || scoreB > LABEL_SCORE_THRESHOLD) {
577
- if (scoreA !== scoreB) {
578
- return scoreA > scoreB ? -1 : 1;
579
- } // prefer more compact matches over longer in label (unless this is a prefix match where
580
- // longer prefix matches are actually preferred)
581
-
582
-
583
- if (scoreA < LABEL_PREFIX_SCORE_THRESHOLD && scoreB < LABEL_PREFIX_SCORE_THRESHOLD) {
584
- const comparedByMatchLength = compareByMatchLength(itemScoreA.labelMatch, itemScoreB.labelMatch);
585
-
586
- if (comparedByMatchLength !== 0) {
587
- return comparedByMatchLength;
588
- }
589
- } // prefer shorter labels over longer labels
590
-
591
-
592
- const labelA = accessor.getItemLabel(itemA) || '';
593
- const labelB = accessor.getItemLabel(itemB) || '';
594
-
595
- if (labelA.length !== labelB.length) {
596
- return labelA.length - labelB.length;
597
- }
598
- } // 3.) compare by score in label+description
599
-
600
-
601
- if (scoreA !== scoreB) {
602
- return scoreA > scoreB ? -1 : 1;
603
- } // 4.) scores are identical: prefer matches in label over non-label matches
604
-
605
-
606
- const itemAHasLabelMatches = Array.isArray(itemScoreA.labelMatch) && itemScoreA.labelMatch.length > 0;
607
- const itemBHasLabelMatches = Array.isArray(itemScoreB.labelMatch) && itemScoreB.labelMatch.length > 0;
608
-
609
- if (itemAHasLabelMatches && !itemBHasLabelMatches) {
610
- return -1;
611
- } else if (itemBHasLabelMatches && !itemAHasLabelMatches) {
612
- return 1;
613
- } // 5.) scores are identical: prefer more compact matches (label and description)
614
-
615
-
616
- const itemAMatchDistance = computeLabelAndDescriptionMatchDistance(itemA, itemScoreA, accessor);
617
- const itemBMatchDistance = computeLabelAndDescriptionMatchDistance(itemB, itemScoreB, accessor);
618
-
619
- if (itemAMatchDistance && itemBMatchDistance && itemAMatchDistance !== itemBMatchDistance) {
620
- return itemBMatchDistance > itemAMatchDistance ? -1 : 1;
621
- } // 6.) scores are identical: start to use the fallback compare
622
-
623
-
624
- return fallbackCompare(itemA, itemB, query, accessor);
625
- }
626
-
627
- exports.compareItemsByFuzzyScore = compareItemsByFuzzyScore;
628
-
629
- function computeLabelAndDescriptionMatchDistance(item, score, accessor) {
630
- let matchStart = -1;
631
- let matchEnd = -1; // If we have description matches, the start is first of description match
632
-
633
- if (score.descriptionMatch && score.descriptionMatch.length) {
634
- matchStart = score.descriptionMatch[0].start;
635
- } // Otherwise, the start is the first label match
636
- else if (score.labelMatch && score.labelMatch.length) {
637
- matchStart = score.labelMatch[0].start;
638
- } // If we have label match, the end is the last label match
639
- // If we had a description match, we add the length of the description
640
- // as offset to the end to indicate this.
641
-
642
-
643
- if (score.labelMatch && score.labelMatch.length) {
644
- matchEnd = score.labelMatch[score.labelMatch.length - 1].end;
645
-
646
- if (score.descriptionMatch && score.descriptionMatch.length) {
647
- const itemDescription = accessor.getItemDescription(item);
648
-
649
- if (itemDescription) {
650
- matchEnd += itemDescription.length;
651
- }
652
- }
653
- } // If we have just a description match, the end is the last description match
654
- else if (score.descriptionMatch && score.descriptionMatch.length) {
655
- matchEnd = score.descriptionMatch[score.descriptionMatch.length - 1].end;
656
- }
657
-
658
- return matchEnd - matchStart;
659
- }
660
-
661
- function compareByMatchLength(matchesA, matchesB) {
662
- if (!matchesA && !matchesB || (!matchesA || !matchesA.length) && (!matchesB || !matchesB.length)) {
663
- return 0; // make sure to not cause bad comparing when matches are not provided
664
- }
665
-
666
- if (!matchesB || !matchesB.length) {
667
- return -1;
668
- }
669
-
670
- if (!matchesA || !matchesA.length) {
671
- return 1;
672
- } // Compute match length of A (first to last match)
673
-
674
-
675
- const matchStartA = matchesA[0].start;
676
- const matchEndA = matchesA[matchesA.length - 1].end;
677
- const matchLengthA = matchEndA - matchStartA; // Compute match length of B (first to last match)
678
-
679
- const matchStartB = matchesB[0].start;
680
- const matchEndB = matchesB[matchesB.length - 1].end;
681
- const matchLengthB = matchEndB - matchStartB; // Prefer shorter match length
682
-
683
- return matchLengthA === matchLengthB ? 0 : matchLengthB < matchLengthA ? 1 : -1;
684
- }
685
-
686
- function fallbackCompare(itemA, itemB, query, accessor) {
687
- // check for label + description length and prefer shorter
688
- const labelA = accessor.getItemLabel(itemA) || '';
689
- const labelB = accessor.getItemLabel(itemB) || '';
690
- const descriptionA = accessor.getItemDescription(itemA);
691
- const descriptionB = accessor.getItemDescription(itemB);
692
- const labelDescriptionALength = labelA.length + (descriptionA ? descriptionA.length : 0);
693
- const labelDescriptionBLength = labelB.length + (descriptionB ? descriptionB.length : 0);
694
-
695
- if (labelDescriptionALength !== labelDescriptionBLength) {
696
- return labelDescriptionALength - labelDescriptionBLength;
697
- } // check for path length and prefer shorter
698
-
699
-
700
- const pathA = accessor.getItemPath(itemA);
701
- const pathB = accessor.getItemPath(itemB);
702
-
703
- if (pathA && pathB && pathA.length !== pathB.length) {
704
- return pathA.length - pathB.length;
705
- } // 7.) finally we have equal scores and equal length, we fallback to comparer
706
- // compare by label
707
-
708
-
709
- if (labelA !== labelB) {
710
- return comparers_1.compareAnything(labelA, labelB, query.normalized);
711
- } // compare by description
712
-
713
-
714
- if (descriptionA && descriptionB && descriptionA !== descriptionB) {
715
- return comparers_1.compareAnything(descriptionA, descriptionB, query.normalized);
716
- } // compare by path
717
-
718
-
719
- if (pathA && pathB && pathA !== pathB) {
720
- return comparers_1.compareAnything(pathA, pathB, query.normalized);
721
- } // equal
722
-
723
-
724
- return 0;
725
- }
726
- /**
727
- * Helper function to prepare a search value for scoring by removing unwanted characters
728
- * and allowing to score on multiple pieces separated by whitespace character.
729
- */
730
-
731
-
732
- const MULTIPLE_QUERY_VALUES_SEPARATOR = ' ';
733
-
734
- function prepareQuery(original) {
735
- if (typeof original !== 'string') {
736
- original = '';
737
- }
738
-
739
- const originalLowercase = original.toLowerCase();
740
- const {
741
- pathNormalized,
742
- normalized,
743
- normalizedLowercase
744
- } = normalizeQuery(original);
745
- const containsPathSeparator = pathNormalized.indexOf(path_1.sep) >= 0;
746
- let values = undefined;
747
- const originalSplit = original.split(MULTIPLE_QUERY_VALUES_SEPARATOR);
748
-
749
- if (originalSplit.length > 1) {
750
- for (const originalPiece of originalSplit) {
751
- const {
752
- pathNormalized: pathNormalizedPiece,
753
- normalized: normalizedPiece,
754
- normalizedLowercase: normalizedLowercasePiece
755
- } = normalizeQuery(originalPiece);
756
-
757
- if (normalizedPiece) {
758
- if (!values) {
759
- values = [];
760
- }
761
-
762
- values.push({
763
- original: originalPiece,
764
- originalLowercase: originalPiece.toLowerCase(),
765
- pathNormalized: pathNormalizedPiece,
766
- normalized: normalizedPiece,
767
- normalizedLowercase: normalizedLowercasePiece
768
- });
769
- }
770
- }
771
- }
772
-
773
- return {
774
- original,
775
- originalLowercase,
776
- pathNormalized,
777
- normalized,
778
- normalizedLowercase,
779
- values,
780
- containsPathSeparator
781
- };
782
- }
783
-
784
- exports.prepareQuery = prepareQuery;
785
-
786
- function normalizeQuery(original) {
787
- let pathNormalized;
788
-
789
- if (platform_1.isWindows) {
790
- pathNormalized = original.replace(/\//g, path_1.sep); // Help Windows users to search for paths when using slash
791
- } else {
792
- pathNormalized = original.replace(/\\/g, path_1.sep); // Help macOS/Linux users to search for paths when using backslash
793
- }
794
-
795
- const normalized = strings_1.stripWildcards(pathNormalized).replace(/\s/g, '');
796
- return {
797
- pathNormalized,
798
- normalized,
799
- normalizedLowercase: normalized.toLowerCase()
800
- };
801
- }
802
-
803
- function pieceToQuery(arg1) {
804
- if (Array.isArray(arg1)) {
805
- return prepareQuery(arg1.map(piece => piece.original).join(MULTIPLE_QUERY_VALUES_SEPARATOR));
806
- }
807
-
808
- return prepareQuery(arg1.original);
809
- }
810
-
811
- exports.pieceToQuery = pieceToQuery; //#endregion