@@ -376,6 +376,26 @@ function OrgMappings:toggle_heading()
376
376
vim .fn .setline (' .' , line )
377
377
end
378
378
379
+ --- Prompt for a note
380
+ --- @private
381
+ --- @param template string
382
+ --- @param indent string
383
+ --- @param title string
384
+ --- @return OrgPromise<string[]>
385
+ function OrgMappings :_get_note (template , indent , title )
386
+ return self .capture :build_note_capture (title ):open ():next (function (closing_note )
387
+ if closing_note == nil then
388
+ return
389
+ end
390
+
391
+ for i , line in ipairs (closing_note ) do
392
+ closing_note [i ] = indent .. ' ' .. line
393
+ end
394
+
395
+ return vim .list_extend ({ template }, closing_note )
396
+ end )
397
+ end
398
+
379
399
function OrgMappings :_todo_change_state (direction )
380
400
local headline = self .files :get_closest_headline ()
381
401
local old_state = headline :get_todo ()
@@ -403,20 +423,7 @@ function OrgMappings:_todo_change_state(direction)
403
423
local indent = headline :get_indent ()
404
424
405
425
local closing_note_text = (' %s- CLOSING NOTE %s \\\\ ' ):format (indent , Date .now ():to_wrapped_string (false ))
406
-
407
- local get_note = function (template )
408
- return self .capture .closing_note :open ():next (function (closing_note )
409
- if closing_note == nil then
410
- return
411
- end
412
-
413
- for i , line in ipairs (closing_note ) do
414
- closing_note [i ] = indent .. ' ' .. line
415
- end
416
-
417
- return vim .list_extend ({ template }, closing_note )
418
- end )
419
- end
426
+ local closed_title = ' Insert note for closed todo item'
420
427
421
428
local repeater_dates = item :get_repeater_dates ()
422
429
@@ -436,7 +443,7 @@ function OrgMappings:_todo_change_state(direction)
436
443
return item
437
444
end
438
445
439
- return get_note (closing_note_text ):next (function (closing_note )
446
+ return self : _get_note (closing_note_text , indent , closed_title ):next (function (closing_note )
440
447
return item :add_note (closing_note )
441
448
end )
442
449
end
@@ -455,6 +462,7 @@ function OrgMappings:_todo_change_state(direction)
455
462
old_state ,
456
463
Date .now ():to_string ()
457
464
)
465
+ local repeat_note_title = (' Insert note for state change from "%s" to "%s"' ):format (old_state , new_todo )
458
466
459
467
if log_repeat_enabled then
460
468
item :set_property (' LAST_REPEAT' , Date .now ():to_wrapped_string (false ))
@@ -470,12 +478,12 @@ function OrgMappings:_todo_change_state(direction)
470
478
471
479
-- Done note has precedence over repeat note
472
480
if prompt_done_note then
473
- return get_note (closing_note_text ):next (function (closing_note )
481
+ return self : _get_note (closing_note_text , indent , closed_title ):next (function (closing_note )
474
482
return item :add_note (closing_note )
475
483
end )
476
484
end
477
485
478
- return get_note (repeat_note_template .. ' \\\\ ' ):next (function (closing_note )
486
+ return self : _get_note (repeat_note_template .. ' \\\\ ' , indent , repeat_note_title ):next (function (closing_note )
479
487
return item :add_note (closing_note )
480
488
end )
481
489
end
@@ -803,6 +811,18 @@ function OrgMappings:_edit_special_callback()
803
811
EditSpecial :new ():done ()
804
812
end
805
813
814
+ function OrgMappings :add_note ()
815
+ local headline = self .files :get_closest_headline ()
816
+ local indent = headline :get_indent ()
817
+ local text = (' %s- Note taken on %s \\\\ ' ):format (indent , Date .now ():to_wrapped_string (false ))
818
+ return self :_get_note (text , indent , ' Insert note for entry.' ):next (function (note )
819
+ if not note then
820
+ return false
821
+ end
822
+ return headline :add_note (note )
823
+ end )
824
+ end
825
+
806
826
function OrgMappings :open_at_point ()
807
827
local link = Hyperlinks .get_link_under_cursor ()
808
828
if not link then
0 commit comments