@@ -9,23 +9,26 @@ local Date = require('orgmode.objects.date')
9
9
local Datetree = require (' orgmode.capture.template.datetree' )
10
10
11
11
--- @alias OrgOnCaptureClose fun ( capture : OrgCapture , opts : OrgProcessCaptureOpts )
12
+ --- @alias OrgOnCaptureCancel fun ( capture : OrgCapture )
12
13
13
14
--- @class OrgCapture
14
15
--- @field templates OrgCaptureTemplates
15
16
--- @field closing_note OrgCaptureWindow
16
17
--- @field files OrgFiles
17
18
--- @field on_pre_refile OrgOnCaptureClose
18
19
--- @field on_post_refile OrgOnCaptureClose
20
+ --- @field on_cancel_refile OrgOnCaptureCancel
19
21
--- @field _window OrgCaptureWindow
20
22
local Capture = {}
21
23
Capture .__index = Capture
22
24
23
- --- @param opts { files : OrgFiles , templates ?: OrgCaptureTemplates , on_pre_refile ?: OrgOnCaptureClose , on_post_refile ?: OrgOnCaptureClose }
25
+ --- @param opts { files : OrgFiles , templates ?: OrgCaptureTemplates , on_pre_refile ?: OrgOnCaptureClose , on_post_refile ?: OrgOnCaptureClose , on_cancel_refile ?: OrgOnCaptureCancel }
24
26
function Capture :new (opts )
25
27
local this = setmetatable ({}, self )
26
28
this .files = opts .files
27
29
this .on_pre_refile = opts .on_pre_refile
28
30
this .on_post_refile = opts .on_post_refile
31
+ this .on_cancel_refile = opts .on_cancel_refile
29
32
this .templates = opts .templates or Templates :new ()
30
33
this .closing_note = this :_setup_closing_note ()
31
34
return this
@@ -58,7 +61,7 @@ function Capture:setup_mappings()
58
61
local kill_map = maps .org_capture_kill
59
62
kill_map .map_entry
60
63
:with_handler (function ()
61
- return self :kill ()
64
+ return self :kill (true )
62
65
end )
63
66
:attach (kill_map .default_map , kill_map .user_map , kill_map .opts )
64
67
end
@@ -99,6 +102,9 @@ function Capture:on_refile_close()
99
102
vim .fn .confirm (string.format (' Do you want to refile this to %s?' , opts .destination_file .filename ), ' &Yes\n &No' )
100
103
vim .cmd ([[ redraw!]] )
101
104
if choice ~= 1 then
105
+ if self .on_cancel_refile then
106
+ self .on_cancel_refile (self )
107
+ end
102
108
return utils .echo_info (' Canceled.' )
103
109
end
104
110
end
@@ -446,8 +452,12 @@ function Capture:autocomplete_refile(arg_lead)
446
452
end , result )
447
453
end
448
454
449
- function Capture :kill ()
455
+ --- @param from_mapping ? boolean
456
+ function Capture :kill (from_mapping )
450
457
if self ._window then
458
+ if from_mapping and self .on_cancel_refile then
459
+ self .on_cancel_refile (self )
460
+ end
451
461
self ._window :kill ()
452
462
self ._window = nil
453
463
end
0 commit comments