Skip to content

Commit e65a661

Browse files
fix(note): Fix capturing note
Closes #846
1 parent 056c217 commit e65a661

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lua/orgmode/capture/init.lua

+13
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,19 @@ function Capture:build_note_capture(title)
489489
end)
490490
:attach(kill_map.default_map, kill_map.user_map, kill_map.opts)
491491
end,
492+
on_close = function(capture_window)
493+
local is_modified = vim.bo.modified
494+
495+
if is_modified then
496+
local choice = vim.fn.confirm('Do you want to capture this note?', '&Yes\n&No')
497+
vim.cmd([[redraw!]])
498+
if choice ~= 1 then
499+
return utils.echo_info('Canceled.')
500+
end
501+
end
502+
503+
capture_window:finish()
504+
end,
492505
})
493506
end
494507

lua/orgmode/capture/window.lua

+11-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local Promise = require('orgmode.utils.promise')
66
---@field template OrgCaptureTemplate
77
---@field on_open? fun(self: OrgCaptureWindow)
88
---@field on_finish? fun(lines: string[]): string[] | nil
9-
---@field on_close? fun()
9+
---@field on_close? fun(self: OrgCaptureWindow)
1010

1111
---@class OrgCaptureWindow :OrgCaptureWindowOpts
1212
---@field private _window fun() | nil
@@ -34,7 +34,7 @@ function CaptureWindow:open()
3434
if not content then
3535
return utils.echo_info('Canceled.')
3636
end
37-
self._window = utils.open_tmp_org_window(16, config.win_split_mode, config.win_border, self.on_close)
37+
self._window = utils.open_tmp_org_window(16, config.win_split_mode, config.win_border, self:_on_close())
3838
vim.api.nvim_buf_set_lines(0, 0, -1, true, content)
3939
self.template:setup()
4040
vim.b.org_capture = true
@@ -50,6 +50,15 @@ function CaptureWindow:open()
5050
end)
5151
end
5252

53+
function CaptureWindow:_on_close()
54+
if not self.on_close then
55+
return nil
56+
end
57+
return function()
58+
self.on_close(self)
59+
end
60+
end
61+
5362
function CaptureWindow:finish()
5463
local result = vim.api.nvim_buf_get_lines(0, 0, -1, false)
5564
if self.on_finish then

0 commit comments

Comments
 (0)