@@ -15,7 +15,6 @@ local ts_org = require('orgmode.treesitter')
15
15
local ts_table = require (' orgmode.treesitter.table' )
16
16
local EventManager = require (' orgmode.events' )
17
17
local Promise = require (' orgmode.utils.promise' )
18
- local TodoConfig = require (' orgmode.parser.todo-config' )
19
18
local events = EventManager .event
20
19
local Link = require (' orgmode.objects.link' )
21
20
387
386
function OrgMappings :_todo_change_state (direction )
388
387
local headline = ts_org .closest_headline ()
389
388
local _ , old_state , was_done = headline :todo ()
390
- --- @cast old_state - nil
391
- --- @cast was_done - nil
392
389
local changed = self :_change_todo_state (direction , true )
393
390
if not changed then
394
391
return
@@ -406,53 +403,9 @@ function OrgMappings:_todo_change_state(direction)
406
403
return dispatchEvent ()
407
404
end
408
405
409
- local new_state = item .todo_keyword .value
410
-
411
- -- Determine which configuration to use
412
- local global_config = config .org_log_done
413
-
414
- --- @type nil | false | ' time' | ' note'
415
- local section_config
416
- local logging_prop = item .properties .items .logging
417
- if logging_prop == ' nil' then
418
- section_config = false
419
- elseif logging_prop ~= nil then
420
- local todoConfig = TodoConfig :parse (logging_prop )
421
- if todoConfig ~= nil then
422
- section_config = todoConfig :get_logging_behavior (old_state , new_state )
423
- else
424
- -- TODO: Report invalid config?
425
- section_config = nil
426
- end
427
- else
428
- section_config = nil
429
- end
430
-
431
- -- @type nil | false | 'time' | 'note'
432
- local user_config
433
- if config .org_todo_keywords ~= nil then
434
- local todoConfig = TodoConfig :parse (table.concat (config .org_todo_keywords , ' ' ))
435
- if todoConfig ~= nil then
436
- user_config = todoConfig :get_logging_behavior (old_state , new_state )
437
- else
438
- -- TODO: Report invalid config?
439
- user_config = nil
440
- end
441
- else
442
- user_config = nil
443
- end
444
-
445
- -- Use the most locally available log config
446
- --- @type false | ' time' | ' note'
447
- local log_config
448
- if section_config ~= nil then
449
- log_config = section_config
450
- elseif user_config ~= nil then
451
- log_config = user_config
452
- else
453
- log_config = global_config
454
- end
455
-
406
+ local log_note = config .org_log_done == ' note'
407
+ local log_time = config .org_log_done == ' time'
408
+ local should_log_time = log_note or log_time
456
409
local indent = config :get_indent (headline :level () + 1 )
457
410
458
411
local get_note = function (note )
@@ -470,12 +423,11 @@ function OrgMappings:_todo_change_state(direction)
470
423
471
424
local repeater_dates = item :get_repeater_dates ()
472
425
if # repeater_dates == 0 then
473
- -- If going from "not done" to "done", set the closed date and add the note/time
474
- if log_config ~= false and item :is_done () and not was_done then
426
+ if should_log_time and item :is_done () and not was_done then
475
427
headline :set_closed_date ()
476
428
item = Files .get_closest_headline ()
477
429
478
- if log_config == ' note ' then
430
+ if log_note then
479
431
dispatchEvent ()
480
432
return self .capture .closing_note :open ():next (function (note )
481
433
local valid_note = get_note (note )
@@ -486,9 +438,7 @@ function OrgMappings:_todo_change_state(direction)
486
438
end )
487
439
end
488
440
end
489
-
490
- -- If going from "done" to "not done", remove the close date
491
- if log_config ~= false and not item :is_done () and was_done then
441
+ if should_log_time and not item :is_done () and was_done then
492
442
headline :remove_closed_date ()
493
443
end
494
444
return dispatchEvent ()
@@ -500,19 +450,19 @@ function OrgMappings:_todo_change_state(direction)
500
450
501
451
self :_change_todo_state (' reset' )
502
452
local state_change = {
503
- string.format (' %s- State "%s" from "%s" [%s]' , indent , new_state , old_state , Date .now ():to_string ()),
453
+ string.format (' %s- State "%s" from "%s" [%s]' , indent , item . todo_keyword . value , old_state , Date .now ():to_string ()),
504
454
}
505
455
506
456
dispatchEvent ()
507
457
return Promise .resolve ()
508
458
:next (function ()
509
- if log_config == ' time ' then
459
+ if not log_note then
510
460
return state_change
511
- elseif log_config == ' note' then
512
- return self .capture .closing_note :open ():next (function (closing_note )
513
- return get_note (closing_note )
514
- end )
515
461
end
462
+
463
+ return self .capture .closing_note :open ():next (function (closing_note )
464
+ return get_note (closing_note )
465
+ end )
516
466
end )
517
467
:next (function (note )
518
468
headline :set_property (' LAST_REPEAT' , Date .now ():to_wrapped_string (false ))
0 commit comments