CodeEditApp / CodeEditSourceEditor

A code editor view written in Swift powered by tree-sitter.
https://codeeditapp.github.io/CodeEditSourceEditor/documentation/codeeditsourceeditor
MIT License
504 stars 74 forks source link

Add range check to `highlightsFromCursor` #187

Closed thecoolwinter closed 1 year ago

thecoolwinter commented 1 year ago

Description

Fixes a bug found found by @cengelbart39 on discord where a parser would consume ranges already consumed by injected languages. This caused the injected ranges to be realized as plain text, when they should have been kept as their injected language's highlights.

This should have been avoided by the call to query.setRange(range) on line 43 in TreeSitterClient+Highlight.swift but it was found that for some reason in the case found by @cengelbart39 it just didn't work.

To fix, an additional check was added in highlightsFromCursor to only take any ranges that have indices in the intersection of it's range and the included range.

Related Issues

Checklist

Screenshots

Before:

https://user-images.githubusercontent.com/35942988/236696171-d30dfd7b-8545-4396-8aa8-490ceac65551.mov

After:

https://user-images.githubusercontent.com/35942988/236697575-3f605c0d-3dda-45c2-8f69-0f41148f1c2d.mov

thecoolwinter commented 1 year ago

The build error will be fixed when #186 is merged.

thecoolwinter commented 1 year ago

@austincondiff thanks! Just waiting for #186 to pin the STTextView version to fix the build error and this should be mergable.