From 89cab28b1cb0e12d48bd40c01d92890e5c777a64 Mon Sep 17 00:00:00 2001 From: Islam Sharabash Date: Mon, 17 Jun 2024 16:47:05 -0700 Subject: [PATCH 1/2] Make searching for notes by filename case insensitive (#620) * Make searching for notes by filename case insensitive I have a note named "Rob Snyder.md". When I tried to link to it with cmp like "[[rob " the note wasn't found. After this change the note is found. Note that `ignore_case` will set the `--ignore-case` flag in the rg command. However that flag is ignored and instead `--glob-case-insensitive` is what affects results. * Update CHANGELOG.md --------- Co-authored-by: Pete --- CHANGELOG.md | 4 ++++ lua/obsidian/client.lua | 8 +++++++- lua/obsidian/search.lua | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38752b8ea..73db1db37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +- Searching for notes by file name is case insensitive. + ## [v3.7.14](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.7.14) - 2024-06-04 ### Added diff --git a/lua/obsidian/client.lua b/lua/obsidian/client.lua index 325d40bed..c25f1e719 100644 --- a/lua/obsidian/client.lua +++ b/lua/obsidian/client.lua @@ -421,7 +421,13 @@ Client._search_iter_async = function(self, term, search_opts, find_opts) on_exit ) - search.find_async(self.dir, term, self:_prepare_search_opts(find_opts), on_find_match, on_exit) + search.find_async( + self.dir, + term, + self:_prepare_search_opts(find_opts, { ignore_case = true }), + on_find_match, + on_exit + ) return function() while cmds_done < 2 do diff --git a/lua/obsidian/search.lua b/lua/obsidian/search.lua index d64da6b0f..6b981c921 100644 --- a/lua/obsidian/search.lua +++ b/lua/obsidian/search.lua @@ -407,6 +407,10 @@ M.build_find_cmd = function(path, term, opts) additional_opts[#additional_opts + 1] = term end + if opts.ignore_case then + additional_opts[#additional_opts + 1] = "--glob-case-insensitive" + end + if path ~= nil and path ~= "." then if opts.escape_path then path = assert(vim.fn.fnameescape(tostring(path))) From 7e087da48bd88fb3a6c6229a97713ac35694337a Mon Sep 17 00:00:00 2001 From: Pio Mendoza <69317890+peeeyow@users.noreply.github.com> Date: Tue, 18 Jun 2024 07:51:32 +0800 Subject: [PATCH 2/2] feat(backlinks): make relative to root links searchable (#626) Co-authored-by: Pete --- CHANGELOG.md | 4 ++++ lua/obsidian/client.lua | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73db1db37..5a19a76ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Added relative to root markdown links as search pattern for backlinks. + ### Fixed - Searching for notes by file name is case insensitive. diff --git a/lua/obsidian/client.lua b/lua/obsidian/client.lua index c25f1e719..fb054e16b 100644 --- a/lua/obsidian/client.lua +++ b/lua/obsidian/client.lua @@ -1303,10 +1303,14 @@ Client.find_backlinks_async = function(self, note, callback, opts) search_terms[#search_terms + 1] = string.format("[[%s|", ref) -- Markdown link without anchor/block. search_terms[#search_terms + 1] = string.format("(%s)", ref) + -- Markdown link without anchor/block and is relative to root. + search_terms[#search_terms + 1] = string.format("(/%s)", ref) -- Wiki links with anchor/block. search_terms[#search_terms + 1] = string.format("[[%s#", ref) -- Markdown link with anchor/block. search_terms[#search_terms + 1] = string.format("(%s#", ref) + -- Markdown link with anchor/block and is relative to root. + search_terms[#search_terms + 1] = string.format("(/%s#", ref) elseif anchor then -- Note: Obsidian allow a lot of different forms of anchor links, so we can't assume -- it's the standardized form here. @@ -1314,11 +1318,15 @@ Client.find_backlinks_async = function(self, note, callback, opts) search_terms[#search_terms + 1] = string.format("[[%s#", ref) -- Markdown link with anchor. search_terms[#search_terms + 1] = string.format("(%s#", ref) + -- Markdown link with anchor and is relative to root. + search_terms[#search_terms + 1] = string.format("(/%s#", ref) elseif block then -- Wiki links with block. search_terms[#search_terms + 1] = string.format("[[%s#%s", ref, block) -- Markdown link with block. search_terms[#search_terms + 1] = string.format("(%s#%s", ref, block) + -- Markdown link with block and is relative to root. + search_terms[#search_terms + 1] = string.format("(/%s#%s", ref, block) end end end