Skip to content

Conversation

@thecoolwinter
Copy link
Collaborator

@thecoolwinter thecoolwinter commented May 3, 2023

Description

Implements bracket/pair highlighting as described in #67. Adds a few functions to STTextViewController:

  • highlightSelectionPairs()
    • Highlights selection pairs from the current selection. This is called whenever the selection is updated and handles determining whether or not the selection highlight should be applied. It makes use of findClosingPair(_ close: String, _ open: String, from: Int, limit: Int, reverse: Bool) -> Int? to determine the indices of the opening and closing pairs.
  • highlightRange(_ range: NSTextRange, scrollToRange: Bool = false)
    • Applies a highlight to the given range, determined by the bracketPairHighlight property. Also handles removing animated layers if needed (as in the case of the flash highlight type).

There are two highlight types:

  • Flash: Flashes a yellow rectangle below the given range with an animation. The highlight disappears after 0.75s. This is modeled closely to the Xcode version.
  • Bordered: Adds a border around both the opening and closing bracket pair. These borders only disappear when the selection changes.
  • Underline: Adds an underline to both the opening and closing bracket pair. These borders only disappear when the selection changes.
    All highlight types are documented in the BracketPairHighlight enum.

Highlighted pairs are the same set of pairs used for the pair autocomplete filter:

  • { }
  • [ ]
  • < >
  • ( )

This feature can also be disabled by setting the bracketPairHighlight property on CodeEditTextView to nil.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

Box highlight:
Screenshot 2023-05-07 at 8 07 11 PM

Flash highlight:

Screen.Recording.2023-05-03.at.4.43.10.PM.mov

Underline highlight with red color:

Screenshot 2023-05-08 at 2 15 27 PM

@austincondiff
Copy link
Collaborator

@thecoolwinter can we add a 2.5 corner radius for the box highlight?

@thecoolwinter
Copy link
Collaborator Author

Yes that would be easy to do quick, I'll do that rq.

@thecoolwinter thecoolwinter changed the title Implement Brace Pair Highlighting Implement Bracket Pair Highlighting May 8, 2023
@austincondiff
Copy link
Collaborator

@thecoolwinter Regarding the underline variant. I think I would attach the underline to the bottom of the character instead of the bottom of the line. If the user has a large line height value this underline could be farther away from the character than desired.

@thecoolwinter
Copy link
Collaborator Author

@austincondiff Updated to reflect that change.

@thecoolwinter thecoolwinter merged commit b60e0fc into CodeEditApp:main May 8, 2023
@thecoolwinter thecoolwinter deleted the feat/brace-pair-highlight branch July 12, 2023 16:27
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.

✨ Matching Tag/Bracket Highlighting

2 participants