Strip trailing whitespace from each line in notes before saving

This commit is contained in:
2024-04-15 16:52:16 -04:00
parent 7d272f77ca
commit b784fd8bd7
2 changed files with 16 additions and 6 deletions
+10 -1
View File
@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"reflect"
"strings"
)
// RenameCli renames an entry at oldLocation to a new location (user input)
@@ -134,8 +135,16 @@ func editNote(baseNote []string) ([]string, bool) {
// close tempFile
tempFile.Close()
// remove trailing empty strings from the edited note
note = offline.RemoveTrailingEmptyStrings(note)
// trim trailing whitespace from each note line
for i, line := range note {
note[i] = strings.TrimRight(line, " \t\r\n")
}
// return the edited note if it is different from baseNote
if !reflect.DeepEqual(offline.RemoveTrailingEmptyStrings(note), baseNote) {
if !reflect.DeepEqual(note, baseNote) {
return note, true
} else {
return []string{}, false