X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=cmd%2Fmicro%2Fcellview.go;h=b0cb6523c3602312b9ba8470d7cae65e83e12ed6;hb=d9735e5c3be7218392f2c3b4cd315d8f6d4834d6;hp=b864c6ba12940a2c271c179b12900f13e0c40e33;hpb=b8debb5404ae137ea02564e852dfe99d149ffc21;p=micro.git diff --git a/cmd/micro/cellview.go b/cmd/micro/cellview.go index b864c6ba..b0cb6523 100644 --- a/cmd/micro/cellview.go +++ b/cmd/micro/cellview.go @@ -38,7 +38,7 @@ func visualToCharPos(visualIndex int, lineN int, str string, buf *Buffer, tabsiz lastWidth = width rw = 0 if c == '\t' { - rw := tabsize - (lineIdx % tabsize) + rw = tabsize - (lineIdx % tabsize) width += rw } else { rw = runewidth.RuneWidth(c) @@ -65,12 +65,41 @@ type CellView struct { } 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 { + curX := buf.Cursor.X + curLoc := buf.Cursor.Loc + if buf.Settings["matchbraceleft"].(bool) { + if curX > 0 { + curX-- + curLoc = curLoc.Move(-1, buf) + } + } + + r := buf.Cursor.RuneUnder(curX) + if r == bp[0] || r == bp[1] { + matchingBrace = buf.FindMatchingBrace(bp, curLoc) + } + } + } + tabsize := int(buf.Settings["tabsize"].(float64)) softwrap := buf.Settings["softwrap"].(bool) - indentchar := []rune(buf.Settings["indentchar"].(string))[0] + indentrunes := []rune(buf.Settings["indentchar"].(string)) + // if empty indentchar settings, use space + if indentrunes == nil || len(indentrunes) == 0 { + indentrunes = []rune{' '} + } + indentchar := indentrunes[0] start := buf.Cursor.Y - if buf.Settings["syntax"].(bool) { + if buf.Settings["syntax"].(bool) && buf.syntaxDef != nil { if start > 0 && buf.lines[start-1].rehighlight { buf.highlighter.ReHighlightLine(buf, start-1) buf.lines[start-1].rehighlight = false @@ -128,7 +157,13 @@ 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, 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 @@ -137,7 +172,8 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) { 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 } @@ -146,7 +182,7 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) { 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} } } @@ -158,7 +194,7 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) { } 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} } }