(fix: #9) Grayscale Selection When Not Focused#16
Merged
thecoolwinter merged 1 commit intoCodeEditApp:mainfrom Feb 5, 2024
Merged
(fix: #9) Grayscale Selection When Not Focused#16thecoolwinter merged 1 commit intoCodeEditApp:mainfrom
thecoolwinter merged 1 commit intoCodeEditApp:mainfrom
Conversation
tom-ludwig
approved these changes
Feb 5, 2024
Member
tom-ludwig
left a comment
There was a problem hiding this comment.
Cool, love this little detail!
LeoBorai
pushed a commit
that referenced
this pull request
Feb 12, 2024
# 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">
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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