Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab Column Misalignment #412

Open
ajkfds opened this issue Apr 15, 2024 · 2 comments
Open

Tab Column Misalignment #412

ajkfds opened this issue Apr 15, 2024 · 2 comments

Comments

@ajkfds
Copy link

ajkfds commented Apr 15, 2024

When inserting characters before a tab, the tab’s column position does not align as expected.

image

The expected behavior was as shown in the image below.

image

AvaloniaEdit 11.0.6 + .net 6.0 + Windows 11 Home

@mgarstenauer
Copy link
Contributor

This seems to be a bug in Avalonia. You can reproduce this bug using a simple TextBox.

<TextBox Text="&#x09;a&#x09;a&#x0D;a&#x09;a&#x09;a"/>

Avalonia:
image

WPF:
image

I am going to file an Avalonia issue.

@ajkfds
Copy link
Author

ajkfds commented Apr 18, 2024

I have found a temporary workaround for the bug until it is fixed.

  1. Set indentation size =1 and ShowTabs = true
            _textEditor.Options.IndentationSize = 1;
            _textEditor.Options.ShowTabs = true;
  1. Fix Rendering/SingleCharacterElementGenerator.cs to accept TabGlyphRun Size cahnge.

Change TabTextElement class from private to internal.
Add TabSize variable.

internal sealed class TabTextElement : VisualLineElemen
    {
        public int TabSize = 0;
        ...
    }

Fix Size override of TabGlyphRun.

private sealed class TabGlyphRun : DrawableTextRun
{
    ...
    //public override Size Size => default;

   public override Size Size
    {
        get
        {
            return new Size(_element.Text.WidthIncludingTrailingWhitespace* (_element.TabSize-1), 0);
        }
    }
    ...
}
  1. Fix Rendering/VisualLine.cs to Set TabSize parameter of TabTextElement
        private void CalculateOffsets()
        {
            var visualOffset = 0;
            var textOffset = 0;
            int tabOffset= 0;
            foreach (var element in _elements)
            {
                element.VisualColumn = visualOffset;
                element.RelativeTextOffset = textOffset;
                visualOffset += element.VisualLength;
                textOffset += element.DocumentLength;
                if(element is SingleCharacterElementGenerator.TabTextElement)
                {
                    (element as SingleCharacterElementGenerator.TabTextElement).TabSize = 4-(tabOffset%4);
                    tabOffset = 0;
                }
                else
                {
                    tabOffset = tabOffset + element.DocumentLength;
                }
            }
            VisualLength = visualOffset;
            Debug.Assert(textOffset == LastDocumentLine.EndOffset - FirstDocumentLine.Offset);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants