AvaloniaEdit icon indicating copy to clipboard operation
AvaloniaEdit copied to clipboard

Line numbers (margin) misaligned with the editor

Open YvesHenri opened this issue 10 months ago • 2 comments

For some reason the line numbers are misaligned with the editor (see picture below):

Image

Here's my AXAML:

<avaloniaEdit:TextEditor SyntaxHighlighting="{Binding SyntaxTheme}" ShowLineNumbers="True" FontFamily="Consolas">
  <avaloniaEdit:TextEditor.Options>
    <avaloniaEdit:TextEditorOptions IndentationSize="3" ConvertTabsToSpaces="True" HighlightCurrentLine="False" />
  </avaloniaEdit:TextEditor.Options>
  <avaloniaEdit:TextEditor.Styles>
    <Style Selector="editing|LineNumberMargin">
      <Setter Property="MinWidthInDigits" Value="4" />
    </Style>
  </avaloniaEdit:TextEditor.Styles>
</avaloniaEdit:TextEditor>

This happens whether setting the FontFamily or not. I'm using <FluentTheme /> only (no other styles).

Bonus: is there a way to add a margin on the sides of the line numbers border?

YvesHenri avatar Apr 25 '25 23:04 YvesHenri

The text alignment looks fine on my machine (AvaloniaEdit 11.2, Windows 11, no dpi scaling). Can you reproduce the problem in the AvaloniaEdit.Demo? What is your OS version and AvaloniaEdit version?

Bonus: is there a way to add a margin on the sides of the line numbers border?

You can change the TextView style to add a margin between the line numbers and the text. See example here: https://github.com/AvaloniaUI/AvaloniaEdit/issues/477#issuecomment-2763238576

mgarstenauer avatar Apr 27 '25 11:04 mgarstenauer

My bet is that this is a similar issue to my fixes in the following PR. It's going to be important that the line number font and such is exactly the same as the text view.

https://github.com/AvaloniaUI/AvaloniaEdit/pull/519

BobbyCannon avatar Jun 26 '25 12:06 BobbyCannon