From c5933466aa13b13101717eb5445b704e2539864e Mon Sep 17 00:00:00 2001 From: Levi Rizki Saputra <42236775+levirs565@users.noreply.github.com> Date: Tue, 26 Sep 2023 11:43:24 +0700 Subject: [PATCH] feat: add path autocompletion to lookup --- src/modal/lookup.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/modal/lookup.ts b/src/modal/lookup.ts index fc06bab..30dc211 100644 --- a/src/modal/lookup.ts +++ b/src/modal/lookup.ts @@ -13,6 +13,20 @@ interface LookupItem { export class LookupModal extends SuggestModal { constructor(app: App, private workspace: DendronWorkspace, private initialQuery: string = "") { super(app); + this.inputEl.addEventListener("keyup", (event) => { + if (event.code === "Tab") { + const selectedElement = this.resultContainerEl.querySelector( + ".is-selected" + ) as HTMLElement | null; + if (selectedElement) { + const path = selectedElement.dataset["path"]; + if (path) { + this.inputEl.value = path; + this.inputEl.dispatchEvent(new Event("input")); + } + } + } + }); } onOpen(): void { @@ -59,12 +73,15 @@ export class LookupModal extends SuggestModal { } renderSuggestion(item: LookupItem | null, el: HTMLElement) { el.classList.add("mod-complex"); + const path = item?.note.getPath(); + if (path) { + el.dataset["path"] = path; + } el.createEl("div", { cls: "suggestion-content" }, (el) => { el.createEl("div", { text: item?.note.title ?? "Create New", cls: "suggestion-title" }); el.createEl("small", { text: item - ? item.note.getPath() + - (this.workspace.vaultList.length > 1 ? ` (${item.vault.config.name})` : "") + ? path + (this.workspace.vaultList.length > 1 ? ` (${item.vault.config.name})` : "") : "Note does not exist", cls: "suggestion-content", });