Skip to content

Get token on position #408

Closed Answered by NickRimmer
NickRimmer asked this question in Q&A
Mar 29, 2024 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

There is solution for current version of AvaloniaEdit

public static TextMateTokenModel? GetCaretToken(this TextMate.Installation textMateInstallation, TextEditor editor) =>
    textMateInstallation.GetToken(editor.TextArea.Caret.Line - 1, editor.TextArea.Caret.Column - 1);

public static TextMateTokenModel? GetToken(this TextMate.Installation textMateInstallation, int lineIndex, int columnIndex)
{
    var line = textMateInstallation?
        .EditorModel?
        .Get(lineIndex);
    if (line == null) return null;

    var tokens = line
        .Tokens?
        .OrderBy(x => x.StartIndex)
        .ToList();
    if (tokens is not { Count: > 0 }) return null;

    var text = textMateInstall…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@NickRimmer
Comment options

Answer selected by NickRimmer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant