// 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)
}
}
}
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]
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
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}
}
}