diff --git a/internal/action/actions.go b/internal/action/actions.go index c0f4aead..cdce96d9 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1472,10 +1472,14 @@ func (h *BufPane) paste(clip string) { func (h *BufPane) JumpToMatchingBrace() bool { matchingBrace, left, found := h.Buf.FindMatchingBrace(h.Cursor.Loc) if found { - if left { - h.Cursor.GotoLoc(matchingBrace) + if h.Buf.Settings["matchbraceleft"].(bool) { + if left { + h.Cursor.GotoLoc(matchingBrace) + } else { + h.Cursor.GotoLoc(matchingBrace.Move(1, h.Buf)) + } } else { - h.Cursor.GotoLoc(matchingBrace.Move(1, h.Buf)) + h.Cursor.GotoLoc(matchingBrace) } h.Relocate() return true diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 3073eba0..15cfe335 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -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 + } } } } diff --git a/internal/config/settings.go b/internal/config/settings.go index 78874ed6..d25f0d07 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -71,6 +71,7 @@ var defaultCommonSettings = map[string]interface{}{ "indentchar": " ", "keepautoindent": false, "matchbrace": true, + "matchbraceleft": true, "matchbracestyle": "underline", "mkparents": false, "permbackup": false, diff --git a/runtime/help/options.md b/runtime/help/options.md index 32375833..ff781834 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -231,7 +231,19 @@ Here are the available options: default value: `false` * `matchbrace`: show matching braces for '()', '{}', '[]' when the cursor - is on a brace character or next to it. + is on a brace character or (if `matchbraceleft` is enabled) next to it. + + default value: `true` + +* `matchbraceleft`: simulate I-beam cursor behavior (cursor located not on a + character but "between" characters): when showing matching braces, if there + is no brace character directly under the cursor, match the brace character + to the left of the cursor instead. Also when jumping to the matching brace, + move the cursor either to the matching brace character or to the character + next to it, depending on whether the initial cursor position was on the + brace character or next to it (i.e. "inside" or "outside" the braces). + With `matchbraceleft` disabled, micro will only match the brace directly + under the cursor and will only jump to precisely to the matching brace. default value: `true` @@ -526,6 +538,7 @@ so that you can see what the formatting should look like. "linter": true, "literate": true, "matchbrace": true, + "matchbraceleft": true, "matchbracestyle": "underline", "mkparents": false, "mouse": true,