mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Preserve existing behavior when editor is empty but make the message more clear
This commit is contained in:
parent
742a16b548
commit
cac3b43e19
4 changed files with 23 additions and 1 deletions
|
@ -311,7 +311,14 @@ def _edit_search_results(
|
||||||
other_entries = _other_entries(journal, old_entries)
|
other_entries = _other_entries(journal, old_entries)
|
||||||
|
|
||||||
# Send user to the editor
|
# Send user to the editor
|
||||||
edited = get_text_from_editor(config, journal.editable_str())
|
try:
|
||||||
|
edited = get_text_from_editor(config, journal.editable_str())
|
||||||
|
except JrnlException as e:
|
||||||
|
if e.has_message_text(MsgText.NoTextReceived):
|
||||||
|
raise JrnlException(Message(MsgText.NoEditsReceivedJournalNotDeleted, MsgStyle.WARNING))
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
journal.parse_editable_str(edited)
|
journal.parse_editable_str(edited)
|
||||||
|
|
||||||
# Put back entries we separated earlier, sort, and write the journal
|
# Put back entries we separated earlier, sort, and write the journal
|
||||||
|
|
|
@ -44,6 +44,9 @@ def get_text_from_editor(config: dict, template: str = "") -> str:
|
||||||
raw = f.read()
|
raw = f.read()
|
||||||
os.remove(tmpfile)
|
os.remove(tmpfile)
|
||||||
|
|
||||||
|
if not raw:
|
||||||
|
raise JrnlException(Message(MsgText.NoTextReceived, MsgStyle.NORMAL))
|
||||||
|
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ from jrnl.output import print_msg
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from jrnl.messages import Message
|
from jrnl.messages import Message
|
||||||
|
from jrnl.messages import MsgText
|
||||||
|
|
||||||
|
|
||||||
class JrnlException(Exception):
|
class JrnlException(Exception):
|
||||||
|
@ -18,3 +19,6 @@ class JrnlException(Exception):
|
||||||
def print(self) -> None:
|
def print(self) -> None:
|
||||||
for msg in self.messages:
|
for msg in self.messages:
|
||||||
print_msg(msg)
|
print_msg(msg)
|
||||||
|
|
||||||
|
def has_message_text(self, message_text: "MsgText"):
|
||||||
|
return any([m.text == message_text for m in self.messages])
|
|
@ -151,6 +151,14 @@ class MsgText(Enum):
|
||||||
https://jrnl.sh/en/stable/external-editors/
|
https://jrnl.sh/en/stable/external-editors/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
NoEditsReceivedJournalNotDeleted = """
|
||||||
|
No text received from editor. Were you trying to delete all the entries?
|
||||||
|
|
||||||
|
This seems a bit drastic, so the operation was cancelled.
|
||||||
|
|
||||||
|
To delete all entries, use the --delete option.
|
||||||
|
"""
|
||||||
|
|
||||||
NoEditsReceived = "No edits to save, because nothing was changed"
|
NoEditsReceived = "No edits to save, because nothing was changed"
|
||||||
|
|
||||||
NoTextReceived = """
|
NoTextReceived = """
|
||||||
|
|
Loading…
Add table
Reference in a new issue