widget: make Editor implement io.Seeker, io.Reader and io.WriterTo

The WriteTo, Seek, Read methods implement a more efficient access to
the Editor content than Text.

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
pierre
2021-05-19 16:23:30 +02:00
committed by Elias Naur
parent df0e058ea6
commit b6e9c0324d
3 changed files with 67 additions and 0 deletions
+15
View File
@@ -1250,6 +1250,21 @@ func (e *Editor) ClearSelection() {
e.caret.end = e.caret.start
}
// WriteTo implements io.WriterTo.
func (e *Editor) WriteTo(w io.Writer) (int64, error) {
return e.rr.WriteTo(w)
}
// Seek implements io.Seeker.
func (e *Editor) Seek(offset int64, whence int) (int64, error) {
return e.rr.Seek(0, io.SeekStart)
}
// Read implements io.Reader.
func (e *Editor) Read(p []byte) (int, error) {
return e.rr.Read(p)
}
func max(a, b int) int {
if a > b {
return a