mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-17 14:27:12 +09:00
Add matchbraceleft option (#3432)
Add `matchbraceleft` option to allow disabling the default behavior matching not just the brace under cursor but also the brace to the left of it (which is arguably convenient, but also ambiguous and non-intuitive). With `matchbraceleft` disabled, micro will only match the brace character that is precisely under the cursor, and also when jumping to the matching brace, will always move cursor precisely to the matching brace character, not to the character next to it. Nota bene: historical journey: - There was already a `matchbraceleft` option introduced in commitea6a87d41a, when this feature (matching brace to the left) was introduced first time. That time it was matching _only_ the brace to the left, _instead_ of the brace under the cursor, and was disabled by default. - Later this feature was removed during the big refactoring of micro. - Then this feature was reintroduced again in commitd1e713ce08, in its present form (i.e. combined brace matching both under the cursor and to the left, simulating I-beam cursor behavior), and it was introduced unconditionally, without an option to disable it. - Since then, multiple users complained about this feature and asked for an option to disable it, so now we are reintroducing it as an option again (this time enabled by default though).
This commit is contained in:
@@ -1193,17 +1193,19 @@ func (b *Buffer) FindMatchingBrace(start Loc) (Loc, bool, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// failed to find matching brace for the given location, so try to find matching
|
||||
// brace for the location one character left of it
|
||||
if start.X-1 >= 0 && start.X-1 < len(curLine) {
|
||||
leftChar := curLine[start.X-1]
|
||||
left := Loc{start.X - 1, start.Y}
|
||||
if b.Settings["matchbraceleft"].(bool) {
|
||||
// failed to find matching brace for the given location, so try to find matching
|
||||
// brace for the location one character left of it
|
||||
if start.X-1 >= 0 && start.X-1 < len(curLine) {
|
||||
leftChar := curLine[start.X-1]
|
||||
left := Loc{start.X - 1, start.Y}
|
||||
|
||||
for _, bp := range BracePairs {
|
||||
if leftChar == bp[0] || leftChar == bp[1] {
|
||||
mb, found := b.findMatchingBrace(bp, left, leftChar)
|
||||
if found {
|
||||
return mb, true, true
|
||||
for _, bp := range BracePairs {
|
||||
if leftChar == bp[0] || leftChar == bp[1] {
|
||||
mb, found := b.findMatchingBrace(bp, left, leftChar)
|
||||
if found {
|
||||
return mb, true, true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user