fix: validate name when renaming in editor
I've noticed that validation of the new name when renaming a note in the editor doesn't work, so you can rename a note to an empty name or a name containing slashes from the editor. The problem was that _filenameFormKey.currentState?.validate() ?? true is always a string or true, but it should be false if the function returns null. I've also fixed a bug which made it impossible to save a note after renaming it in the editor but before the new name has been applied.
Codecov Report
Attention: Patch coverage is 50.00000% with 1 lines in your changes are missing coverage. Please review.
Project coverage is 36.97%. Comparing base (
f3afcea) to head (a2a29c5).
| Files | Patch % | Lines |
|---|---|---|
| lib/pages/editor/editor.dart | 50.00% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #1213 +/- ##
==========================================
+ Coverage 36.93% 36.97% +0.04%
==========================================
Files 111 111
Lines 8715 8716 +1
==========================================
+ Hits 3219 3223 +4
+ Misses 5496 5493 -3
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
_filenameFormKey.currentState?.validate() ?? true is always a string or true
The [FormState.validate] function returns true if there are no errors, otherwise false. Dart wouldn't accept an "if (string)" anyway.
I've also fixed a bug which made it impossible to save a note after renaming it in the editor but before the new name has been applied.
I'll need to look at this further but I don't have time rn
The [FormState.validate] function returns true if there are no errors, otherwise false. Dart wouldn't accept an "if (string)" anyway.
You're right, that doesn't solve the issue. I misunderstood how the validate() function works.
I've fixed it now. When you exit the editor after renaming the file, but before it has been saved, _filenameFormKey.currentState is null, so _filenameFormKey.currentState?.validate() ?? true is true and the file will be renamed, even though the validation didn't happen. By calling _validateFilenameTextField(newName) directly, the name is always validated.