From 163ce4613967737c33af60b1f16b324ebc85649b Mon Sep 17 00:00:00 2001 From: Ankur Kumar <18713058+sirjager@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:55:38 +0530 Subject: [PATCH] fix: updated search.lua/build_find_cmd to extend support for md,mdx,mdoc --- lua/obsidian/search.lua | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lua/obsidian/search.lua b/lua/obsidian/search.lua index 2fca209c9..7b294c2df 100644 --- a/lua/obsidian/search.lua +++ b/lua/obsidian/search.lua @@ -392,14 +392,32 @@ end ---@return string[] M.build_find_cmd = function(path, term, opts) opts = SearchOpts.from_tbl(opts and opts or {}) - local additional_opts = {} - local pattern = require("obsidian.patterns").search_pattern + local additional_opts = {} if term ~= nil then - term = "*" .. term .. "*" + local valid_extensions = require("obsidian.patterns").file_extensions + if opts.include_non_markdown then + term = "*" .. term .. "*" + else + -- Check if term does not already have a valid extension + local has_valid_extension = false + for _, ext in ipairs(valid_extensions) do + if vim.endswith(term, ext) then + has_valid_extension = true + break + end + end + + if not has_valid_extension then + term = "*" .. term .. table.concat(valid_extensions, ",*") -- Match all valid extensions + else + term = "*" .. term + end + end + additional_opts[#additional_opts + 1] = "-g" - additional_opts[#additional_opts + 1] = pattern + additional_opts[#additional_opts + 1] = term end if opts.ignore_case then