diff --git a/widget/buffer.go b/widget/buffer.go index b6e89c85..40e02a86 100644 --- a/widget/buffer.go +++ b/widget/buffer.go @@ -113,6 +113,9 @@ func (e *editBuffer) Seek(offset int64, whence int) (ret int64, err error) { } func (e *editBuffer) Read(p []byte) (int, error) { + if len(p) == 0 { + return 0, nil + } if e.pos == e.len() { return 0, io.EOF } diff --git a/widget/editor_test.go b/widget/editor_test.go index 18c00732..4e14de75 100644 --- a/widget/editor_test.go +++ b/widget/editor_test.go @@ -121,6 +121,9 @@ func assertCaret(t *testing.T, e *Editor, line, col, bytes int) { if bytes != caretBytes { t.Errorf("caret at buffer position %d, expected %d", caretBytes, bytes) } + // Ensure that SelectedText() does not panic no matter what the + // editor's state is. + _ = e.SelectedText() } type editMutation int