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

✨ Emphasis API for Highlighting Text Ranges #62

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tom-ludwig
Copy link
Member

Description

This PR introduces the Emphasis API to highlight specific text ranges within a TextView. This functionality can be used in various scenarios, such as highlighting search results, emphasizing code symbols, or highlighting the code symbol that the mouse is hovering over.
This PR only introduces the Emphasis API and does not include any search functionality or text-range validation (e.g., checking if an already emphasized range has changed).

Note

To test the UI changes, you will likely need to use CESE and add CETE as a local package.
To experiment with the highlighting, add the following snippet to TextView+KeyDown at line 13 and change the ranges accordingly:

        let rangesToHighlight = [
            NSRange(location: 562, length: 7),
            NSRange(location: 651, length: 7),
            NSRange(location: 724, length: 7),
        ]

        if event.keyCode == kVK_F1 {
            emphasizeAPI?.emphasizeRanges(ranges: rangesToHighlight, activeIndex: 0)
            return
        }

        if event.keyCode == kVK_F2 {
            emphasizeAPI?.highlightNext()
            return
        }
        if event.keyCode == kVK_F3 {
            emphasizeAPI?.highlightPrevious()
            return
        }
        if event.keyCode == kVK_F4 {
            emphasizeAPI?.removeEmphasizeLayers()
            return
        }

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

Screen.Recording.2024-11-25.at.8.46.32.PM.mov

Multiline:
Screenshot 2024-11-28 at 12 12 54 PM

Screenshot 2024-11-28 at 12 13 10 PM

Copy link
Contributor

@thecoolwinter thecoolwinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a spelling error and a file placement suggestion. That smooth path function is beautiful, awesome stuff.

@austincondiff
Copy link
Contributor

Excellent work @tom-ludwig! It looks really good. Just a small detail—the animation looks a little off. Instead of scaling it, it seems to be translated from below and to the right. Can we fix this?

@tom-ludwig
Copy link
Member Author

@austincondiff Yeah, it’s not what Xcode is using, but honestly, I’m not really a fan of Xcode’s approach. I’ll experiment with the animation to come up with something better.

@austincondiff
Copy link
Contributor

Xcodes approach is a macOS standard found in many other apps. I’d like to first start with it and if we want to, later on adjust as needed.

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.

✨ Emphasis API for Highlighting Text Ranges
3 participants