}
func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
+ if width <= 0 {
+ return
+ }
+
+ matchingBrace := Loc{-1, -1}
+ // bracePairs is defined in buffer.go
+ if buf.Settings["matchbrace"].(bool) {
+ for _, bp := range bracePairs {
+ if buf.Cursor.RuneUnder(buf.Cursor.X) == bp[0] {
+ matchingBrace = buf.FindMatchingBrace(bp, buf.Cursor.Loc)
+ break
+ }
+ left := buf.Cursor.Loc.X
+ if buf.Settings["matchbraceleft"].(bool) {
+ left -= 1
+ if left < 0 {
+ left = 0
+ }
+ }
+ if buf.Cursor.RuneUnder(left) == bp[1] {
+ matchingBrace = buf.FindMatchingBrace(
+ bp, Loc{X: left, Y: buf.Cursor.Loc.Y})
+ }
+ }
+ }
+
tabsize := int(buf.Settings["tabsize"].(float64))
softwrap := buf.Settings["softwrap"].(bool)
indentrunes := []rune(buf.Settings["indentchar"].(string))
// if empty indentchar settings, use space
if indentrunes == nil || len(indentrunes) == 0 {
- indentrunes = []rune(" ")
+ indentrunes = []rune{' '}
}
indentchar := indentrunes[0]
char := line[colN]
if viewCol >= 0 {
- c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, char, curStyle, 1}
+ st := curStyle
+ if colN == matchingBrace.X && lineN == matchingBrace.Y && !buf.Cursor.HasSelection() {
+ st = curStyle.Reverse(true)
+ }
+ if viewCol < len(c.lines[viewLine]) {
+ c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, char, st, 1}
+ }
}
if char == '\t' {
charWidth := tabsize - (viewCol+left)%tabsize
c.lines[viewLine][viewCol].width = charWidth
indentStyle := curStyle
- if group, ok := colorscheme["indent-char"]; ok {
+ ch := buf.Settings["indentchar"].(string)
+ if group, ok := colorscheme["indent-char"]; ok && !IsStrWhitespace(ch) && ch != "" {
indentStyle = group
}
for i := 1; i < charWidth; i++ {
viewCol++
- if viewCol >= 0 && viewCol < lineLength {
+ if viewCol >= 0 && viewCol < lineLength && viewCol < len(c.lines[viewLine]) {
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, ' ', curStyle, 1}
}
}
}
for i := 1; i < charWidth; i++ {
viewCol++
- if viewCol >= 0 && viewCol < lineLength {
+ if viewCol >= 0 && viewCol < lineLength && viewCol < len(c.lines[viewLine]) {
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, ' ', curStyle, 1}
}
}