Skip to content

Commit 7a9081a

Browse files
authored
Fix bug where opts.search_max_lines was not respected (#647)
Fixes #644.
1 parent 3cc9aaa commit 7a9081a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

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

14+
### Fixed
15+
16+
- Fixed bug where `opts.search_max_lines` was not propagated through some client methods.
17+
1418
## [v3.8.1](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.8.1) - 2024-06-26
1519

1620
### Fixed

lua/obsidian/client.lua

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ end
462462
---@param opts { search: obsidian.SearchOpts|?, notes: obsidian.note.LoadOpts|? }|?
463463
Client.find_notes_async = function(self, term, callback, opts)
464464
opts = opts or {}
465+
opts.notes = opts.notes or {}
466+
if not opts.notes.max_lines then
467+
opts.notes.max_lines = self.opts.search_max_lines
468+
end
465469

466470
local next_path = self:_search_iter_async(term, opts.search)
467471
local executor = AsyncExecutor.new()
@@ -606,6 +610,10 @@ end
606610
---@return obsidian.Note|?
607611
Client.resolve_note_async = function(self, query, callback, opts)
608612
opts = opts or {}
613+
opts.notes = opts.notes or {}
614+
if not opts.notes.max_lines then
615+
opts.notes.max_lines = self.opts.search_max_lines
616+
end
609617

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

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

998+
opts = opts or {}
999+
if not opts.max_lines then
1000+
opts.max_lines = self.opts.search_max_lines
1001+
end
9891002
return Note.from_buffer(bufnr, opts)
9901003
end
9911004

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

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

13491362
---@type obsidian.note.LoadOpts
1350-
local load_opts = { collect_anchor_links = opts.anchor ~= nil, collect_blocks = opts.block ~= nil }
1363+
local load_opts = {
1364+
collect_anchor_links = opts.anchor ~= nil,
1365+
collect_blocks = opts.block ~= nil,
1366+
max_lines = self.opts.search_max_lines,
1367+
}
13511368

13521369
---@param match MatchData
13531370
local function on_match(match)

0 commit comments

Comments
 (0)