mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-08-06 22:04:11 +00:00
Editor: Fix handling empty input
This commit is contained in:
parent
9713c18b6b
commit
7a98d29c74
@ -1,7 +1,6 @@
|
|||||||
package hyphae
|
package hyphae
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ import (
|
|||||||
func FetchMycomarkupFile(h Hypha) (string, error) {
|
func FetchMycomarkupFile(h Hypha) (string, error) {
|
||||||
switch h := h.(type) {
|
switch h := h.(type) {
|
||||||
case *EmptyHypha:
|
case *EmptyHypha:
|
||||||
return "", errors.New("empty hyphae have no text")
|
return "", nil
|
||||||
case *MediaHypha:
|
case *MediaHypha:
|
||||||
if !h.HasTextFile() {
|
if !h.HasTextFile() {
|
||||||
return "", nil
|
return "", nil
|
||||||
|
@ -62,17 +62,16 @@ func UploadText(h hyphae.Hypha, data []byte, userMessage string, u *user.User) e
|
|||||||
return errors.New("invalid hypha name")
|
return errors.New("invalid hypha name")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldText, err := hyphae.FetchMycomarkupFile(h)
|
||||||
|
if err != nil {
|
||||||
|
hop.Abort()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Empty data check
|
// Empty data check
|
||||||
if len(bytes.TrimSpace(data)) == 0 { // if nothing but whitespace
|
if len(bytes.TrimSpace(data)) == 0 && len(oldText) == 0 { // if nothing but whitespace
|
||||||
switch h.(type) {
|
hop.Abort()
|
||||||
case *hyphae.EmptyHypha, *hyphae.MediaHypha:
|
return nil
|
||||||
// Writing no description, it's ok, just like cancel button.
|
|
||||||
hop.Abort()
|
|
||||||
return nil
|
|
||||||
case *hyphae.TextualHypha:
|
|
||||||
// What do you want passing nothing for a textual hypha?
|
|
||||||
return errors.New("No data passed")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point, we have a savable user-generated Mycomarkup document. Gotta save it.
|
// At this point, we have a savable user-generated Mycomarkup document. Gotta save it.
|
||||||
@ -90,12 +89,6 @@ func UploadText(h hyphae.Hypha, data []byte, userMessage string, u *user.User) e
|
|||||||
hyphae.Insert(H)
|
hyphae.Insert(H)
|
||||||
backlinks.UpdateBacklinksAfterEdit(H, "")
|
backlinks.UpdateBacklinksAfterEdit(H, "")
|
||||||
case *hyphae.MediaHypha:
|
case *hyphae.MediaHypha:
|
||||||
oldText, err := hyphae.FetchMycomarkupFile(h)
|
|
||||||
if err != nil {
|
|
||||||
hop.Abort()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: that []byte(...) part should be removed
|
// TODO: that []byte(...) part should be removed
|
||||||
if bytes.Equal(data, []byte(oldText)) {
|
if bytes.Equal(data, []byte(oldText)) {
|
||||||
// No changes! Just like cancel button
|
// No changes! Just like cancel button
|
||||||
|
Loading…
x
Reference in New Issue
Block a user