<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using AvaloniaEdit.Utils;
using Avalonia.Media;

namespace AvaloniaEdit.Text
{
    internal sealed class TextLineImpl : TextLine
    {
        private const int MaxCharactersPerLine = 10000;

        private readonly TextLineRun[] _runs;

        public override int FirstIndex { get; }

        public override int Length { get; }

        public override int TrailingWhitespaceLength { get; }

        public override double Width { get; }

        public override double WidthIncludingTrailingWhitespace { get; }

        public override double Height { get; }

        public override double Baseline { get; }

        internal static TextLineImpl Create(TextParagraphProperties paragraphProperties, int firstIndex, int paragraphLength, TextSource textSource)
        {
            var index = firstIndex;
            var visibleLength = 0;
            var widthLeft = paragraphLength > 0 ? paragraphLength : double.MaxValue;
            TextLineRun prevRun = null;
            var run = TextLineRun.Create(textSource, index, firstIndex, widthLeft);
            if (!run.IsEnd && run.Width <= widthLeft)
            {
                index += run.Length;
                widthLeft -= run.Width;
                prevRun = run;
                run = TextLineRun.Create(textSource, index, firstIndex, widthLeft);
            }<commit_msg>Fix wrapping bug<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using AvaloniaEdit.Utils;
using Avalonia.Media;

namespace AvaloniaEdit.Text
{
    internal sealed class TextLineImpl : TextLine
    {
        private const int MaxCharactersPerLine = 10000;

        private readonly TextLineRun[] _runs;

        public override int FirstIndex { get; }

        public override int Length { get; }

        public override int TrailingWhitespaceLength { get; }

        public override double Width { get; }

        public override double WidthIncludingTrailingWhitespace { get; }

        public override double Height { get; }

        public override double Baseline { get; }

        internal static TextLineImpl Create(TextParagraphProperties paragraphProperties, int firstIndex, int paragraphLength, TextSource textSource)
        {
            var index = firstIndex;
            var visibleLength = 0;
            var widthLeft = paragraphProperties.TextWrapping == TextWrapping.Wrap && paragraphLength > 0 ? paragraphLength : double.MaxValue;
            TextLineRun prevRun = null;
            var run = TextLineRun.Create(textSource, index, firstIndex, widthLeft);
            if (!run.IsEnd && run.Width <= widthLeft)
            {
                index += run.Length;
                widthLeft -= run.Width;
                prevRun = run;
                run = TextLineRun.Create(textSource, index, firstIndex, widthLeft);
            }
{'fraction_non_alphanumeric': 0.06952965235173825, 'fraction_numerical': 0.004771642808452625, 'mean_word_length': 2.424737456242707, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2217331', 'n_tokens_mistral': 761, 'n_tokens_neox': 712, 'n_words': 224}