From 9f6ec014245dc7ada185a4686658bb03e033faea Mon Sep 17 00:00:00 2001 From: tadashi-aikawa Date: Sat, 13 Aug 2022 14:49:39 +0900 Subject: [PATCH] Add a count view of the number of suggestions and an actual filter view --- src/ui/AnotherQuickSwitcherModal.ts | 28 +++++++++++++++++++++------- src/ui/icons.ts | 3 +++ styles.css | 8 ++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/ui/AnotherQuickSwitcherModal.ts b/src/ui/AnotherQuickSwitcherModal.ts index 8682483..7df1db2 100644 --- a/src/ui/AnotherQuickSwitcherModal.ts +++ b/src/ui/AnotherQuickSwitcherModal.ts @@ -21,7 +21,7 @@ import { sort } from "../sorters"; import { UnsafeModalInterface } from "./UnsafeModalInterface"; import { excludeFormat } from "../utils/strings"; import { MOD, quickResultSelectionModifier } from "src/keys"; -import { HEADER, LINK, SEARCH, TAG } from "./icons"; +import { FILTER, HEADER, LINK, SEARCH, TAG } from "./icons"; function buildLogMessage(message: string, msec: number) { return `${message}: ${Math.round(msec)}[ms]`; @@ -50,6 +50,7 @@ export class AnotherQuickSwitcherModal searchCommandEl?: HTMLDivElement; defaultInputEl?: HTMLDivElement; + countInputEl?: HTMLDivElement; constructor(app: App, settings: Settings, command: SearchCommand) { super(app); @@ -211,6 +212,7 @@ export class AnotherQuickSwitcherModal this.searchCommandEl?.remove(); this.defaultInputEl?.remove(); + this.countInputEl?.remove(); this.searchCommandEl = createDiv({ cls: "another-quick-switcher__status__search-command", @@ -226,13 +228,16 @@ export class AnotherQuickSwitcherModal if (this.command.searchBy.link) { this.searchCommandEl.insertAdjacentHTML("beforeend", LINK); } - - this.defaultInputEl = createDiv({ - text: this.command.defaultInput, - cls: "another-quick-switcher__status__default-input", - }); this.inputEl.before(this.searchCommandEl); - this.inputEl.before(this.defaultInputEl); + + if (this.command.defaultInput) { + this.defaultInputEl = createDiv({ + text: this.searchQuery, + cls: "another-quick-switcher__status__default-input", + }); + this.defaultInputEl.insertAdjacentHTML("afterbegin", FILTER); + this.resultContainerEl.before(this.defaultInputEl); + } const qs = this.searchQuery.split(" ").filter((x) => x); @@ -310,6 +315,15 @@ export class AnotherQuickSwitcherModal ) ); + this.countInputEl = createDiv({ + text: `${Math.min( + items.length, + this.settings.maxNumberOfSuggestions + )} / ${items.length}`, + cls: "another-quick-switcher__status__count-input", + }); + this.inputEl.before(this.countInputEl); + return items .slice(0, this.settings.maxNumberOfSuggestions) .map((x, order) => ({ ...x, order })); diff --git a/src/ui/icons.ts b/src/ui/icons.ts index 3b09fee..c2a4cf6 100644 --- a/src/ui/icons.ts +++ b/src/ui/icons.ts @@ -9,3 +9,6 @@ export const SEARCH = ` `; +export const FILTER = ` + +`; diff --git a/styles.css b/styles.css index 7276dec..974822d 100644 --- a/styles.css +++ b/styles.css @@ -95,6 +95,14 @@ margin: 0 5px; } .another-quick-switcher__status__default-input { + display: flex; + align-items: center; + font-size: 80%; + margin: 5px 0 0 20px; + /*noinspection CssUnresolvedCustomProperty*/ + color: var(--text-muted); +} +.another-quick-switcher__status__count-input { font-size: 85%; position: absolute; /*noinspection CssUnresolvedCustomProperty*/