Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/AvaloniaEdit/Rendering/TextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,13 +1031,16 @@ private TextRunProperties CreateGlobalTextRunProperties()
return p;
}

private double LetterSpacing => TextElement.GetLetterSpacing(this);

private VisualLineTextParagraphProperties CreateParagraphProperties(TextRunProperties defaultTextRunProperties)
{
return new VisualLineTextParagraphProperties
{
defaultTextRunProperties = defaultTextRunProperties,
textWrapping = _canHorizontallyScroll ? TextWrapping.NoWrap : TextWrapping.Wrap,
tabSize = Options.IndentationSize * WideSpaceWidth
tabSize = Options.IndentationSize * WideSpaceWidth,
letterSpacing = LetterSpacing
};
}

Expand Down Expand Up @@ -1505,7 +1508,7 @@ private void CalculateDefaultTextMetrics()
line = _formatter.FormatLine(
new SimpleTextSource("x", textRunProperties),
0, 32000,
new VisualLineTextParagraphProperties { defaultTextRunProperties = textRunProperties });
new VisualLineTextParagraphProperties { defaultTextRunProperties = textRunProperties, letterSpacing = LetterSpacing });
}

if (line != null)
Expand Down Expand Up @@ -1940,7 +1943,8 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
if (change.Property == TemplatedControl.FontFamilyProperty
|| change.Property == TemplatedControl.FontSizeProperty
|| change.Property == TemplatedControl.FontStyleProperty
|| change.Property == TemplatedControl.FontWeightProperty)
|| change.Property == TemplatedControl.FontWeightProperty
|| change.Property == TextElement.LetterSpacingProperty)
{
// changing font properties requires recreating cached elements
RecreateCachedElements();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ sealed class VisualLineTextParagraphProperties : TextParagraphProperties
internal TextWrapping textWrapping;
internal double tabSize;
internal double indent;
internal double letterSpacing;
internal bool firstLineInParagraph;

public override double DefaultIncrementalTab => tabSize;

public override FlowDirection FlowDirection => FlowDirection.LeftToRight;
public override TextAlignment TextAlignment => TextAlignment.Left;
public override double LineHeight => double.NaN;
public override double LetterSpacing => letterSpacing;
public override bool FirstLineInParagraph => firstLineInParagraph;
public override TextRunProperties DefaultTextRunProperties => defaultTextRunProperties;

Expand Down
9 changes: 9 additions & 0 deletions src/AvaloniaEdit/TextEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Text;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
Expand Down Expand Up @@ -61,6 +62,7 @@ static TextEditor()
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
LetterSpacingProperty.Changed.Subscribe(OnLetterSpacingPropertyChanged);
SearchResultsBrushProperty.Changed.Subscribe(SearchResultsBrushChangedCallback);
}

Expand Down Expand Up @@ -612,6 +614,13 @@ private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}

private static void OnLetterSpacingPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;

editor?.TextArea.TextView.SetValue(TextElement.LetterSpacingProperty, e.NewValue);
}

private static void SearchResultsBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
Expand Down