mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-03 15:16:12 +02:00
Adjust fix for #1639 to still create entries if both --edit and --change-time flags are present
This commit is contained in:
parent
35b93f121c
commit
0fbdf25e83
2 changed files with 13 additions and 20 deletions
25
jrnl/jrnl.py
25
jrnl/jrnl.py
|
@ -187,12 +187,6 @@ def search_mode(args: "Namespace", journal: Journal, **kwargs) -> None:
|
||||||
if args.edit:
|
if args.edit:
|
||||||
# If we want to both edit and change time in one action
|
# If we want to both edit and change time in one action
|
||||||
if args.change_time:
|
if args.change_time:
|
||||||
if not journal:
|
|
||||||
# --edit can be called on an empty journal, but --edit
|
|
||||||
# and --change-time together means the user is likely
|
|
||||||
# expecting to have selected some entries; bail out
|
|
||||||
return
|
|
||||||
|
|
||||||
# Generate a new list instead of assigning so it won't be
|
# Generate a new list instead of assigning so it won't be
|
||||||
# modified by _change_time_search_results
|
# modified by _change_time_search_results
|
||||||
selected_entries = [e for e in journal.entries]
|
selected_entries = [e for e in journal.entries]
|
||||||
|
@ -210,9 +204,7 @@ def search_mode(args: "Namespace", journal: Journal, **kwargs) -> None:
|
||||||
_edit_search_results(**kwargs)
|
_edit_search_results(**kwargs)
|
||||||
|
|
||||||
elif not journal:
|
elif not journal:
|
||||||
# Bail out if there are no entries and we're not editing; we
|
# Bail out if there are no entries and we're not editing
|
||||||
# could put this before the above edit block, but there are
|
|
||||||
# some use cases where --edit is called on an empty journal
|
|
||||||
return
|
return
|
||||||
|
|
||||||
elif args.change_time:
|
elif args.change_time:
|
||||||
|
@ -445,16 +437,15 @@ def _change_time_search_results(
|
||||||
MsgText.ChangeTimeEntryQuestion
|
MsgText.ChangeTimeEntryQuestion
|
||||||
)
|
)
|
||||||
|
|
||||||
if entries_to_change:
|
other_entries += [e for e in journal.entries if e not in entries_to_change]
|
||||||
other_entries += [e for e in journal.entries if e not in entries_to_change]
|
journal.entries = entries_to_change
|
||||||
journal.entries = entries_to_change
|
|
||||||
|
|
||||||
date = time.parse(args.change_time)
|
date = time.parse(args.change_time)
|
||||||
journal.change_date_entries(date)
|
journal.change_date_entries(date)
|
||||||
|
|
||||||
journal.entries += other_entries
|
journal.entries += other_entries
|
||||||
journal.sort()
|
journal.sort()
|
||||||
journal.write()
|
journal.write()
|
||||||
|
|
||||||
|
|
||||||
def _display_search_results(args: "Namespace", journal: Journal, **kwargs) -> None:
|
def _display_search_results(args: "Namespace", journal: Journal, **kwargs) -> None:
|
||||||
|
|
|
@ -243,17 +243,19 @@ Feature: Change entry times in journal
|
||||||
# | basic_dayone.yaml | @todo
|
# | basic_dayone.yaml | @todo
|
||||||
|
|
||||||
|
|
||||||
Scenario Outline: --change-time with --edit and no selected entries doesn't overwrite journal
|
Scenario Outline: --change-time with --edit and an empty search adds an entry
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
And we write nothing to the editor if opened
|
And we write nothing to the editor if opened
|
||||||
And we use the password "test" if prompted
|
And we use the password "test" if prompted
|
||||||
When we run "jrnl -on tomorrow --change-time '2022-04-23 10:30' --edit"
|
And we append to the editor if opened
|
||||||
#Then the error output should contain "No entry to modify"
|
[2022-11-13 11:25] worked on jrnl tests
|
||||||
|
When we run "jrnl -on tomorrow --change-time --edit"
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-08-29 11:11 Entry the first.
|
2020-08-29 11:11 Entry the first.
|
||||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||||
2020-09-24 09:14 The third entry finally after weeks without writing.
|
2020-09-24 09:14 The third entry finally after weeks without writing.
|
||||||
|
2022-11-13 11:25 worked on jrnl tests
|
||||||
|
|
||||||
Examples: Configs
|
Examples: Configs
|
||||||
| config_file |
|
| config_file |
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue