Skip to content

fix(editor): discard a rich note nobody typed into - #166

Merged
pasichDev merged 1 commit into
masterfrom
fix/165-empty-extended-note
Sep 7, 2026
Merged

fix(editor): discard a rich note nobody typed into#166
pasichDev merged 1 commit into
masterfrom
fix/165-empty-extended-note

Conversation

@pasichDev

Copy link
Copy Markdown
Owner

Fixes #165.

Opening a note in the extended editor is enough to make the editor serialize a document — an empty paragraph, with an id — and emptiness was decided by comparing that string against "[]". So a new note left untouched read as meaningful: closeActivity() skipped the "new empty note → delete" branch, needsSave() actively wrote it, and the note showed up in the list and in the statistics.

What changed

  • EditorDocument.hasContent() (new) decides emptiness from the parsed blocks. A block counts as content unless it is a text block whose text is blank; any file reference counts, read through the existing EditorAttachmentBlocks walk, so data.file and data.files[] are both covered. Only the empty paragraph is written without the user asking for it, so a delimiter, a table, or a tool this build cannot read is kept, and an unreadable document is kept rather than discarded. Free of android.*, so the rule is exercised by ordinary JVM tests.
  • The attachments check had the same shape of bug. Every extended-editor change writes the parsed attachment list, which is the string "[]" when there are no files, and "the field is not blank" read that as "this note has attachments" — which alone kept the empty note alive even once the document check was right. It now asks Note.isAttachments(), the same method that already decides which editor a note opens in.
  • Removed the extended-editor branch in closeActivity() that its own comment called wrong. It is unreachable: needsSave() already requires content.

Behaviour worth knowing about

An existing note the user empties is no longer saved — the stored text stays and the note is not deleted either. That is what the simple editor has always done, and the parity this issue asks for, but it is a change for rich notes, so existingNoteEmptiedByTheUserKeepsWhatWasStored pins it as a deliberate decision rather than an accident.

Tests

17 new unit tests. EditorDocumentTest covers the shapes the issue lists — [], a single empty paragraph, whitespace and empty markup, empty header and list, an attachment as the only content — plus image/gallery blocks, a delimiter, a table, an unknown tool, and an unreadable document. NotePresenterEmptyExtendedNoteTest covers the close path end to end; its two "empty note" tests fail against the old check and pass against the new one.

Full unit suite, lintDebug and spotlessCheck are green.

Opening a note in the extended editor is enough to make the editor
serialize a document — an empty paragraph, with an id — and emptiness was
decided by comparing that string against "[]". So a new note left
untouched read as meaningful: closeActivity() skipped the "new empty note
→ delete" branch, needsSave() actively wrote it, and the note showed up
in the list and in the statistics.

Emptiness now comes from the parsed blocks (EditorDocument): a block
counts unless it is a text block whose text is blank, and any file
reference counts. Only the empty paragraph is written without the user
asking for it, so a delimiter, a table or a tool this build cannot read
is kept, and an unreadable document is kept rather than discarded.

The attachments check had the same shape of bug — every extended-editor
change writes the parsed attachment list, which is the string "[]" when
there are no files, and a non-blank field read as "has attachments",
which alone kept the empty note alive. It now asks Note.isAttachments().

That leaves the extended-editor branch inside closeActivity() (the one
its own comment called wrong) unreachable, since needsSave() already
requires content; removed.

Closes #165
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Test coverage (unit + instrumentation)

Overall Project 18.23% -0.12% 🍏
Files changed 47.48% 🍏

Module Coverage
debug 19.65% -0.23% 🍏
debug 16.81% -0.01% 🍏
Files
Module File Coverage
debug EditorDocument.java 0% 🍏
NotePresenter.java 0% -0.76% 🍏
debug EditorDocument.java 94.79% -5.21% 🍏
NotePresenter.java 50.76% 🍏

@pasichDev
pasichDev merged commit 2cf70f3 into master Sep 7, 2026
4 checks passed
@pasichDev
pasichDev deleted the fix/165-empty-extended-note branch September 7, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty note created in the extended editor is kept and counted in statistics

1 participant