Horizontal scrollbar doesn't get scrolled to the caret when programmingly do a backward selection

SyntaxEditor for WPF Forum

Posted 7 years ago by Jianjun Wang
Version: 16.1.0633
Avatar

Horizontal scrollbar doesn't get scrolled to the caret when programmingly do a backward selection by setting the Selection.StartPosition greater than Selection.EndPosition:

ActiveView.ScrollToCaretOnSelectionChange = true

ActiveView.Selection.StartPosition = new TextPosition(10, 100); // selection start at character 100 of line 10
ActiveView.Selection.EndPosition = new TextPosition(10, 0); // selection end at character 0 of line 10

 

After execution of above code, the caret is placed at character 0 of line 10, which is expected, but the horizontal scrollbar is scrolled to character 100 of line 10, causing the caret at character 0 of line 10 is not visible.

I would expect the horizontal scrollbar to be scrolled to the Selection.EndPosition, which is character 0 of line 10, since the caret is there.

Is this a bug or how I can workaround it?

Comments (3)

Posted 7 years ago by Jianjun Wang
Avatar

mm... using ActiveView.Selection.SelectRange(new TextPosition(10, 100), new TextPosition(10, 0)) will get the correct behavior of horizontal scrollbar being scrolled to the TextPosition(10, 0).

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Caret moves try to ensure the caret remains visible based on the view's FirstVisibleX and the current bounds.  The problem here is that after StartPosition is set, everything is sort of in an intermediate state where some internal variables have been updated but the view layout didn't occur just yet prior to EndPosition being set.  The two workarounds would be to do the single SelectRange call as you saw, or you could call editor.UpdateLayout() in between the two position calls.  But doing the SelectRange call is better.


Actipro Software Support

Posted 7 years ago by Jianjun Wang
Avatar

Yes. will use a SelectRange call to achieve the functionality.

Thanks for the information and confirmation.

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.