Draw tab characters correctly

This commit is contained in:
Zachary Yedidia 2017-02-19 12:34:51 -05:00
parent 1ba51e4f59
commit ff5c8d7451
2 changed files with 14 additions and 10 deletions

View file

@ -33,7 +33,10 @@ type Char struct {
visualLoc Loc
realLoc Loc
char rune
style tcell.Style
// The actual character that is drawn
// This is only different from char if it's for example hidden character
drawChar rune
style tcell.Style
}
type CellView struct {
@ -100,13 +103,13 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
char := line[colN]
if char == '\t' {
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, indentchar, curStyle}
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, indentchar, curStyle}
viewCol += tabsize - viewCol%tabsize
} else if runewidth.RuneWidth(char) > 1 {
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, curStyle}
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, char, curStyle}
viewCol += runewidth.RuneWidth(char)
} else {
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, curStyle}
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, char, curStyle}
viewCol++
}
colN++

View file

@ -3,6 +3,7 @@ package main
import "strconv"
func (v *View) DisplayView() {
tabsize := int(v.Buf.Settings["tabsize"].(float64))
if v.Type == vtLog {
// Log views should always follow the cursor...
v.Relocate()
@ -70,6 +71,8 @@ func (v *View) DisplayView() {
screenX++
}
lineStr := v.Buf.Line(realLineN)
// If there are gutter messages we need to display the '>>' symbol here
if hasGutterMessages {
// msgOnLine stores whether or not there is a gutter message on this line in particular
@ -156,23 +159,21 @@ func (v *View) DisplayView() {
}
var lastChar *Char
for i, char := range line {
for _, char := range line {
if char != nil {
if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
v.Cursor.Y == char.realLoc.Y && v.Cursor.X == char.realLoc.X {
screen.ShowCursor(xOffset+char.visualLoc.X, char.visualLoc.Y)
}
screen.SetContent(xOffset+char.visualLoc.X, char.visualLoc.Y, char.char, nil, char.style)
if i == len(line)-1 {
lastChar = char
}
screen.SetContent(xOffset+char.visualLoc.X, char.visualLoc.Y, char.drawChar, nil, char.style)
lastChar = char
}
}
if lastChar != nil {
if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
v.Cursor.Y == lastChar.realLoc.Y && v.Cursor.X == lastChar.realLoc.X+1 {
screen.ShowCursor(xOffset+lastChar.visualLoc.X+1, lastChar.visualLoc.Y)
screen.ShowCursor(xOffset+StringWidth(string(lineStr), tabsize), lastChar.visualLoc.Y)
}
} else if len(line) == 0 {
if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&