1
0

fix single line release state

This commit is contained in:
Arpad Ryszka 2025-11-02 01:23:00 +01:00
parent f8e59c1465
commit caf622f43f
2 changed files with 20 additions and 1 deletions

View File

@ -28,7 +28,16 @@ func singleLineEdit(r rune, s singleLineState) ([]rune, singleLineState) {
} }
func singleLineReleaseState(s singleLineState) []rune { func singleLineReleaseState(s singleLineState) []rune {
return s.currentWord if len(s.currentWord) == 0 {
return nil
}
var ret []rune
if s.started {
ret = append(ret, ' ')
}
return append(ret, s.currentWord...)
} }
func singleLine() Editor { func singleLine() Editor {

View File

@ -16,4 +16,14 @@ func TestSingleLine(t *testing.T) {
t.Fatal(b.String()) t.Fatal(b.String())
} }
}) })
t.Run("two lines", func(t *testing.T) {
var b bytes.Buffer
w := textedit.New(&b, textedit.SingleLine())
w.Write([]byte("Some sample text...\nwith invalid chars."))
w.Flush()
if b.String() != "Some sample text... with invalid chars." {
t.Fatal(b.String())
}
})
} }