mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-12 09:28:31 +02:00
Change time on the new entry when --change-time and --edit are used together with a search that matching no entries
This commit is contained in:
parent
0fbdf25e83
commit
3bd76faa9a
2 changed files with 23 additions and 8 deletions
17
jrnl/jrnl.py
17
jrnl/jrnl.py
|
@ -328,7 +328,11 @@ def _other_entries(journal: Journal, entries: list["Entry"]) -> list["Entry"]:
|
||||||
|
|
||||||
|
|
||||||
def _edit_search_results(
|
def _edit_search_results(
|
||||||
config: dict, journal: Journal, old_entries: list["Entry"], **kwargs
|
args: "Namespace",
|
||||||
|
config: dict,
|
||||||
|
journal: Journal,
|
||||||
|
old_entries: list["Entry"],
|
||||||
|
**kwargs
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
1. Send the given journal entries to the user-configured editor
|
1. Send the given journal entries to the user-configured editor
|
||||||
|
@ -350,6 +354,10 @@ def _edit_search_results(
|
||||||
# Get stats now for summary later
|
# Get stats now for summary later
|
||||||
old_stats = _get_predit_stats(journal)
|
old_stats = _get_predit_stats(journal)
|
||||||
|
|
||||||
|
# If we're adding a new entry (due to no entries matching the
|
||||||
|
# search), apply the change time operation if it was requested
|
||||||
|
do_change_time = not journal.entries and args.change_time
|
||||||
|
|
||||||
# Send user to the editor
|
# Send user to the editor
|
||||||
edited = get_text_from_editor(config, journal.editable_str())
|
edited = get_text_from_editor(config, journal.editable_str())
|
||||||
journal.parse_editable_str(edited)
|
journal.parse_editable_str(edited)
|
||||||
|
@ -358,6 +366,13 @@ def _edit_search_results(
|
||||||
_print_edited_summary(journal, old_stats)
|
_print_edited_summary(journal, old_stats)
|
||||||
|
|
||||||
# Put back entries we separated earlier, sort, and write the journal
|
# Put back entries we separated earlier, sort, and write the journal
|
||||||
|
if do_change_time:
|
||||||
|
# If we're changing time, _change_time_search_results will
|
||||||
|
# handle the recombining, sorting, and saving
|
||||||
|
_change_time_search_results(
|
||||||
|
args, journal, other_entries, no_prompt=True, **kwargs
|
||||||
|
)
|
||||||
|
else:
|
||||||
journal.entries += other_entries
|
journal.entries += other_entries
|
||||||
journal.sort()
|
journal.sort()
|
||||||
journal.write()
|
journal.write()
|
||||||
|
|
|
@ -243,19 +243,19 @@ Feature: Change entry times in journal
|
||||||
# | basic_dayone.yaml | @todo
|
# | basic_dayone.yaml | @todo
|
||||||
|
|
||||||
|
|
||||||
Scenario Outline: --change-time with --edit and an empty search adds an entry
|
Scenario Outline: --change-time with --edit and an empty search adds an entry at the specified time
|
||||||
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
|
||||||
And we append to the editor if opened
|
And we append to the editor if opened
|
||||||
[2022-11-13 11:25] worked on jrnl tests
|
worked on jrnl tests
|
||||||
When we run "jrnl -on tomorrow --change-time --edit"
|
When we run "jrnl -on tomorrow --change-time '2022-11-13 13:25' --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
|
2022-11-13 13:25 worked on jrnl tests
|
||||||
|
|
||||||
Examples: Configs
|
Examples: Configs
|
||||||
| config_file |
|
| config_file |
|
||||||
|
|
Loading…
Add table
Reference in a new issue