-
Notifications
You must be signed in to change notification settings - Fork 12
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
(fix: #9) Grayscale Selection When Not Focused #16
(fix: #9) Grayscale Selection When Not Focused #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, love this little detail!
# Description This PR adds support for injected languages using tree-sitter as described in #16 and in the [tree-sitter documentation](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#language-injection). Languages can contain _injected_ languages which are described in a language's `injections.scm` file. Some examples of injected languages are: - HTML contains CSS and Javascript in `style` and `script` tags - Javascript contains Regex literals - PHP contains HTML between the `<php` tags - C++ can contain rawstring literals of arbitrary languages # Details This PR is a rework of the `TreeSitterClient` class. Specifically it: - Adds a `layers` array and `primaryLayer` property. `layers` contains all language layers in the document, and `primaryLayer` is the ID of the document's primary language. - Each layer is a `LanguageLayer` object. These objects represent an injected language-range(s) combination. Each layer can have one or more range associated with it depending on if it should be [parsed as one document or multiple](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#language-injection). - When editing: - Each layer's ranges are updated using a similar algorithm to tree-sitter, and edits are applied to make use of the incremental parsing tree-sitter gives. - Each layer is checked for any injections, inserting any new injected layers and keeping track of any 'untouched' layers to remove. - Any layers that were not touched are removed. The highlight query algorithm is largely the same, but keeps track of any ranges not used by any injected layers, and only queries the primary layer for those ranges so as not to override any injected highlights. # Related Issues - Closes #16 # Screenshots Before, other languages were detected but parsed and highlighted as normal text. <img width="1104" alt="Screenshot 2023-02-28 at 3 08 52 PM" src="https://user-images.githubusercontent.com/35942988/221980502-3aa61b6a-136a-43b9-a545-8fd835945002.png"> With Injected languages, in this case CSS and JS embedded in HTML and a second layer of Regex embedded in JS embedded in HTML: <img width="889" alt="Screenshot 2023-03-24 at 2 45 15 PM" src="https://user-images.githubusercontent.com/35942988/227628557-df55d986-a104-4a24-ab6c-97c8e69f6136.png">
Description
Finishes #9, correctly changing selection highlights when the view is not focused. Similar to other MacOS controls, the selection color is simply made grayscale when not focused.
Related Issues
Checklist
Screenshots
Screen.Recording.2024-02-03.at.12.48.35.AM.mov