Skip to content

Commit

Permalink
fix(note): Fix capturing note
Browse files Browse the repository at this point in the history
Closes #846
  • Loading branch information
kristijanhusak committed Jan 25, 2025
1 parent 056c217 commit e65a661
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 13 additions & 0 deletions lua/orgmode/capture/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,19 @@ function Capture:build_note_capture(title)
end)
:attach(kill_map.default_map, kill_map.user_map, kill_map.opts)
end,
on_close = function(capture_window)
local is_modified = vim.bo.modified

if is_modified then
local choice = vim.fn.confirm('Do you want to capture this note?', '&Yes\n&No')
vim.cmd([[redraw!]])
if choice ~= 1 then
return utils.echo_info('Canceled.')
end
end

capture_window:finish()
end,
})
end

Expand Down
13 changes: 11 additions & 2 deletions lua/orgmode/capture/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local Promise = require('orgmode.utils.promise')
---@field template OrgCaptureTemplate
---@field on_open? fun(self: OrgCaptureWindow)
---@field on_finish? fun(lines: string[]): string[] | nil
---@field on_close? fun()
---@field on_close? fun(self: OrgCaptureWindow)

---@class OrgCaptureWindow :OrgCaptureWindowOpts
---@field private _window fun() | nil
Expand Down Expand Up @@ -34,7 +34,7 @@ function CaptureWindow:open()
if not content then
return utils.echo_info('Canceled.')
end
self._window = utils.open_tmp_org_window(16, config.win_split_mode, config.win_border, self.on_close)
self._window = utils.open_tmp_org_window(16, config.win_split_mode, config.win_border, self:_on_close())
vim.api.nvim_buf_set_lines(0, 0, -1, true, content)
self.template:setup()
vim.b.org_capture = true
Expand All @@ -50,6 +50,15 @@ function CaptureWindow:open()
end)
end

function CaptureWindow:_on_close()
if not self.on_close then
return nil
end
return function()
self.on_close(self)
end
end

function CaptureWindow:finish()
local result = vim.api.nvim_buf_get_lines(0, 0, -1, false)
if self.on_finish then
Expand Down

0 comments on commit e65a661

Please sign in to comment.