-
-
Notifications
You must be signed in to change notification settings - Fork 127
/
commandpalette.ts
1540 lines (1343 loc) · 38.8 KB
/
commandpalette.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
import {
ArrayExt, StringExt
} from '@lumino/algorithm';
import {
JSONExt, ReadonlyJSONObject
} from '@lumino/coreutils';
import {
CommandRegistry
} from '@lumino/commands';
import {
ElementExt
} from '@lumino/domutils';
import {
Message
} from '@lumino/messaging';
import {
ElementDataset, VirtualDOM, VirtualElement, h
} from '@lumino/virtualdom';
import {
Widget
} from './widget';
/**
* A widget which displays command items as a searchable palette.
*/
export
class CommandPalette extends Widget {
/**
* Construct a new command palette.
*
* @param options - The options for initializing the palette.
*/
constructor(options: CommandPalette.IOptions) {
super({ node: Private.createNode() });
this.addClass('lm-CommandPalette');
/* <DEPRECATED> */
this.addClass('p-CommandPalette');
/* </DEPRECATED> */
this.setFlag(Widget.Flag.DisallowLayout);
this.commands = options.commands;
this.renderer = options.renderer || CommandPalette.defaultRenderer;
this.commands.commandChanged.connect(this._onGenericChange, this);
this.commands.keyBindingChanged.connect(this._onGenericChange, this);
}
/**
* Dispose of the resources held by the widget.
*/
dispose(): void {
this._items.length = 0;
this._results = null;
super.dispose();
}
/**
* The command registry used by the command palette.
*/
readonly commands: CommandRegistry;
/**
* The renderer used by the command palette.
*/
readonly renderer: CommandPalette.IRenderer;
/**
* The command palette search node.
*
* #### Notes
* This is the node which contains the search-related elements.
*/
get searchNode(): HTMLDivElement {
return this.node.getElementsByClassName('lm-CommandPalette-search')[0] as HTMLDivElement;
}
/**
* The command palette input node.
*
* #### Notes
* This is the actual input node for the search area.
*/
get inputNode(): HTMLInputElement {
return this.node.getElementsByClassName('lm-CommandPalette-input')[0] as HTMLInputElement;
}
/**
* The command palette content node.
*
* #### Notes
* This is the node which holds the command item nodes.
*
* Modifying this node directly can lead to undefined behavior.
*/
get contentNode(): HTMLUListElement {
return this.node.getElementsByClassName('lm-CommandPalette-content')[0] as HTMLUListElement;
}
/**
* A read-only array of the command items in the palette.
*/
get items(): ReadonlyArray<CommandPalette.IItem> {
return this._items;
}
/**
* Add a command item to the command palette.
*
* @param options - The options for creating the command item.
*
* @returns The command item added to the palette.
*/
addItem(options: CommandPalette.IItemOptions): CommandPalette.IItem {
// Create a new command item for the options.
let item = Private.createItem(this.commands, options);
// Add the item to the array.
this._items.push(item);
// Refresh the search results.
this.refresh();
// Return the item added to the palette.
return item;
}
/**
* Remove an item from the command palette.
*
* @param item - The item to remove from the palette.
*
* #### Notes
* This is a no-op if the item is not in the palette.
*/
removeItem(item: CommandPalette.IItem): void {
this.removeItemAt(this._items.indexOf(item));
}
/**
* Remove the item at a given index from the command palette.
*
* @param index - The index of the item to remove.
*
* #### Notes
* This is a no-op if the index is out of range.
*/
removeItemAt(index: number): void {
// Remove the item from the array.
let item = ArrayExt.removeAt(this._items, index);
// Bail if the index is out of range.
if (!item) {
return;
}
// Refresh the search results.
this.refresh();
}
/**
* Remove all items from the command palette.
*/
clearItems(): void {
// Bail if there is nothing to remove.
if (this._items.length === 0) {
return;
}
// Clear the array of items.
this._items.length = 0;
// Refresh the search results.
this.refresh();
}
/**
* Clear the search results and schedule an update.
*
* #### Notes
* This should be called whenever the search results of the palette
* should be updated.
*
* This is typically called automatically by the palette as needed,
* but can be called manually if the input text is programatically
* changed.
*
* The rendered results are updated asynchronously.
*/
refresh(): void {
this._results = null;
this.update();
}
/**
* Handle the DOM events for the command palette.
*
* @param event - The DOM event sent to the command palette.
*
* #### Notes
* This method implements the DOM `EventListener` interface and is
* called in response to events on the command palette's DOM node.
* It should not be called directly by user code.
*/
handleEvent(event: Event): void {
switch (event.type) {
case 'click':
this._evtClick(event as MouseEvent);
break;
case 'keydown':
this._evtKeyDown(event as KeyboardEvent);
break;
case 'input':
this.refresh();
break;
case 'focus':
case 'blur':
this._toggleFocused();
break;
}
}
/**
* A message handler invoked on a `'before-attach'` message.
*/
protected onBeforeAttach(msg: Message): void {
this.node.addEventListener('click', this);
this.node.addEventListener('keydown', this);
this.node.addEventListener('input', this);
this.node.addEventListener('focus', this, true);
this.node.addEventListener('blur', this, true);
}
/**
* A message handler invoked on an `'after-detach'` message.
*/
protected onAfterDetach(msg: Message): void {
this.node.removeEventListener('click', this);
this.node.removeEventListener('keydown', this);
this.node.removeEventListener('input', this);
this.node.removeEventListener('focus', this, true);
this.node.removeEventListener('blur', this, true);
}
/**
* A message handler invoked on an `'activate-request'` message.
*/
protected onActivateRequest(msg: Message): void {
if (this.isAttached) {
let input = this.inputNode;
input.focus();
input.select();
}
}
/**
* A message handler invoked on an `'update-request'` message.
*/
protected onUpdateRequest(msg: Message): void {
// Fetch the current query text and content node.
let query = this.inputNode.value;
let contentNode = this.contentNode;
// Ensure the search results are generated.
let results = this._results;
if (!results) {
// Generate and store the new search results.
results = this._results = Private.search(this._items, query);
// Reset the active index.
this._activeIndex = (
query ? ArrayExt.findFirstIndex(results, Private.canActivate) : -1
);
}
// If there is no query and no results, clear the content.
if (!query && results.length === 0) {
VirtualDOM.render(null, contentNode);
return;
}
// If the is a query but no results, render the empty message.
if (query && results.length === 0) {
let content = this.renderer.renderEmptyMessage({ query });
VirtualDOM.render(content, contentNode);
return;
}
// Create the render content for the search results.
let renderer = this.renderer;
let activeIndex = this._activeIndex;
let content = new Array<VirtualElement>(results.length);
for (let i = 0, n = results.length; i < n; ++i) {
let result = results[i];
if (result.type === 'header') {
let indices = result.indices;
let category = result.category;
content[i] = renderer.renderHeader({ category, indices });
} else {
let item = result.item;
let indices = result.indices;
let active = i === activeIndex;
content[i] = renderer.renderItem({ item, indices, active });
}
}
// Render the search result content.
VirtualDOM.render(content, contentNode);
// Adjust the scroll position as needed.
if (activeIndex < 0 || activeIndex >= results.length) {
contentNode.scrollTop = 0;
} else {
let element = contentNode.children[activeIndex];
ElementExt.scrollIntoViewIfNeeded(contentNode, element);
}
}
/**
* Handle the `'click'` event for the command palette.
*/
private _evtClick(event: MouseEvent): void {
// Bail if the click is not the left button.
if (event.button !== 0) {
return;
}
// Find the index of the item which was clicked.
let index = ArrayExt.findFirstIndex(this.contentNode.children, node => {
return node.contains(event.target as HTMLElement);
});
// Bail if the click was not on an item.
if (index === -1) {
return;
}
// Kill the event when a content item is clicked.
event.preventDefault();
event.stopPropagation();
// Execute the item if possible.
this._execute(index);
}
/**
* Handle the `'keydown'` event for the command palette.
*/
private _evtKeyDown(event: KeyboardEvent): void {
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
return;
}
switch (event.keyCode) {
case 13: // Enter
event.preventDefault();
event.stopPropagation();
this._execute(this._activeIndex);
break;
case 38: // Up Arrow
event.preventDefault();
event.stopPropagation();
this._activatePreviousItem();
break;
case 40: // Down Arrow
event.preventDefault();
event.stopPropagation();
this._activateNextItem();
break;
}
}
/**
* Activate the next enabled command item.
*/
private _activateNextItem(): void {
// Bail if there are no search results.
if (!this._results || this._results.length === 0) {
return;
}
// Find the next enabled item index.
let ai = this._activeIndex;
let n = this._results.length;
let start = ai < n - 1 ? ai + 1 : 0;
let stop = start === 0 ? n - 1 : start - 1;
this._activeIndex = ArrayExt.findFirstIndex(
this._results, Private.canActivate, start, stop
);
// Schedule an update of the items.
this.update();
}
/**
* Activate the previous enabled command item.
*/
private _activatePreviousItem(): void {
// Bail if there are no search results.
if (!this._results || this._results.length === 0) {
return;
}
// Find the previous enabled item index.
let ai = this._activeIndex;
let n = this._results.length;
let start = ai <= 0 ? n - 1 : ai - 1;
let stop = start === n - 1 ? 0 : start + 1;
this._activeIndex = ArrayExt.findLastIndex(
this._results, Private.canActivate, start, stop
);
// Schedule an update of the items.
this.update();
}
/**
* Execute the command item at the given index, if possible.
*/
private _execute(index: number): void {
// Bail if there are no search results.
if (!this._results) {
return;
}
// Bail if the index is out of range.
let part = this._results[index];
if (!part) {
return;
}
// Update the search text if the item is a header.
if (part.type === 'header') {
let input = this.inputNode;
input.value = `${part.category.toLowerCase()} `;
input.focus();
this.refresh();
return;
}
// Bail if item is not enabled.
if (!part.item.isEnabled) {
return;
}
// Execute the item.
this.commands.execute(part.item.command, part.item.args);
// Clear the query text.
this.inputNode.value = '';
// Refresh the search results.
this.refresh();
}
/**
* Toggle the focused modifier based on the input node focus state.
*/
private _toggleFocused(): void {
let focused = document.activeElement === this.inputNode;
this.toggleClass('lm-mod-focused', focused);
/* <DEPRECATED> */
this.toggleClass('p-mod-focused', focused);
/* </DEPRECATED> */
}
/**
* A signal handler for generic command changes.
*/
private _onGenericChange(): void {
this.refresh();
}
private _activeIndex = -1;
private _items: CommandPalette.IItem[] = [];
private _results: Private.SearchResult[] | null = null;
}
/**
* The namespace for the `CommandPalette` class statics.
*/
export
namespace CommandPalette {
/**
* An options object for creating a command palette.
*/
export
interface IOptions {
/**
* The command registry for use with the command palette.
*/
commands: CommandRegistry;
/**
* A custom renderer for use with the command palette.
*
* The default is a shared renderer instance.
*/
renderer?: IRenderer;
}
/**
* An options object for creating a command item.
*/
export
interface IItemOptions {
/**
* The category for the item.
*/
category: string;
/**
* The command to execute when the item is triggered.
*/
command: string;
/**
* The arguments for the command.
*
* The default value is an empty object.
*/
args?: ReadonlyJSONObject;
/**
* The rank for the command item.
*
* The rank is used as a tie-breaker when ordering command items
* for display. Items are sorted in the following order:
* 1. Text match (lower is better)
* 2. Category (locale order)
* 3. Rank (lower is better)
* 4. Label (locale order)
*
* The default rank is `Infinity`.
*/
rank?: number;
}
/**
* An object which represents an item in a command palette.
*
* #### Notes
* Item objects are created automatically by a command palette.
*/
export
interface IItem {
/**
* The command to execute when the item is triggered.
*/
readonly command: string;
/**
* The arguments for the command.
*/
readonly args: ReadonlyJSONObject;
/**
* The category for the command item.
*/
readonly category: string;
/**
* The rank for the command item.
*/
readonly rank: number;
/**
* The display label for the command item.
*/
readonly label: string;
/**
* The display caption for the command item.
*/
readonly caption: string;
/**
* The icon renderer for the command item.
*/
readonly icon: VirtualElement.IRenderer | undefined
/* <DEPRECATED> */ | string /* </DEPRECATED> */;
/**
* The icon class for the command item.
*/
readonly iconClass: string;
/**
* The icon label for the command item.
*/
readonly iconLabel: string;
/**
* The extra class name for the command item.
*/
readonly className: string;
/**
* The dataset for the command item.
*/
readonly dataset: CommandRegistry.Dataset;
/**
* Whether the command item is enabled.
*/
readonly isEnabled: boolean;
/**
* Whether the command item is toggled.
*/
readonly isToggled: boolean;
/**
* Whether the command item is visible.
*/
readonly isVisible: boolean;
/**
* The key binding for the command item.
*/
readonly keyBinding: CommandRegistry.IKeyBinding | null;
}
/**
* The render data for a command palette header.
*/
export
interface IHeaderRenderData {
/**
* The category of the header.
*/
readonly category: string;
/**
* The indices of the matched characters in the category.
*/
readonly indices: ReadonlyArray<number> | null;
}
/**
* The render data for a command palette item.
*/
export
interface IItemRenderData {
/**
* The command palette item to render.
*/
readonly item: IItem;
/**
* The indices of the matched characters in the label.
*/
readonly indices: ReadonlyArray<number> | null;
/**
* Whether the item is the active item.
*/
readonly active: boolean;
}
/**
* The render data for a command palette empty message.
*/
export
interface IEmptyMessageRenderData {
/**
* The query which failed to match any commands.
*/
query: string;
}
/**
* A renderer for use with a command palette.
*/
export
interface IRenderer {
/**
* Render the virtual element for a command palette header.
*
* @param data - The data to use for rendering the header.
*
* @returns A virtual element representing the header.
*/
renderHeader(data: IHeaderRenderData): VirtualElement;
/**
* Render the virtual element for a command palette item.
*
* @param data - The data to use for rendering the item.
*
* @returns A virtual element representing the item.
*
* #### Notes
* The command palette will not render invisible items.
*/
renderItem(data: IItemRenderData): VirtualElement;
/**
* Render the empty results message for a command palette.
*
* @param data - The data to use for rendering the message.
*
* @returns A virtual element representing the message.
*/
renderEmptyMessage(data: IEmptyMessageRenderData): VirtualElement;
}
/**
* The default implementation of `IRenderer`.
*/
export
class Renderer implements IRenderer {
/**
* Render the virtual element for a command palette header.
*
* @param data - The data to use for rendering the header.
*
* @returns A virtual element representing the header.
*/
renderHeader(data: IHeaderRenderData): VirtualElement {
let content = this.formatHeader(data);
return h.li({ className:
'lm-CommandPalette-header'
/* <DEPRECATED> */
+ ' p-CommandPalette-header'
/* </DEPRECATED> */
}, content);
}
/**
* Render the virtual element for a command palette item.
*
* @param data - The data to use for rendering the item.
*
* @returns A virtual element representing the item.
*/
renderItem(data: IItemRenderData): VirtualElement {
let className = this.createItemClass(data);
let dataset = this.createItemDataset(data);
return (
h.li({ className, dataset },
this.renderItemIcon(data),
this.renderItemContent(data),
this.renderItemShortcut(data),
)
);
}
/**
* Render the empty results message for a command palette.
*
* @param data - The data to use for rendering the message.
*
* @returns A virtual element representing the message.
*/
renderEmptyMessage(data: IEmptyMessageRenderData): VirtualElement {
let content = this.formatEmptyMessage(data);
return h.li({
className: 'lm-CommandPalette-emptyMessage'
/* <DEPRECATED> */
+ ' p-CommandPalette-emptyMessage'
/* </DEPRECATED> */
}, content);
}
/**
* Render the icon for a command palette item.
*
* @param data - The data to use for rendering the icon.
*
* @returns A virtual element representing the icon.
*/
renderItemIcon(data: IItemRenderData): VirtualElement {
let className = this.createIconClass(data);
/* <DEPRECATED> */
if (typeof data.item.icon === 'string') {
return h.div({className}, data.item.iconLabel);
}
/* </DEPRECATED> */
// if data.item.icon is undefined, it will be ignored
return h.div({className}, data.item.icon!, data.item.iconLabel);
}
/**
* Render the content for a command palette item.
*
* @param data - The data to use for rendering the content.
*
* @returns A virtual element representing the content.
*/
renderItemContent(data: IItemRenderData): VirtualElement {
return (
h.div({
className: 'lm-CommandPalette-itemContent'
/* <DEPRECATED> */
+ ' p-CommandPalette-itemContent'
/* </DEPRECATED> */
},
this.renderItemLabel(data),
this.renderItemCaption(data)
)
);
}
/**
* Render the label for a command palette item.
*
* @param data - The data to use for rendering the label.
*
* @returns A virtual element representing the label.
*/
renderItemLabel(data: IItemRenderData): VirtualElement {
let content = this.formatItemLabel(data);
return h.div({
className: 'lm-CommandPalette-itemLabel'
/* <DEPRECATED> */
+ ' p-CommandPalette-itemLabel'
/* </DEPRECATED> */
}, content);
}
/**
* Render the caption for a command palette item.
*
* @param data - The data to use for rendering the caption.
*
* @returns A virtual element representing the caption.
*/
renderItemCaption(data: IItemRenderData): VirtualElement {
let content = this.formatItemCaption(data);
return h.div({
className: 'lm-CommandPalette-itemCaption'
/* <DEPRECATED> */
+ ' p-CommandPalette-itemCaption'
/* </DEPRECATED> */
}, content);
}
/**
* Render the shortcut for a command palette item.
*
* @param data - The data to use for rendering the shortcut.
*
* @returns A virtual element representing the shortcut.
*/
renderItemShortcut(data: IItemRenderData): VirtualElement {
let content = this.formatItemShortcut(data);
return h.div({
className: 'lm-CommandPalette-itemShortcut'
/* <DEPRECATED> */
+ ' p-CommandPalette-itemShortcut'
/* </DEPRECATED> */
}, content);
}
/**
* Create the class name for the command palette item.
*
* @param data - The data to use for the class name.
*
* @returns The full class name for the command palette item.
*/
createItemClass(data: IItemRenderData): string {
// Set up the initial class name.
let name = 'lm-CommandPalette-item';
/* <DEPRECATED> */
name += ' p-CommandPalette-item';
/* </DEPRECATED> */
// Add the boolean state classes.
if (!data.item.isEnabled) {
name += ' lm-mod-disabled';
/* <DEPRECATED> */
name += ' p-mod-disabled';
/* </DEPRECATED> */
}
if (data.item.isToggled) {
name += ' lm-mod-toggled';
/* <DEPRECATED> */
name += ' p-mod-toggled';
/* </DEPRECATED> */
}
if (data.active) {
name += ' lm-mod-active';
/* <DEPRECATED> */
name += ' p-mod-active';
/* </DEPRECATED> */
}
// Add the extra class.
let extra = data.item.className;
if (extra) {
name += ` ${extra}`;
}
// Return the complete class name.
return name;
}
/**
* Create the dataset for the command palette item.
*
* @param data - The data to use for creating the dataset.
*
* @returns The dataset for the command palette item.
*/
createItemDataset(data: IItemRenderData): ElementDataset {
return { ...data.item.dataset, command: data.item.command };
}
/**
* Create the class name for the command item icon.
*
* @param data - The data to use for the class name.
*
* @returns The full class name for the item icon.
*/
createIconClass(data: IItemRenderData): string {
let name = 'lm-CommandPalette-itemIcon';
/* <DEPRECATED> */
name += ' p-CommandPalette-itemIcon';
/* </DEPRECATED> */
let extra = data.item.iconClass;
return extra ? `${name} ${extra}` : name;
}
/**
* Create the render content for the header node.
*
* @param data - The data to use for the header content.
*
* @returns The content to add to the header node.
*/
formatHeader(data: IHeaderRenderData): h.Child {
if (!data.indices || data.indices.length === 0) {
return data.category;
}
return StringExt.highlight(data.category, data.indices, h.mark);
}
/**
* Create the render content for the empty message node.
*
* @param data - The data to use for the empty message content.
*
* @returns The content to add to the empty message node.
*/
formatEmptyMessage(data: IEmptyMessageRenderData): h.Child {
return `No commands found that match '${data.query}'`;
}
/**
* Create the render content for the item shortcut node.
*
* @param data - The data to use for the shortcut content.
*
* @returns The content to add to the shortcut node.
*/
formatItemShortcut(data: IItemRenderData): h.Child {
let kb = data.item.keyBinding;
return kb ? kb.keys.map(CommandRegistry.formatKeystroke).join(', ') : null;
}
/**
* Create the render content for the item label node.
*
* @param data - The data to use for the label content.
*
* @returns The content to add to the label node.
*/
formatItemLabel(data: IItemRenderData): h.Child {
if (!data.indices || data.indices.length === 0) {
return data.item.label;
}
return StringExt.highlight(data.item.label, data.indices, h.mark);
}
/**
* Create the render content for the item caption node.
*
* @param data - The data to use for the caption content.
*
* @returns The content to add to the caption node.
*/
formatItemCaption(data: IItemRenderData): h.Child {