]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/cellview.go
Code optimisation (#1117)
[micro.git] / cmd / micro / cellview.go
index e8813a7988200f8f53b604049da2dafa37bc8b0f..b0cb6523c3602312b9ba8470d7cae65e83e12ed6 100644 (file)
@@ -73,9 +73,18 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
        // bracePairs is defined in buffer.go
        if buf.Settings["matchbrace"].(bool) {
                for _, bp := range bracePairs {
-                       r := buf.Cursor.RuneUnder(buf.Cursor.X)
+                       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, buf.Cursor.Loc)
+                               matchingBrace = buf.FindMatchingBrace(bp, curLoc)
                        }
                }
        }
@@ -85,7 +94,7 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
        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]
 
@@ -152,7 +161,9 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
                                if colN == matchingBrace.X && lineN == matchingBrace.Y && !buf.Cursor.HasSelection() {
                                        st = curStyle.Reverse(true)
                                }
-                               c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, char, st, 1}
+                               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
@@ -171,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}
                                        }
                                }
@@ -183,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}
                                        }
                                }