Skip to content

Commit 1d4336b

Browse files
committed
feat: show current index of extensions
1 parent 35a0b7b commit 1d4336b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

denops/fall/picker.ts

+39
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ import { HelpComponent } from "./component/help.ts";
3434
import { consume, type Event } from "./event.ts";
3535

3636
const SCHEDULER_INTERVAL = 10;
37+
const MATCHER_ICON = " ";
38+
const SORTER_ICON = " ";
39+
const RENDERER_ICON = " ";
40+
const PREVIEWER_ICON = "󰥷 ";
3741

3842
type ReservedCallback = (
3943
denops: Denops,
@@ -62,6 +66,10 @@ export type PickerResult<T extends Detail> = {
6266

6367
export type PickerOptions = {
6468
schedulerInterval?: number;
69+
matcherIcon?: string;
70+
sorterIcon?: string;
71+
rendererIcon?: string;
72+
previewerIcon?: string;
6573
};
6674

6775
export class Picker<T extends Detail> implements AsyncDisposable {
@@ -81,12 +89,20 @@ export class Picker<T extends Detail> implements AsyncDisposable {
8189
readonly #helpComponent: HelpComponent;
8290
readonly #helpWidthRatio = 0.98;
8391
readonly #helpHeightRatio = 0.3;
92+
readonly #matcherIcon: string;
93+
readonly #sorterIcon: string;
94+
readonly #rendererIcon: string;
95+
readonly #previewerIcon: string;
8496
#selection: Set<unknown> = new Set();
8597

8698
constructor(params: PickerParams<T>, options: PickerOptions = {}) {
8799
this.#schedulerInterval = options.schedulerInterval ?? SCHEDULER_INTERVAL;
88100
this.#name = params.name;
89101
this.#coordinator = params.coordinator;
102+
this.#matcherIcon = options.matcherIcon ?? MATCHER_ICON;
103+
this.#sorterIcon = options.sorterIcon ?? SORTER_ICON;
104+
this.#rendererIcon = options.rendererIcon ?? RENDERER_ICON;
105+
this.#previewerIcon = options.previewerIcon ?? PREVIEWER_ICON;
90106

91107
// Components
92108
const { theme, zindex = 50 } = params;
@@ -151,6 +167,20 @@ export class Picker<T extends Detail> implements AsyncDisposable {
151167
return { row, col, width, height };
152168
}
153169

170+
#getExtensionIndicator(): string {
171+
const { matcherIndex } = this.#matchProcessor;
172+
const { sorterIndex } = this.#sortProcessor;
173+
const { rendererIndex } = this.#renderProcessor;
174+
const { previewerIndex } = this.#previewProcessor ?? {};
175+
const matcherIndicator = `${this.#matcherIcon}${matcherIndex + 1}`;
176+
const sorterIndicator = `${this.#sorterIcon}${sorterIndex + 1}`;
177+
const rendererIndicator = `${this.#rendererIcon}${rendererIndex + 1}`;
178+
const previewerIndicator = previewerIndex !== undefined
179+
? `${this.#previewerIcon}${previewerIndex + 1}`
180+
: "";
181+
return `${matcherIndicator} ${sorterIndicator} ${rendererIndicator} ${previewerIndicator}`;
182+
}
183+
154184
async open(
155185
denops: Denops,
156186
{ signal }: { signal?: AbortSignal },
@@ -264,6 +294,7 @@ export class Picker<T extends Detail> implements AsyncDisposable {
264294
if (args.length > 0) {
265295
this.#inputComponent.title = `${this.#name}:${args.join(" ")}`;
266296
}
297+
this.#listComponent.title = this.#getExtensionIndicator();
267298

268299
// Start mainloop
269300
let action: string | undefined;
@@ -441,6 +472,7 @@ export class Picker<T extends Detail> implements AsyncDisposable {
441472
}
442473
}
443474
this.#matchProcessor.matcherIndex = index;
475+
this.#listComponent.title = this.#getExtensionIndicator();
444476
reserve((denops) => {
445477
this.#matchProcessor.start(denops, {
446478
items: this.#collectProcessor.items,
@@ -453,6 +485,7 @@ export class Picker<T extends Detail> implements AsyncDisposable {
453485
}
454486
case "switch-matcher-at":
455487
this.#matchProcessor.matcherIndex = event.index;
488+
this.#listComponent.title = this.#getExtensionIndicator();
456489
reserve((denops) => {
457490
this.#matchProcessor.start(denops, {
458491
items: this.#collectProcessor.items,
@@ -472,6 +505,7 @@ export class Picker<T extends Detail> implements AsyncDisposable {
472505
}
473506
}
474507
this.#sortProcessor.sorterIndex = index;
508+
this.#listComponent.title = this.#getExtensionIndicator();
475509
reserve((denops) => {
476510
// NOTE:
477511
// We need to restart from the matcher processor because
@@ -486,6 +520,7 @@ export class Picker<T extends Detail> implements AsyncDisposable {
486520
}
487521
case "switch-sorter-at":
488522
this.#sortProcessor.sorterIndex = event.index;
523+
this.#listComponent.title = this.#getExtensionIndicator();
489524
reserve((denops) => {
490525
// NOTE:
491526
// We need to restart from the matcher processor because
@@ -507,6 +542,7 @@ export class Picker<T extends Detail> implements AsyncDisposable {
507542
}
508543
}
509544
this.#renderProcessor.rendererIndex = index;
545+
this.#listComponent.title = this.#getExtensionIndicator();
510546
reserve((denops) => {
511547
// NOTE:
512548
// We need to restart from the matcher processor because
@@ -521,6 +557,7 @@ export class Picker<T extends Detail> implements AsyncDisposable {
521557
}
522558
case "switch-renderer-at":
523559
this.#renderProcessor.rendererIndex = event.index;
560+
this.#listComponent.title = this.#getExtensionIndicator();
524561
reserve((denops) => {
525562
// NOTE:
526563
// We need to restart from the matcher processor because
@@ -543,6 +580,7 @@ export class Picker<T extends Detail> implements AsyncDisposable {
543580
}
544581
}
545582
this.#previewProcessor.previewerIndex = index;
583+
this.#listComponent.title = this.#getExtensionIndicator();
546584
reserve((denops) => {
547585
this.#previewProcessor?.start(denops, {
548586
item: this.#matchProcessor.items[this.#renderProcessor.cursor],
@@ -553,6 +591,7 @@ export class Picker<T extends Detail> implements AsyncDisposable {
553591
case "switch-previewer-at":
554592
if (!this.#previewProcessor) break;
555593
this.#previewProcessor.previewerIndex = event.index;
594+
this.#listComponent.title = this.#getExtensionIndicator();
556595
reserve((denops) => {
557596
this.#previewProcessor?.start(denops, {
558597
item: this.#matchProcessor.items[this.#renderProcessor.cursor],

0 commit comments

Comments
 (0)