mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +09:00
@@ -1060,11 +1060,15 @@ func (h *BufPane) JumpToMatchingBrace() bool {
|
|||||||
r := h.Cursor.RuneUnder(h.Cursor.X)
|
r := h.Cursor.RuneUnder(h.Cursor.X)
|
||||||
rl := h.Cursor.RuneUnder(h.Cursor.X - 1)
|
rl := h.Cursor.RuneUnder(h.Cursor.X - 1)
|
||||||
if r == bp[0] || r == bp[1] || rl == bp[0] || rl == bp[1] {
|
if r == bp[0] || r == bp[1] || rl == bp[0] || rl == bp[1] {
|
||||||
matchingBrace, left := h.Buf.FindMatchingBrace(bp, h.Cursor.Loc)
|
matchingBrace, left, found := h.Buf.FindMatchingBrace(bp, h.Cursor.Loc)
|
||||||
if left {
|
if found {
|
||||||
h.Cursor.GotoLoc(matchingBrace)
|
if left {
|
||||||
|
h.Cursor.GotoLoc(matchingBrace)
|
||||||
|
} else {
|
||||||
|
h.Cursor.GotoLoc(matchingBrace.Move(1, h.Buf))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
h.Cursor.GotoLoc(matchingBrace.Move(1, h.Buf))
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -821,7 +821,7 @@ var BracePairs = [][2]rune{
|
|||||||
// returns the location of the matching brace
|
// returns the location of the matching brace
|
||||||
// if the boolean returned is true then the original matching brace is one character left
|
// if the boolean returned is true then the original matching brace is one character left
|
||||||
// of the starting location
|
// of the starting location
|
||||||
func (b *Buffer) FindMatchingBrace(braceType [2]rune, start Loc) (Loc, bool) {
|
func (b *Buffer) FindMatchingBrace(braceType [2]rune, start Loc) (Loc, bool, bool) {
|
||||||
curLine := []rune(string(b.LineBytes(start.Y)))
|
curLine := []rune(string(b.LineBytes(start.Y)))
|
||||||
startChar := ' '
|
startChar := ' '
|
||||||
if start.X >= 0 && start.X < len(curLine) {
|
if start.X >= 0 && start.X < len(curLine) {
|
||||||
@@ -851,9 +851,9 @@ func (b *Buffer) FindMatchingBrace(braceType [2]rune, start Loc) (Loc, bool) {
|
|||||||
i--
|
i--
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if startChar == braceType[0] {
|
if startChar == braceType[0] {
|
||||||
return Loc{x, y}, false
|
return Loc{x, y}, false, true
|
||||||
}
|
}
|
||||||
return Loc{x, y}, true
|
return Loc{x, y}, true, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -875,9 +875,9 @@ func (b *Buffer) FindMatchingBrace(braceType [2]rune, start Loc) (Loc, bool) {
|
|||||||
i--
|
i--
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if leftChar == braceType[1] {
|
if leftChar == braceType[1] {
|
||||||
return Loc{x, y}, true
|
return Loc{x, y}, true, true
|
||||||
}
|
}
|
||||||
return Loc{x, y}, false
|
return Loc{x, y}, false, true
|
||||||
}
|
}
|
||||||
} else if r == braceType[1] {
|
} else if r == braceType[1] {
|
||||||
i++
|
i++
|
||||||
@@ -885,7 +885,7 @@ func (b *Buffer) FindMatchingBrace(braceType [2]rune, start Loc) (Loc, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return start, true
|
return start, true, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retab changes all tabs to spaces or vice versa
|
// Retab changes all tabs to spaces or vice versa
|
||||||
|
|||||||
@@ -452,12 +452,14 @@ func (w *BufWindow) displayBuffer() {
|
|||||||
r := c.RuneUnder(curX)
|
r := c.RuneUnder(curX)
|
||||||
rl := c.RuneUnder(curX - 1)
|
rl := c.RuneUnder(curX - 1)
|
||||||
if r == bp[0] || r == bp[1] || rl == bp[0] || rl == bp[1] {
|
if r == bp[0] || r == bp[1] || rl == bp[0] || rl == bp[1] {
|
||||||
mb, left := b.FindMatchingBrace(bp, curLoc)
|
mb, left, found := b.FindMatchingBrace(bp, curLoc)
|
||||||
matchingBraces = append(matchingBraces, mb)
|
if found {
|
||||||
if !left {
|
matchingBraces = append(matchingBraces, mb)
|
||||||
matchingBraces = append(matchingBraces, curLoc)
|
if !left {
|
||||||
} else {
|
matchingBraces = append(matchingBraces, curLoc)
|
||||||
matchingBraces = append(matchingBraces, curLoc.Move(-1, b))
|
} else {
|
||||||
|
matchingBraces = append(matchingBraces, curLoc.Move(-1, b))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user