Pass a dictionary with the color map instead an interface

This commit is contained in:
Daniel 2023-09-26 13:20:54 +02:00
Родитель 2a07c6ea07
Коммит 228bb5e4f0
2 изменённых файлов: 20 добавлений и 24 удалений

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

@ -17,8 +17,7 @@ namespace AvaloniaEdit.TextMate
{
public class TextMateColoringTransformer :
GenericLineTransformer,
IModelTokensChangedListener,
ForegroundTextTransformation.IColorMap
IModelTokensChangedListener
{
private Theme _theme;
private IGrammar _grammar;
@ -77,6 +76,7 @@ namespace AvaloniaEdit.TextMate
public void Dispose()
{
_textView.VisualLinesChanged -= TextView_VisualLinesChanged;
_brushes.Clear();
}
public void SetTheme(Theme theme)
@ -105,15 +105,6 @@ namespace AvaloniaEdit.TextMate
}
}
IBrush ForegroundTextTransformation.IColorMap.GetBrush(int colorId)
{
if (_brushes == null)
return null;
_brushes.TryGetValue(colorId, out IBrush result);
return result;
}
protected override void TransformLine(DocumentLine line, ITextRunConstructionContext context)
{
try
@ -190,7 +181,7 @@ namespace AvaloniaEdit.TextMate
if (transformations[i] == null)
transformations[i] = new ForegroundTextTransformation();
transformations[i].ColorMap = this;
transformations[i].ColorMap = _brushes;
transformations[i].ExceptionHandler = _exceptionHandler;
transformations[i].StartOffset = lineOffset + startIndex;
transformations[i].EndOffset = lineOffset + endIndex;

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

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using AvaloniaEdit.Document;
@ -13,12 +14,7 @@ namespace AvaloniaEdit.TextMate
public class ForegroundTextTransformation : TextTransformation
{
public interface IColorMap
{
AM.IBrush GetBrush(int color);
}
public IColorMap ColorMap { get; set; }
public Dictionary<int, AM.IBrush> ColorMap { get; set; }
public Action<Exception> ExceptionHandler { get; set; }
public int ForegroundColor { get; set; }
public int BackgroundColor { get; set; }
@ -47,13 +43,13 @@ namespace AvaloniaEdit.TextMate
}
transformer.SetTextStyle(line, formattedOffset, endOffset - line.Offset - formattedOffset,
ColorMap.GetBrush(ForegroundColor),
ColorMap.GetBrush(BackgroundColor),
GetFontStyle(),
GetFontWeight(),
IsUnderline());
GetBrush(ForegroundColor),
GetBrush(BackgroundColor),
GetFontStyle(),
GetFontWeight(),
IsUnderline());
}
catch(Exception ex)
catch (Exception ex)
{
ExceptionHandler?.Invoke(ex);
}
@ -85,5 +81,14 @@ namespace AvaloniaEdit.TextMate
return false;
}
AM.IBrush GetBrush(int colorId)
{
if (ColorMap == null)
return null;
ColorMap.TryGetValue(colorId, out AM.IBrush result);
return result;
}
}
}