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

ctrl+x (cutting) on a very big file crashes #9

Closed
mrexodia opened this issue Jul 8, 2017 · 2 comments
Closed

ctrl+x (cutting) on a very big file crashes #9

mrexodia opened this issue Jul 8, 2017 · 2 comments
Labels

Comments

@mrexodia
Copy link

mrexodia commented Jul 8, 2017

If you type string x = @" and then paste some very big multi-line text, then ctrl+a and ctrl+x it will crash inside UpdateHighlightLineAsync

Here is my workaround, but I don't understand the code so I didn't send a pull request:

        private async void UpdateHighlightLineAsync(VersionedHighlightedLine line)
        {
            try //added to catch a deleted documentLine
            {
                await Task.Run(async () =>
                {
                    await initialDelayTask.ConfigureAwait(false);
                    line.CancellationToken.ThrowIfCancellationRequested();

                    var documentLine = line.DocumentLine;
                    var currentVersion = Document.Version;
                    if (line.Version == null || !currentVersion.BelongsToSameDocumentAs(line.Version) || currentVersion.CompareAge(line.Version) != 0)
                    {
                        return;
                    }
                    var spans = await GetClassifiedSpansAsync(documentLine, line.CancellationToken).ConfigureAwait(false);
                    line.CancellationToken.ThrowIfCancellationRequested();

                    await TaskHelper.Run(() =>
                    {
                        try
                        {
                            if (line.CancellationToken.IsCancellationRequested)
                            {
                                return;
                            }

                            var newLineSections = new List<HighlightedSection>();
                            foreach (var classifiedSpan in spans)
                            {
                                if (IsOutsideLine(documentLine, classifiedSpan.TextSpan.Start, classifiedSpan.TextSpan.Length))
                                {
                                    continue;
                                }
                                newLineSections.Add(new HighlightedSection
                                {
                                    Color = CodeHighlightColors.GetHighlightingColor(classifiedSpan.ClassificationType),
                                    Offset = classifiedSpan.TextSpan.Start,
                                    Length = classifiedSpan.TextSpan.Length
                                });
                            }
                            if (!line.Sections.SequenceEqual(newLineSections, HighlightedSectionComparer.Default))
                            {
                                line.Sections.Clear();
                                foreach (var newSection in newLineSections) { line.Sections.Add(newSection); }
                                try
                                {
                                    HighlightingStateChanged?.Invoke(documentLine.LineNumber, documentLine.LineNumber);
                                }
                                catch (ArgumentOutOfRangeException) //this was the second exception, just swallow
                                {
                                }
                            }
                        }
                        catch(InvalidOperationException)
                        {
                            if (!documentLine.IsDeleted) //don't throw if the line is deleted
                                throw;
                        }
                    }, uiTaskScheduler).ConfigureAwait(false);
                }, line.CancellationToken);
            }
            catch (OperationCanceledException) { }
        }
@jbe2277
Copy link
Owner

jbe2277 commented Jul 11, 2017

Thank you for the feedback. I'm able to reproduce the issue.

@jbe2277 jbe2277 added the bug label Jul 11, 2017
@jbe2277
Copy link
Owner

jbe2277 commented Aug 10, 2017

Fixed in v2.4.1.

@jbe2277 jbe2277 closed this as completed Aug 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants