Skip to content

Commit

Permalink
feat: add path autocompletion to lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
levirs565 committed Sep 26, 2023
1 parent fda7555 commit c593346
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/modal/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ interface LookupItem {
export class LookupModal extends SuggestModal<LookupItem | null> {
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 {
Expand Down Expand Up @@ -59,12 +73,15 @@ export class LookupModal extends SuggestModal<LookupItem | null> {
}
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",
});
Expand Down

0 comments on commit c593346

Please sign in to comment.