From 6409ebf217730f33b223e7e6b03d5f7a70abe8ac Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Sat, 13 Jan 2024 16:55:27 +0100 Subject: [PATCH] feat(input): note suggest shows the parent folder of the note --- src/suggesters/suggestFile.ts | 26 +++++++++++++++++++++----- styles.css | 6 ++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/suggesters/suggestFile.ts b/src/suggesters/suggestFile.ts index 3e54a558..6cf3d5b9 100644 --- a/src/suggesters/suggestFile.ts +++ b/src/suggesters/suggestFile.ts @@ -1,4 +1,4 @@ -import { AbstractInputSuggest, App, TFile } from "obsidian"; +import { AbstractInputSuggest, App, TFile, setIcon } from "obsidian"; import { enrich_tfile, get_tfiles_from_folder } from "../utils/files"; import { E, pipe, A } from "@std"; import Fuse from "fuse.js"; @@ -33,9 +33,19 @@ export class FileSuggest extends AbstractInputSuggest { const lower_input_str = input_str.toLowerCase(); if (input_str === "") return all_files.right; const fuse = new Fuse(all_files.right, { - keys: ["path", "tags", "frontmatter"], + includeMatches: false, + includeScore: true, + shouldSort: true, + keys: [ + { name: "path", weight: 2 }, + { name: "tags", weight: 1 }, + { name: "frontmatter.aliases", weight: 2 }, + ], + }); + return fuse.search(lower_input_str).map((result) => { + //console.log(result); + return result.item; }); - return fuse.search(lower_input_str).map((result) => result.item); } /* This is an example structure of how a obsidian suggestion looks like in the dom @@ -63,10 +73,16 @@ In the renderSuggestion the `el` is the suggestion-item div const text = this.strategy.renderSuggestion(file); el.addClasses(["mod-complex"]); const title = el.createDiv({ cls: "suggestion-title", text: text }); - const note = el.createDiv({ cls: "suggestion-note", text: file.parent?.path }); + const subtitle = el.createDiv({ + cls: "suggestion-note modal-form-suggestion", + text: file.parent?.path, + }); + const icon = el.createSpan({ cls: "suggestion-icon" }); + setIcon(icon, "folder"); + subtitle.prepend(icon); const body = el.createDiv({ cls: "suggestion-content" }); body.appendChild(title); - body.appendChild(note); + body.appendChild(subtitle); el.appendChild(body); } diff --git a/styles.css b/styles.css index 701eec35..9612518c 100644 --- a/styles.css +++ b/styles.css @@ -89,3 +89,9 @@ If your plugin does not need CSS, delete this file. color: var(--text-error); font-weight: bold; } +.modal-form-suggestion { + display: flex; + gap: 8px; + padding: 4px 0; + align-items: center; +}