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

🐞 Text styling and syntax highlighting are very unreliable #162

Closed
nkleemann opened this issue Mar 15, 2023 · 4 comments
Closed

🐞 Text styling and syntax highlighting are very unreliable #162

nkleemann opened this issue Mar 15, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@nkleemann
Copy link

Description

Text styling (both color and font) sometimes won't get applied after pasting, or typing in text.

Sometimes, the styling get's applied when I scroll the EditorView, that's why you can see my scroll a few times in the screen recording. It's not working though..

I say "sometimes" because I can't always reproduce it, and I've found no other correlations. This bug occurs roughly 3 out of 5 times trying to paste, or type, text into the editor view.

This is my EditorTheme (same thing happens with black on white btw, but still):

@State var theme = EditorTheme(
        text: .white,
        insertionPoint: .white,
        invisibles: .gray,
        background: .black,
        lineHighlight: .init(white: 0.2, alpha: 0.6),
        selection: .blue,
        keywords: .systemPink,
        commands: .systemPink,
        types: .systemMint,
        attributes: .systemTeal,
        variables: .systemMint,
        values: .systemOrange,
        numbers: .systemCyan,
        strings: .systemRed,
        characters: .systemRed,
        comments: .systemGreen
)

To Reproduce

  1. Use the basic Example provided in the README
  2. Paste in code blocks, or try to type in text at the bottom of the editor view.

Expected Behavior

Upon entering any text into the editor view it should get processed and styled immediately.

Version Information

CodeEditTextView: 0.4.0
macOS: 13.2.1
Xcode: 14.2 (14C18)

Additional Context

No response

Screenshots

Screen.Recording.2023-03-15.at.22.01.08.mov
@nkleemann nkleemann added the bug Something isn't working label Mar 15, 2023
@nkleemann nkleemann changed the title 🐞 Text styling and syntax highlighting is very unreliable 🐞 Text styling and syntax highlighting are very unreliable Mar 15, 2023
@thecoolwinter
Copy link
Collaborator

From your video it looks like this is the same problem as #142. Can you try copy-pasting something in a document with a lot more text in it? Enough to fill the screen at least.

@nkleemann
Copy link
Author

It's always the same result; and the position the text is pasted into doesn't matter. Sometimes it happens in an empty file, or end of file, sometimes when pasting in-between other blocks of code. Sadly I can't reproduce it, it seems totally stochastic.

Also keep in mind that it's not only pasting - normal text input also often doesn't get highlighted.

I just tried this with the CodeEdit alpha and confirmed it there too.

@lukepistrol lukepistrol moved this from 🆕 New to 📋 Todo in CodeEdit Project Mar 23, 2023
matthijseikelenboom pushed a commit that referenced this issue Apr 4, 2023
<!--- IMPORTANT: If this PR addresses multiple unrelated issues, it will
be closed until separated. -->

### Description

<!--- REQUIRED: Describe what changed in detail -->

This change adds all positive edits to the visible range. The assumption
is that any edits the user may make are going to be visible at some
point in time. If the cursor is not already on the page, it will be
scrolled to and if it extends beyond the viewport it will be scrolled to
be visible as well. In both of those cases the added range will be
overridden immediately due to the scroll. So this fixes the case where
characters are being inserted at the end of a file, but aren't being
scrolled to. This is apparent in the attached screen recordings.

Alternatives considered:
- **Re-calculating the visible set:** Decided against due to the extra
work that would need to be done potentially every keystroke to calculate
a new visible range.
- **Update the visible set only if the edit is actually visible:**
Decided against due to the reasons previously mentioned. Any edit will
eventually be included in the visible set if it is not already in it
when the edit occurs.

### Related Issues

<!--- REQUIRED: Tag all related issues (e.g. * #123) -->
<!--- If this PR resolves the issue please specify (e.g. * closes #123)
-->
<!--- If this PR addresses multiple issues, these issues must be related
to one other -->

* closes #142
* Maybe related to #162

### Checklist

<!--- Add things that are not yet implemented above -->

- [x] I read and understood the [contributing
guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md)
as well as the [code of
conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md)
- [x] The issues this PR addresses are related to each other
- [x] My changes generate no new warnings
- [x] My code builds and runs on my machine
- [x] My changes are all related to the related issue above
- [x] I documented my code

### Screenshots

Before fix. Edits applied to the end of the file are never sent to
tree-sitter for highlighting as they are out of the range of the visible
set. They are only updated when the document is scrolled and
`visibleSet` is recalculated.


https://user-images.githubusercontent.com/35942988/229874599-e2714b72-d51f-4748-89e1-b80ee51bddda.mov

After fix. Edits with positive deltas are always included in the
`visibleSet`.


https://user-images.githubusercontent.com/35942988/229875515-36e96921-71c0-48aa-a62c-75cbd91c52fb.mov


<!--- REQUIRED: if issue is UI related -->

<!--- IMPORTANT: Fill out all required fields. Otherwise we might close
this PR temporarily -->
@thecoolwinter
Copy link
Collaborator

I'd like to look into this further but still can't reproduce it. There's been some large changes to the highlighting system in #150, #171 and #173 specifically that would apply to text pasted into the editor. Before doing more work on this can you confirm it's still an issue for you in the latest CodeEdit version that includes those changes, 0.0.3-alpha-32?

@nkleemann
Copy link
Author

I just bumped my version to 0.6.1 and all issues are resolved for me. Thank you!

@github-project-automation github-project-automation bot moved this from 📋 Todo to 🏁 Complete in CodeEdit Project Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🏁 Complete
Development

No branches or pull requests

2 participants