Unplanned
Last Updated: 25 Dec 2025 13:25 by Martin Ivanov
Martin Ivanov
Created on: 25 Dec 2025 13:25
Category: RichTextBox
Type: Bug Report
0
RichTextBox: The line break symbol is treated as a text character when calculating the caret position on click at the end of the line

The line break symbol (Shift+Enter) is treated as a text character and it gets measured in the document position calculations executed when you click at the end of the document (somewhere after the line break symbol which ends the line). 

This causes two visual issues. The first one is that the caret goes after the line break symbol, which means that when ShowFormattingSymbols is False an empty space (non-existing in the document) is added at the end of the line. Even if ShowFormattingSymbols=true and the line break symbol gets display, it is not expected for ,the caret to get positioned after the symbol.

The second issues is that, when you start typing after you click at the end of the line, the caret position is corrected, but this leads to a jumps of the caret with one character to the left, which brings an unpleasant visual glitch.

To work this around, you can create a custom MouseSelectionHandler and override its RegisterDocumentMouseDown method. This will allow you to check if the caret is placed after the line break symbol and manually update the caret position if that is the case.

public class CustomMouseSelectionHandler : MouseSelectionHandler
{
    private IDocumentEditorPresenter presenter;
    private RadDocument document;

    public CustomMouseSelectionHandler(RadDocument document, IDocumentEditorPresenter presenter) 
        : base(document, presenter)
    {
        this.presenter = presenter;
        this.document = document;
    }      

    public override void RegisterDocumentMouseDown(bool ctrlPressed, bool shiftPressed, Point position, UIElement originalSource = null, SourceType source = SourceType.Mouse)
    {
        base.RegisterDocumentMouseDown(ctrlPressed, shiftPressed, position, originalSource, source);
        var box = this.document.CaretPosition.GetCurrentSpanBox();
        if (box != null && box.AssociatedSpan.Text == "¬")
        {
            document.CaretPosition.MoveToCurrentLineEnd();
        }
    }
}
To register the custom handler, use the MouseSelectionHandler property of the ActiveEditorPresenter.

 this.richTextBox.Loaded += (s, args) =>
 {
     var presenter = (DocumentPresenterBase)this.richTextBox.ActiveEditorPresenter;
     presenter.MouseSelectionHandler = new CustomMouseSelectionHandler(this.richTextBox.Document, presenter);
 };

0 comments