How to enable Virtual Space in AvalonEdit?

1k views Asked by At

I want to achieve "Virtual Space" functionality, similar to one in Visual Studio, in AvalonEdit.

I.e. the caret could be positioned beyond the end of the text line, and if you press any key, there would be spaces automatically added to match.

I am very used to this feature, but neither Googling nor studying AvalonEdit's code gave me any clues on how to enable it, if it is supported at all.

If it is not, suggestions how to extend caret handling mechanisms would be nice.

Thanks!

1

There are 1 answers

2
Daniel On BEST ANSWER

Edit: Virtual space support has been added to AvalonEdit in version 4.2.0.8283. Set textEditor.Options.EnableVirtualSpace = true;.

Below is my original answer.


It's not currently supported.

If you want to try adding it, make sure you read the "coordinate systems" documentation (in the help file on CodeProject). You'll want to extend the "visual column" so that positions after the line end are valid. And you'll have to adjust the position<->column calculations (VisualLine.GetVisualColumn and friends). Use TextView.WideSpaceWidth to figure out the columns past the end of the line.

The above should allow you to use the mouse to place the caret in virtual space. After that, you'll need to change the caret movement (arrow keys, CaretNavigationCommandHandler) and text input logic (TextArea.PerformTextInput) to also support the virtual space.

And if you're successful with the above steps, don't forget to contribute your changes back to AvalonEdit. :-) While I'm not a fan of virtual space myself, we need something like it to make the RectangleSelection work properly.