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

(fix: #9) Grayscale Selection When Not Focused #16

Merged

Conversation

thecoolwinter
Copy link
Contributor

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

  • 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-02-03.at.12.48.35.AM.mov

Copy link

@0xWDG 0xWDG left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@avdept avdept left a comment

Choose a reason for hiding this comment

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

Lgtm

Copy link
Member

@tom-ludwig tom-ludwig left a 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!

@thecoolwinter thecoolwinter merged commit cf4ee3b into CodeEditApp:main Feb 5, 2024
2 checks passed
EstebanBorai 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">
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.

🐞 Text view does not handle inactive state
5 participants