-
Notifications
You must be signed in to change notification settings - Fork 154
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
Add token scopes to TextRunProperties #409
Add token scopes to TextRunProperties #409
Conversation
I don't think it's a good idea to set the TextMate tokens scopes in the VisualLines since the TextMate integration is optional and also for duplicating the in memory. Probably would be better to enable some API in the TextMate installation to get the tokens for a certain offset. |
The line tokens are available here:
|
Hm... yeah, let me think a bit. We can have just some extra dictionary with whatever here. But I'm surprised that TextMate is optional, as all examples and purpose of editor in general is syntax highlighting (; |
The idea to reuse tokens already calculated for text we showing in editor. Otherwise I can just get line/column indexes, load grammar and just calculate it again |
TextMate is implemented as a plugin so the installation is optional and the dependencies are inverted (AvaloniaEdit doesn't know about TextMate so it doesn't make sense storing textmate tokens in the VisualLine) |
Yep, I agree, absolutely make sense |
I'm opened for ideas (: I still think this is not a bad to store information in visual line, as it part of visual properties. And it easier to manage it here. Bur probably it should be as extra attributes, for whatever values can be read by anyone, not specifically TextMate |
I think that what you need is just exposing the TMModel here as a public property:
Then, when the caret changes just access the TextMate installation and then access the TMModel to get the current line tokens and get the scopes from there. |
5c9ae2c
to
62b8790
Compare
Thank you so much for your help, very appreciate it. Well, what I found, we don't even need to change anything in code ^^" This code return already scopes: var scopes = _textMateInstallation
.EditorModel
.Get(_textEditor.TextArea.Caret.Line - 1)
.Tokens
.OrderBy(x => x.StartIndex)
.LastOrDefault(x => x.StartIndex <= _textEditor.TextArea.Caret.Column - 1)?
.Scopes ?? new List<string>(); So, I pushed small changes to get it a bit easier from |
I put solution here |
Hey, I didn't find how to get token scopes in editor. So there is an idea (;
During text decorating with
TextTransformation
, we already have token information here. So, we only need to include details to elementTextRunProperties
which we can read later whenever we need.I didn't add any special method to read scopes, I use existing element properties: