diff --git a/view.go b/view.go index 7fb1e2f7..73d8fa7c 100644 --- a/view.go +++ b/view.go @@ -235,8 +235,7 @@ func (v *View) setRune(x, y int, ch rune, fgColor, bgColor Attribute) error { // y < total lines && y > 0 // (x < view width || x < y's line width) && x > 0 func (v *View) SetCursor(x, y int) error { - maxX, _ := v.Size() - if x < 0 || y < 0 || y >= len(v.lines) || (len(v.lines[y]) >= x && x >= maxX) { + if x < 0 || y < 0 || (y >= len(v.lines) && y != 0) || (x > 0 && (len(v.lines) == 0 || len(v.lines[y]) < x)) { return ErrInvalidPoint } @@ -598,14 +597,15 @@ func (v *View) draw() error { return nil } -// Clear empties the view's internal buffer. -// And resets reading and writing offsets. +// Clear empties the view and resets the view offsets, cursor position, read offsets and write offsets func (v *View) Clear() { v.writeMutex.Lock() v.Rewind() v.tainted = true v.ei.reset() - v.lines = nil + v.lines = [][]cell{} + v.SetCursor(0, 0) + v.SetOrigin(0, 0) v.clearRunes() v.writeMutex.Unlock() }