@@ -67,18 +67,18 @@ import debounce from "~/utilities/debounce";
6767 :key =" s.name + '_' + i"
6868 class =" px-3 py-2 text-sm cursor-pointer hover:bg-muted/60"
6969 :class =" { 'bg-muted/70': i === suggestionIndex }"
70- @mousedown.prevent =" selectSuggestion(s.name )"
70+ @mousedown.prevent =" selectSuggestion(s.command )"
7171 >
7272 <div class =" flex items-start gap-3" >
7373 <div class =" min-w-0" >
7474 <div class =" font-mono text-foreground break-words" >
75- {{ s.name }}
75+ < span v-html = " s.name" ></ span >
7676 </div >
7777 <div
7878 v-if =" s.description"
7979 class =" text-xs text-muted-foreground mt-0.5 line-clamp-2"
8080 >
81- {{ s.description }}
81+ < span v-html = " s.description" ></ span >
8282 </div >
8383 </div >
8484 <div
@@ -271,6 +271,7 @@ export default {
271271 historyIndex: - 1 as number , // -1 means not navigating history
272272 historyTemp: " " as string , // buffer of current input before history navigation
273273 suggestions: [] as Array <{
274+ command: string ;
274275 name: string ;
275276 kind? : string ;
276277 flags? : string ;
@@ -352,16 +353,37 @@ export default {
352353 });
353354 const data = await res .json ();
354355 const commands = Array .isArray (data ?.hits ) ? data .hits : [];
355- this .suggestions = commands .map (function (command : {
356- document: {
357- name: string ;
358- kind: string ;
359- flags: string ;
360- description: string ;
361- };
362- }) {
363- return command .document ;
364- });
356+ this .suggestions = commands .map (
357+ (command : {
358+ document: {
359+ command: string ;
360+ name: string ;
361+ kind: string ;
362+ flags: string ;
363+ description: string ;
364+ };
365+ highlights: Array <{
366+ field: string ;
367+ snippet: string ;
368+ }>;
369+ text_match_info: {
370+ best_field_score: string ;
371+ };
372+ }) => {
373+ command .document .command = command .document .name ;
374+
375+ for (const highlight of command .highlights ) {
376+ if (highlight .field === " name" ) {
377+ command .document .name = highlight .snippet ;
378+ }
379+ if (highlight .field === " description" ) {
380+ command .document .description = highlight .snippet ;
381+ }
382+ }
383+
384+ return command .document ;
385+ },
386+ );
365387 this .showSuggestions = this .suggestions .length > 0 ;
366388 } catch (error ) {
367389 console .error (` unable to fetch suggestions ` , error );
@@ -384,8 +406,8 @@ export default {
384406 onCommandBlur() {
385407 setTimeout (() => (this .showSuggestions = false ), 100 );
386408 },
387- selectSuggestion(name : string ) {
388- this .form .setFieldValue (" command" , name );
409+ selectSuggestion(command : string ) {
410+ this .form .setFieldValue (" command" , command );
389411 this .showSuggestions = false ;
390412 this .sendCommand ();
391413 },
@@ -418,6 +440,14 @@ export default {
418440 onCommandKeyDown(event : KeyboardEvent ) {
419441 // When suggestions are visible, arrow keys navigate suggestions instead of history
420442 if (this .showSuggestions && this .suggestions .length > 0 ) {
443+ if (event .key === " Tab" ) {
444+ const selected = this .suggestions [0 ];
445+ if (selected ?.command ) {
446+ this .selectSuggestion (selected .command );
447+ event .preventDefault ();
448+ return ;
449+ }
450+ }
421451 if (event .key === " ArrowDown" ) {
422452 this .suggestionIndex =
423453 (this .suggestionIndex + 1 ) % this .suggestions .length ;
@@ -434,8 +464,8 @@ export default {
434464 if (event .key === " Enter" ) {
435465 if (this .suggestionIndex >= 0 ) {
436466 const selected = this .suggestions [this .suggestionIndex ];
437- if (selected ?.name ) {
438- this .selectSuggestion (selected .name );
467+ if (selected ?.command ) {
468+ this .selectSuggestion (selected .command );
439469 event .preventDefault ();
440470 return ;
441471 }
0 commit comments