Skip to content

Commit 95cb541

Browse files
feat(add_note): include heading title on add_note editor (#1100)
* feat(add_note): include heading title when adding note * test(add_note): includes heading title when adding note --------- Co-authored-by: Kristijan Husak <husakkristijan@gmail.com>
1 parent 2b2f327 commit 95cb541

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

lua/orgmode/org/mappings.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -862,12 +862,14 @@ function OrgMappings:add_note()
862862
local headline = self.files:get_closest_headline()
863863
local indent = headline:get_indent()
864864
local text = ('%s- Note taken on %s \\\\'):format(indent, Date.now():to_wrapped_string(false))
865-
return self:_get_note(text, indent, 'Insert note for entry.'):next(function(note)
866-
if not note then
867-
return false
868-
end
869-
return headline:add_note(note)
870-
end)
865+
return self
866+
:_get_note(text, indent, string.format('Insert note for %s.', headline:get_title() or 'entry'))
867+
:next(function(note)
868+
if not note then
869+
return false
870+
end
871+
return headline:add_note(note)
872+
end)
871873
end
872874

873875
function OrgMappings:open_at_point()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
local helpers = require('tests.plenary.helpers')
2+
local orgmode = require('orgmode')
3+
local Promise = require('orgmode.utils.promise')
4+
5+
describe('Add Note', function()
6+
after_each(function()
7+
vim.cmd([[silent! %bw!]])
8+
end)
9+
10+
it('includes heading title in note prompt', function()
11+
helpers.create_file({
12+
'* TODO Example Title',
13+
'Some content',
14+
})
15+
16+
-- Place cursor on the headline
17+
vim.fn.cursor(1, 1)
18+
19+
local captured_title = nil
20+
21+
helpers.with_var(orgmode.capture, 'build_note_capture', function(_, title)
22+
captured_title = title
23+
-- Return a stub with an open() that resolves immediately
24+
return {
25+
open = function()
26+
return Promise.resolve({ 'Test note content' })
27+
end,
28+
}
29+
end, function()
30+
orgmode.action('org_mappings.add_note')
31+
end)
32+
33+
assert.are.same('Insert note for Example Title.', captured_title)
34+
end)
35+
end)

0 commit comments

Comments
 (0)