Setting FirstVisiblePosition Not possible

SyntaxEditor for WPF Forum

Posted 4 years ago by James Zheng
Version: 16.1.0630
Platform: .NET 4.5
Environment: Windows 10 (64-bit)
Avatar

Hi Actipro,

I'm writing an editor whose settings (zoom level and first visible position) are restored when its document is changed. I restore the first visible position as follow:

view.FirstVisiblePosition = _firstVisiblePosition;

However, in some cases, the first visible position is set a few lines before the desired line when switching from a document without zoom to one with zoom. After some debugging, it's found to be due to view.VisibleViewLines.FullyVisibleCount. This count is still the count from the previous document. Therefore, the editor thought that it's called to scroll to a position beyond its limit, and, in the end it, only scroll to a "maximum line" possible which is not true.

Please advice.

Thanks and Regards,

James Zheng

[Modified 4 years ago]

Comments (3)

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

Hi James,

What if you do something like set ZoomAnimationDuration = 0, then set ZoomLevel, call UpdateLayout, restore old ZoomAnimationDuration value and finally set FirstVisiblePosition?


Actipro Software Support

Posted 4 years ago by James Zheng
Avatar

Hi Actipro,

This won't help. Below is the function used to restore.

public void Restore(IEditorView view)
{
            if (_zoomLevel != view.SyntaxEditor.ZoomLevel)
            {
                var duration = view.SyntaxEditor.ZoomAnimationDuration;

                view.SyntaxEditor.ZoomAnimationDuration = new Duration();
                view.SyntaxEditor.ZoomLevel = _zoomLevel;
                view.SyntaxEditor.UpdateLayout();

                view.SyntaxEditor.ZoomAnimationDuration = duration;
            }

            if (_selectionRange != view.Selection.TextRange)
            {
                view.Selection.SelectRange(_selectionRange);
            }

            if (_currentCaretPosition != view.SyntaxEditor.Caret.Position)
            {
                view.SyntaxEditor.Caret.Position = _currentCaretPosition;
            }

            if (_firstVisiblePosition != view.FirstVisiblePosition)
            {
                view.FirstVisiblePosition = _firstVisiblePosition;
            }

            if (_firstVisibleX != view.FirstVisibleX)
            {
                view.FirstVisibleX = _firstVisibleX;
            }
}

 

Regards,

James Zheng

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

Hi James,

If you'd like us to debug it, could you put together a new simple sample project that shows the issue and email the ZIP to our support address?  Be sure to mention this thread in your email and rename the .zip file extension so it doesn't get spam blocked.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) 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.