@@ -9,23 +9,26 @@ local Date = require('orgmode.objects.date')
99local Datetree = require (' orgmode.capture.template.datetree' )
1010
1111--- @alias OrgOnCaptureClose fun ( capture : OrgCapture , opts : OrgProcessCaptureOpts )
12+ --- @alias OrgOnCaptureCancel fun ( capture : OrgCapture )
1213
1314--- @class OrgCapture
1415--- @field templates OrgCaptureTemplates
1516--- @field closing_note OrgCaptureWindow
1617--- @field files OrgFiles
1718--- @field on_pre_refile OrgOnCaptureClose
1819--- @field on_post_refile OrgOnCaptureClose
20+ --- @field on_cancel_refile OrgOnCaptureCancel
1921--- @field _window OrgCaptureWindow
2022local Capture = {}
2123Capture .__index = Capture
2224
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 }
2426function Capture :new (opts )
2527 local this = setmetatable ({}, self )
2628 this .files = opts .files
2729 this .on_pre_refile = opts .on_pre_refile
2830 this .on_post_refile = opts .on_post_refile
31+ this .on_cancel_refile = opts .on_cancel_refile
2932 this .templates = opts .templates or Templates :new ()
3033 this .closing_note = this :_setup_closing_note ()
3134 return this
@@ -58,7 +61,7 @@ function Capture:setup_mappings()
5861 local kill_map = maps .org_capture_kill
5962 kill_map .map_entry
6063 :with_handler (function ()
61- return self :kill ()
64+ return self :kill (true )
6265 end )
6366 :attach (kill_map .default_map , kill_map .user_map , kill_map .opts )
6467end
@@ -99,6 +102,9 @@ function Capture:on_refile_close()
99102 vim .fn .confirm (string.format (' Do you want to refile this to %s?' , opts .destination_file .filename ), ' &Yes\n &No' )
100103 vim .cmd ([[ redraw!]] )
101104 if choice ~= 1 then
105+ if self .on_cancel_refile then
106+ self .on_cancel_refile (self )
107+ end
102108 return utils .echo_info (' Canceled.' )
103109 end
104110 end
@@ -446,8 +452,12 @@ function Capture:autocomplete_refile(arg_lead)
446452 end , result )
447453end
448454
449- function Capture :kill ()
455+ --- @param from_mapping ? boolean
456+ function Capture :kill (from_mapping )
450457 if self ._window then
458+ if from_mapping and self .on_cancel_refile then
459+ self .on_cancel_refile (self )
460+ end
451461 self ._window :kill ()
452462 self ._window = nil
453463 end
0 commit comments