From 74cac8291a978be7c0551850356aa279a4efa6ca Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Tue, 31 May 2016 17:23:08 -0400 Subject: [PATCH] Screen redraw optimization We don't have to clear the screen every time, we only have to make sure that we erase the rest of the line that used to be on the current line. We can still optimize a bit more by finding the longest line and drawing to that length, but using the full width is fine for now. --- cmd/micro/micro.go | 2 +- cmd/micro/view.go | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 066e3200..03807f7e 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -169,7 +169,7 @@ func InitScreen() { // RedrawAll redraws everything -- all the views and the messenger func RedrawAll() { - screen.Clear() + messenger.Clear() for _, v := range views { v.Display() } diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 8d85692c..a0539e8a 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -532,7 +532,6 @@ func (v *View) DisplayView() { } } // Write the line - tabchars := 0 for colN, ch := range line { var lineStyle tcell.Style @@ -570,17 +569,17 @@ func (v *View) DisplayView() { } } indentChar := []rune(settings["indentchar"].(string)) - screen.SetContent(x-v.leftCol+tabchars, lineN, indentChar[0], nil, lineIndentStyle) + screen.SetContent(x-v.leftCol, lineN, indentChar[0], nil, lineIndentStyle) tabSize := int(settings["tabsize"].(float64)) for i := 0; i < tabSize-1; i++ { - tabchars++ - if x-v.leftCol+tabchars >= v.lineNumOffset { - screen.SetContent(x-v.leftCol+tabchars, lineN, ' ', nil, lineStyle) + x++ + if x-v.leftCol >= v.lineNumOffset { + screen.SetContent(x-v.leftCol, lineN, ' ', nil, lineStyle) } } } else { - if x-v.leftCol+tabchars >= v.lineNumOffset { - screen.SetContent(x-v.leftCol+tabchars, lineN, ch, nil, lineStyle) + if x-v.leftCol >= v.lineNumOffset { + screen.SetContent(x-v.leftCol, lineN, ch, nil, lineStyle) } } charNum++ @@ -599,10 +598,14 @@ func (v *View) DisplayView() { if style, ok := colorscheme["selection"]; ok { selectStyle = style } - screen.SetContent(x-v.leftCol+tabchars, lineN, ' ', nil, selectStyle) + screen.SetContent(x-v.leftCol, lineN, ' ', nil, selectStyle) } charNum++ + + for i := 0; i < v.width-x; i++ { + screen.SetContent(x+i, lineN, ' ', nil, defStyle) + } } }