Improve preview window rendering

- Fix incorrect display of the last line when more than a line is
  wrapped above
- Avoid unnecessary flickering of the window
This commit is contained in:
Junegunn Choi
2017-07-19 22:46:16 +09:00
parent 28810c178f
commit bc9d2abdb6
4 changed files with 21 additions and 6 deletions

View File

@@ -962,6 +962,7 @@ func (t *Terminal) printPreview() {
}
reader := bufio.NewReader(strings.NewReader(t.previewer.text))
lineNo := -t.previewer.offset
height := t.pwindow.Height()
var ansi *ansiState
for {
line, err := reader.ReadString('\n')
@@ -970,7 +971,8 @@ func (t *Terminal) printPreview() {
line = line[:len(line)-1]
}
lineNo++
if lineNo > t.pwindow.Height() {
if lineNo > height ||
t.pwindow.Y() == height-1 && t.pwindow.X() > 0 {
break
} else if lineNo > 0 {
var fillRet tui.FillReturn
@@ -1000,7 +1002,7 @@ func (t *Terminal) printPreview() {
}
}
t.pwindow.FinishFill()
if t.previewer.lines > t.pwindow.Height() {
if t.previewer.lines > height {
offset := fmt.Sprintf("%d/%d", t.previewer.offset+1, t.previewer.lines)
pos := t.pwindow.Width() - len(offset)
if t.tui.DoesAutoWrap() {