Skip to content

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 force-pushed the findmatchingbrace-rework branch from fe87b26 to 8632471 Compare May 26, 2024 15:15
@dmaluka dmaluka merged commit 9eb8782 into micro-editor:master Jun 4, 2024
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.

2 participants