]> git.lizzy.rs Git - micro.git/commitdiff
Fix matchbraceleft option
authorZachary Yedidia <zyedidia@gmail.com>
Sat, 28 Apr 2018 21:42:17 +0000 (17:42 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Sat, 28 Apr 2018 21:42:17 +0000 (17:42 -0400)
Fixes #1101

cmd/micro/cellview.go

index 9c50856e4ab50ac5eefee8ba12c18395d02429d6..52fe73ff30142dc1b034a8531b8f21d6c00663f1 100644 (file)
@@ -73,20 +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 {
-                       if buf.Cursor.RuneUnder(buf.Cursor.X) == bp[0] {
-                               matchingBrace = buf.FindMatchingBrace(bp, buf.Cursor.Loc)
-                               break
-                       }
-                       left := buf.Cursor.Loc.X
+                       curX := buf.Cursor.X
+                       curLoc := buf.Cursor.Loc
                        if buf.Settings["matchbraceleft"].(bool) {
-                               left -= 1
-                               if left < 0 {
-                                       left = 0
+                               curX--
+                               if curX > 0 {
+                                       curLoc = curLoc.Move(-1, buf)
                                }
                        }
-                       if buf.Cursor.RuneUnder(left) == bp[1] {
-                               matchingBrace = buf.FindMatchingBrace(
-                                       bp, Loc{X: left, Y: buf.Cursor.Loc.Y})
+
+                       r := buf.Cursor.RuneUnder(curX)
+                       if r == bp[0] || r == bp[1] {
+                               matchingBrace = buf.FindMatchingBrace(bp, curLoc)
                        }
                }
        }