fix single line release state
This commit is contained in:
parent
f8e59c1465
commit
caf622f43f
@ -28,7 +28,16 @@ func singleLineEdit(r rune, s singleLineState) ([]rune, singleLineState) {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@ -16,4 +16,14 @@ func TestSingleLine(t *testing.T) {
|
||||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user