Skip to content

Commit

Permalink
Fix bug where opts.search_max_lines was not respected (#647)
Browse files Browse the repository at this point in the history
Fixes #644.
  • Loading branch information
epwalsh authored Jul 11, 2024
1 parent 3cc9aaa commit 7a9081a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added `:ObsidianTOC` command for loading the table of contents of the current note into a picker list.

### Fixed

- Fixed bug where `opts.search_max_lines` was not propagated through some client methods.

## [v3.8.1](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.8.1) - 2024-06-26

### Fixed
Expand Down
21 changes: 19 additions & 2 deletions lua/obsidian/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ end
---@param opts { search: obsidian.SearchOpts|?, notes: obsidian.note.LoadOpts|? }|?
Client.find_notes_async = function(self, term, callback, opts)
opts = opts or {}
opts.notes = opts.notes or {}
if not opts.notes.max_lines then
opts.notes.max_lines = self.opts.search_max_lines
end

local next_path = self:_search_iter_async(term, opts.search)
local executor = AsyncExecutor.new()
Expand Down Expand Up @@ -606,6 +610,10 @@ end
---@return obsidian.Note|?
Client.resolve_note_async = function(self, query, callback, opts)
opts = opts or {}
opts.notes = opts.notes or {}
if not opts.notes.max_lines then
opts.notes.max_lines = self.opts.search_max_lines
end

-- Autocompletion for command args will have this format.
local note_path, count = string.gsub(query, "^.*  ", "")
Expand Down Expand Up @@ -803,6 +811,7 @@ Client.resolve_link_async = function(self, link, callback)
local load_opts = {
collect_anchor_links = anchor_link and true or false,
collect_blocks = block_link and true or false,
max_lines = self.opts.search_max_lines,
}

-- Assume 'location' is current buffer path if empty, like for TOCs.
Expand Down Expand Up @@ -986,6 +995,10 @@ Client.current_note = function(self, bufnr, opts)
return nil
end

opts = opts or {}
if not opts.max_lines then
opts.max_lines = self.opts.search_max_lines
end
return Note.from_buffer(bufnr, opts)
end

Expand Down Expand Up @@ -1086,7 +1099,7 @@ Client.find_tags_async = function(self, term, callback, opts)
---@param path obsidian.Path
---@return { [1]: obsidian.Note, [2]: {[1]: integer, [2]: integer}[] }
local load_note = function(path)
local note, contents = Note.from_file_with_contents_async(path, { max_lines = self.opts.search_max_lines or 1000 })
local note, contents = Note.from_file_with_contents_async(path, { max_lines = self.opts.search_max_lines })
return { note, search.find_code_blocks(contents) }
end

Expand Down Expand Up @@ -1347,7 +1360,11 @@ Client.find_backlinks_async = function(self, note, callback, opts)
end

---@type obsidian.note.LoadOpts
local load_opts = { collect_anchor_links = opts.anchor ~= nil, collect_blocks = opts.block ~= nil }
local load_opts = {
collect_anchor_links = opts.anchor ~= nil,
collect_blocks = opts.block ~= nil,
max_lines = self.opts.search_max_lines,
}

---@param match MatchData
local function on_match(match)
Expand Down

0 comments on commit 7a9081a

Please sign in to comment.