This commit is contained in:
Benedikt Stebner 2022-03-11 06:44:07 +01:00
Родитель 19dc0f3bcb
Коммит 48ca598e0e
6 изменённых файлов: 53 добавлений и 20 удалений

Просмотреть файл

@ -2,7 +2,7 @@
<PropertyGroup>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AvaloniaVersion>0.10.999-cibuild0019161-beta</AvaloniaVersion>
<AvaloniaVersion>0.10.999-cibuild0019182-beta</AvaloniaVersion>
<TextMateSharpVersion>1.0.31</TextMateSharpVersion>
<NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
<Version>0.10.12.2</Version>

Просмотреть файл

@ -4,5 +4,6 @@
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="AvaloniaCI" value="https://nuget.avaloniaui.net/repository/avalonia-all/index.json" />
<add key="CI Feed" value="https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json" />
</packageSources>
</configuration>

Просмотреть файл

@ -20,6 +20,7 @@ using System;
using Avalonia;
using Avalonia.Media;
using Avalonia.Media.TextFormatting;
using Avalonia.Utilities;
using AvaloniaEdit.Utils;
using JetBrains.Annotations;
@ -93,8 +94,7 @@ namespace AvaloniaEdit.Rendering
defaultTextRunProperties = properties,
textWrapping = TextWrapping.NoWrap,
tabSize = 40
},
null);
});
}
}
@ -112,6 +112,8 @@ namespace AvaloniaEdit.Rendering
throw new ArgumentNullException(nameof(properties));
Properties = properties;
Element = element ?? throw new ArgumentNullException(nameof(element));
Text = new ReadOnlySlice<char>(new string(' ', element.VisualLength).AsMemory(), element.RelativeTextOffset,
element.VisualLength);
}
/// <summary>
@ -119,6 +121,8 @@ namespace AvaloniaEdit.Rendering
/// </summary>
public FormattedTextElement Element { get; }
public override ReadOnlySlice<char> Text { get; }
/// <inheritdoc/>
public override TextRunProperties Properties { get; }

Просмотреть файл

@ -22,6 +22,7 @@ using Avalonia;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using Avalonia.Media.TextFormatting;
using Avalonia.Utilities;
using AvaloniaEdit.Document;
using AvaloniaEdit.Utils;
using LogicalDirection = AvaloniaEdit.Document.LogicalDirection;
@ -153,7 +154,7 @@ namespace AvaloniaEdit.Rendering
if (startVisualColumn == VisualColumn)
return new TabGlyphRun(this, TextRunProperties);
else if (startVisualColumn == VisualColumn + 1)
return new TextCharacters("\t".AsMemory(), 0, 1, TextRunProperties);
return new TextCharacters(new ReadOnlySlice<char>("\t".AsMemory(), RelativeTextOffset, 1), TextRunProperties);
else
throw new ArgumentOutOfRangeException(nameof(startVisualColumn));
}

Просмотреть файл

@ -156,15 +156,16 @@ namespace AvaloniaEdit.Rendering
void PerformVisualElementConstruction(VisualLineElementGenerator[] generators)
{
TextDocument document = this.Document;
int offset = FirstDocumentLine.Offset;
int currentLineEnd = offset + FirstDocumentLine.Length;
var lineLength = FirstDocumentLine.Length;
var offset = FirstDocumentLine.Offset;
var currentLineEnd = offset + lineLength;
LastDocumentLine = FirstDocumentLine;
int askInterestOffset = 0; // 0 or 1
var askInterestOffset = 0; // 0 or 1
while (offset + askInterestOffset <= currentLineEnd) {
int textPieceEndOffset = currentLineEnd;
foreach (VisualLineElementGenerator g in generators) {
g.CachedInterest = g.GetFirstInterestedOffset(offset + askInterestOffset);
var textPieceEndOffset = currentLineEnd;
foreach (var g in generators) {
g.CachedInterest = (lineLength > LENGTH_LIMIT) ? -1: g.GetFirstInterestedOffset(offset + askInterestOffset);
if (g.CachedInterest != -1) {
if (g.CachedInterest < offset)
throw new ArgumentOutOfRangeException(g.GetType().Name + ".GetFirstInterestedOffset",
@ -176,16 +177,33 @@ namespace AvaloniaEdit.Rendering
}
Debug.Assert(textPieceEndOffset >= offset);
if (textPieceEndOffset > offset) {
int textPieceLength = textPieceEndOffset - offset;
_elements.Add(new VisualLineText(this, textPieceLength));
var textPieceLength = textPieceEndOffset - offset;
int remaining = textPieceLength;
while (true)
{
if (remaining > LENGTH_LIMIT)
{
// split in chunks of LENGTH_LIMIT
_elements.Add(new VisualLineText(this, LENGTH_LIMIT));
remaining -= LENGTH_LIMIT;
}
else
{
_elements.Add(new VisualLineText(this, remaining));
break;
}
}
offset = textPieceEndOffset;
}
// If no elements constructed / only zero-length elements constructed:
// do not asking the generators again for the same location (would cause endless loop)
askInterestOffset = 1;
foreach (VisualLineElementGenerator g in generators) {
foreach (var g in generators) {
if (g.CachedInterest == offset) {
VisualLineElement element = g.ConstructElement(offset);
var element = g.ConstructElement(offset);
if (element != null) {
_elements.Add(element);
if (element.DocumentLength > 0) {
@ -193,7 +211,7 @@ namespace AvaloniaEdit.Rendering
askInterestOffset = 0;
offset += element.DocumentLength;
if (offset > currentLineEnd) {
DocumentLine newEndLine = document.GetLineByOffset(offset);
var newEndLine = Document.GetLineByOffset(offset);
currentLineEnd = newEndLine.Offset + newEndLine.Length;
this.LastDocumentLine = newEndLine;
if (currentLineEnd < offset) {

Просмотреть файл

@ -62,9 +62,16 @@ namespace AvaloniaEdit.Rendering
throw new ArgumentNullException(nameof(context));
var relativeOffset = startVisualColumn - VisualColumn;
var offset = context.VisualLine.FirstDocumentLine.Offset + RelativeTextOffset + relativeOffset;
var text = context.GetText(
offset,
DocumentLength - relativeOffset);
StringSegment text = context.GetText(context.VisualLine.FirstDocumentLine.Offset + RelativeTextOffset + relativeOffset, DocumentLength - relativeOffset);
return new TextCharacters(new ReadOnlySlice<char>(text.Text.AsMemory(), text.Offset, text.Count), this.TextRunProperties);
return new TextCharacters(
new ReadOnlySlice<char>(text.Text.AsMemory(), RelativeTextOffset, text.Count,
text.Offset), TextRunProperties);
}
/// <inheritdoc/>
@ -80,8 +87,10 @@ namespace AvaloniaEdit.Rendering
if (context == null)
throw new ArgumentNullException(nameof(context));
int relativeOffset = visualColumnLimit - VisualColumn;
StringSegment text = context.GetText(context.VisualLine.FirstDocumentLine.Offset + RelativeTextOffset, relativeOffset);
var relativeOffset = visualColumnLimit - VisualColumn;
var text = context.GetText(context.VisualLine.FirstDocumentLine.Offset + RelativeTextOffset, relativeOffset);
return new ReadOnlySlice<char>(text.Text.AsMemory(), text.Offset, text.Count);
}