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

ScrollTo() - when First loading a Document, has difficulty scrolling to #469

Open
Natestah opened this issue Nov 11, 2024 · 2 comments
Open

Comments

@Natestah
Copy link
Contributor

I have this gnarly little bit of code in Blitz Search with a Todo Note to bug AvaloniaEdit about it..

I have noticed ScrollTo not resolving if I set the text document, and immediately follow up with calling scroll to.

        //I don't like this, Maybe we can work it into AvaloniaEdit itself "Load a document and center it on this line when things are finished"
        for (int i = 0; i < 2; i++)
        {
            AvaloniaTextEditor.ScrollTo(lineNumer, 1);

            try
            {
                var line = AvaloniaTextEditor.Document.GetLineByNumber(lineNumer);
                AvaloniaTextEditor.CaretOffset = line.Offset + column;
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine(e);
                break;
            }

            try
            {
                await Task.Delay(50,_currentToken.Token);
            }
            catch (OperationCanceledException)
            {
                return;
            }
            if (_currentToken.IsCancellationRequested)
            {
                break;
            }
        }
        AvaloniaTextEditor.TextArea.TextView.Redraw();
    }
@danipen
Copy link
Collaborator

danipen commented Nov 11, 2024

Probably you need to post setting the caret offset I to the Avalonia dispatcher to wait until the layout has finished and visual lines have been generated.

@Natestah
Copy link
Contributor Author

I'm somewhat familiar with the inner workings, but I am hoping to get some way to have to be less smart about that on the Editor itself. Can it do that automatically?

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

No branches or pull requests

2 participants