Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve FindMatchingBrace() interface and implementation #3319

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

dmaluka
Copy link
Collaborator

@dmaluka dmaluka commented May 26, 2024

Rework FindMatchingBrace() interface and implementation: instead of passing a single brace pair to FindMatchingBrace(), make it traverse all brace pairs in buffer.BracePairs on its own.

This has the following advantages:

  1. Makes FindMatchingBrace() easier to use, in particular much easier to use from Lua. See JumpToMatchingBrace inconsistent with adjacent unpaired braces e.g. )[ or }( or )( #3308)

  2. Lets FindMatchingBrace() ensure that we use just one matching brace - the higher-priority one. This fixes the following issues (first found in options: add matchbracestyle #2876 (comment)):

    ([foo]bar)
     ^

when the cursor is on [:

  • Both [] and () pairs are highlighted, whereas the expected behavior is that only one pair is highlighted - the one that has higher priority, i.e. the one the JumpToMatchingBrace action would jump to.

  • JumpToMatchingBrace incorrectly jumps to ) instead of ] (which should take higher priority in this case).

In contrast, with ((foo)bar) it works correctly.

Instead of passing a single brace pair to FindMatchingBrace(), make it
traverse all brace pairs in buffer.BracePairs on its own.

This has the following advantages:

1. Makes FindMatchingBrace() easier to use, in particular much easier
   to use from Lua.

2. Lets FindMatchingBrace() ensure that we use just one matching brace -
   the higher-priority one. This fixes the following issues:

    ([foo]bar)
     ^

when the cursor is on `[`:

- Both `[]` and `()` pairs are highlighted, whereas the expected
  behavior is that only one pair is highlighted - the one that the
  JumpToMatchingBrace action would jump to.

- JumpToMatchingBrace action incorrectly jumps to `)` instead of
  `]` (which should take higher priority in this case).

In contrast, with `((foo)bar)` it works correctly.
@dmaluka dmaluka merged commit 9eb8782 into zyedidia:master Jun 4, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants