diff --git a/cmd/micro/cellview.go b/cmd/micro/cellview.go index f329ef78..78b547d8 100644 --- a/cmd/micro/cellview.go +++ b/cmd/micro/cellview.go @@ -45,6 +45,7 @@ type Char struct { // This is only different from char if it's for example hidden character drawChar rune style tcell.Style + width int } type CellView struct { @@ -113,16 +114,34 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) { char := line[colN] if viewCol >= 0 { - c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, char, curStyle} + c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, char, curStyle, 1} } if char == '\t' { + width := tabsize - (viewCol+left)%tabsize if viewCol >= 0 { c.lines[viewLine][viewCol].drawChar = indentchar + c.lines[viewLine][viewCol].width = width } - viewCol += tabsize - (viewCol+left)%tabsize + for i := 1; i < width; i++ { + viewCol++ + if viewCol >= 0 { + c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, ' ', curStyle, 1} + } + } + viewCol++ } else if runewidth.RuneWidth(char) > 1 { - viewCol += runewidth.RuneWidth(char) + width := runewidth.RuneWidth(char) + if viewCol >= 0 { + c.lines[viewLine][viewCol].width = width + } + for i := 1; i < width; i++ { + viewCol++ + if viewCol >= 0 { + c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, ' ', curStyle, 1} + } + } + viewCol++ } else { viewCol++ } diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 492ca84a..52f975ca 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -648,7 +648,6 @@ func (v *View) openHelp(helpPage string) { } func (v *View) DisplayView() { - tabsize := int(v.Buf.Settings["tabsize"].(float64)) if v.Type == vtLog { // Log views should always follow the cursor... v.Relocate() @@ -719,8 +718,6 @@ 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 @@ -807,6 +804,7 @@ func (v *View) DisplayView() { } var lastChar *Char + cursorSet := false for _, char := range line { if char != nil { lineStyle := char.style @@ -821,16 +819,12 @@ func (v *View) DisplayView() { if style, ok := colorscheme["selection"]; ok { lineStyle = style } - - width := StringWidth(string(char.char), tabsize) - for i := 1; i < width; i++ { - screen.SetContent(xOffset+char.visualLoc.X+i, yOffset+char.visualLoc.Y, ' ', nil, lineStyle) - } } if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() && - v.Cursor.Y == char.realLoc.Y && v.Cursor.X == char.realLoc.X { + v.Cursor.Y == char.realLoc.Y && v.Cursor.X == char.realLoc.X && !cursorSet { screen.ShowCursor(xOffset+char.visualLoc.X, yOffset+char.visualLoc.Y) + cursorSet = true } if v.Buf.Settings["cursorline"].(bool) && tabs[curTab].CurView == v.Num && @@ -838,11 +832,6 @@ func (v *View) DisplayView() { style := GetColor("cursor-line") fg, _, _ := style.Decompose() lineStyle = lineStyle.Background(fg) - - width := StringWidth(string(char.char), tabsize) - for i := 1; i < width; i++ { - screen.SetContent(xOffset+char.visualLoc.X+i, yOffset+char.visualLoc.Y, ' ', nil, lineStyle) - } } screen.SetContent(xOffset+char.visualLoc.X, yOffset+char.visualLoc.Y, char.drawChar, nil, lineStyle) @@ -855,11 +844,11 @@ func (v *View) DisplayView() { var realLoc Loc var visualLoc Loc if lastChar != nil { + lastX = xOffset + lastChar.visualLoc.X + lastChar.width 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+StringWidth(string(lineStr), tabsize), yOffset+lastChar.visualLoc.Y) + screen.ShowCursor(lastX, yOffset+lastChar.visualLoc.Y) } - lastX = xOffset + StringWidth(string(lineStr), tabsize) realLoc = Loc{lastChar.realLoc.X, realLineN} visualLoc = Loc{lastX - xOffset, lastChar.visualLoc.Y} } else if len(line) == 0 {