Skip to content
Myr

Improve preview window rendering

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Fix incorrect display of the last line when more than a line is wrapped above - Avoid unnecessary flickering of the window

authored by Junegunn Choi · committed by Junegunn Choi · parent 28810c1 · Browse files · 4 files+21 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+21 added−6 removed

  • other:+21 added−6 removed

4 files+21 added−6 removed

modified:src/tui/light.go+12 added-4 removed
703 unmodified lines
704func (w *LightWindow) X() int {705 return w.posx706}707708func (w *LightWindow) Y() int {709 return w.posy710}711712func (w *LightWindow) Enclose(y int, x int) bool {713 return x >= w.left && x < (w.left+w.width) &&714 y >= w.top && y < (w.top+w.height)715}
126 unmodified lines
842 lines := wrapLine(line, w.posx, w.width, w.tabstop)843 for j, wl := range lines {844 if w.posx >= w.Width()-1 && wl.displayWidth == 0 {845 if w.posy < w.height-1 {842 w.MoveAndClear(w.posy+1, 0)846 w.Move(w.posy+1, 0)847 }848 return FillNextLine849 }850 w.stderrInternal(wl.text, false)851 w.posx += wl.displayWidth852853 // Wrap line854 if j < len(lines)-1 || i < len(allLines)-1 {855 if w.posy+1 >= w.height {856 return FillSuspend857 }852 w.MoveAndClear(w.posy+1, 0)858 w.MoveAndClear(w.posy, w.posx)859 w.Move(w.posy+1, 0)860 onMove()861 }862 }863 }
6 unmodified lines
870 }871}872873func (w *LightWindow) Fill(text string) FillReturn {867 w.MoveAndClear(w.posy, w.posx)874 w.Move(w.posy, w.posx)875 w.setBg()876 return w.fill(text, w.setBg)877}878879func (w *LightWindow) CFill(fg Color, bg Color, attr Attr, text string) FillReturn {873 w.MoveAndClear(w.posy, w.posx)880 w.Move(w.posy, w.posx)881 if bg == colDefault {882 bg = w.bg883 }884 if w.csiColor(fg, bg, attr) {
3 unmodified lines
888 return w.fill(text, w.setBg)889}890891func (w *LightWindow) FinishFill() {892 w.MoveAndClear(w.posy, w.posx)893 for y := w.posy + 1; y < w.height; y++ {894 w.MoveAndClear(y, 0)895 }896}
6 unmodified lines
modified:src/tui/tcell.go+4 added
162 unmodified lines
163func (w *TcellWindow) X() int {164 return w.lastX165}166167func (w *TcellWindow) Y() int {168 return w.lastY169}170171func (r *FullscreenRenderer) DoesAutoWrap() bool {172 return false173}174
408 unmodified lines
modified:src/tui/tui.go+1 added
234 unmodified lines
235 FinishFill()236 Close()237238 X() int239 Y() int240 Enclose(y int, x int) bool241242 Move(y int, x int)243 MoveAndClear(y int, x int)
186 unmodified lines
modified:src/terminal.go+4 added-2 removed
960 unmodified lines
961 maxWidth -= 1962 }963 reader := bufio.NewReader(strings.NewReader(t.previewer.text))964 lineNo := -t.previewer.offset965 height := t.pwindow.Height()966 var ansi *ansiState967 for {968 line, err := reader.ReadString('\n')969 eof := err == io.EOF970 if !eof {971 line = line[:len(line)-1]972 }973 lineNo++973 if lineNo > t.pwindow.Height() {974 if lineNo > height ||975 t.pwindow.Y() == height-1 && t.pwindow.X() > 0 {976 break977 } else if lineNo > 0 {978 var fillRet tui.FillReturn979 _, _, ansi = extractColor(line, ansi, func(str string, ansi *ansiState) bool {
21 unmodified lines
1001 break1002 }1003 }1004 t.pwindow.FinishFill()1003 if t.previewer.lines > t.pwindow.Height() {1005 if t.previewer.lines > height {1006 offset := fmt.Sprintf("%d/%d", t.previewer.offset+1, t.previewer.lines)1007 pos := t.pwindow.Width() - len(offset)1008 if t.tui.DoesAutoWrap() {1009 pos -= 1
839 unmodified lines