dont refresh selectedview on document changed

SyntaxEditor for Windows Forms Forum

Posted 7 years ago by Tanja Lerbs - Germany
Version: 12.1.0302
Avatar

I search for a property in the editor to disable the refresh of the selectedview when I change the document.

The problem is: After changing the document, the selectedview scrolls automatically to the changed line.

Please help.

Thank you in advance.

Comments (3)

Posted 7 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

You can use SuspendPainting() to supsend GUI updates and SelectedView.Selection.SuspendEvents() to suspend selection changed events.

However don't forget to resume the painting/events. I've made myself some helper classes and wrap the calls with a using, so the dispose is called even if there is an exception.

Keep in mind that the selection events are only delayed, not ignored. You probably want to supsend the painting, then do your work, reset the selection and resume painting (in that order).

// Note: This class can only delay the selection changed events, not suppress them
  public class SuspendSelectionEvents : IDisposable
  {
    private bool mIsDisposed = false;
    private SyntaxEditor mEditor;

    public SuspendSelectionEvents(SyntaxEditor editor)
    {
      mEditor = editor;

      if ((null != mEditor) && (!mEditor.IsDisposed) && (null != mEditor.SelectedView))
      {
        mEditor.SelectedView.Selection.SuspendEvents();
      }
    }

    ~SuspendSelectionEvents()
    {
      Debug.Assert(mIsDisposed, "dispose object with using section");
      Dispose();
    }

    #region IDisposable Members

    public void Dispose()
    {
      if (!mIsDisposed)
      {
        mIsDisposed = true;

        if ((null != mEditor) && (!mEditor.IsDisposed) && (null != mEditor.SelectedView))
        {
          mEditor.SelectedView.Selection.ResumeEvents();
        }
      }
    }

    #endregion IDisposable Members
  }

  public class SuspendPainting : IDisposable
  {
    private bool mIsDisposed = false;
    private SyntaxEditor mEditor;

    public SuspendPainting(SyntaxEditor editor)
    {
      mEditor = editor;

      if ((null != mEditor) && (!mEditor.IsDisposed))
      {
        mEditor.SuspendPainting();
      }
    }

    ~SuspendPainting()
    {
      Debug.Assert(mIsDisposed, "dispose object with using section");
      Dispose();
    }

    #region IDisposable Members

    public void Dispose()
    {
      if (!mIsDisposed)
      {
        mIsDisposed = true;

        if ((null != mEditor) && (!mEditor.IsDisposed))
        {
          mEditor.ResumePainting();
        }
      }
    }

    #endregion IDisposable Members
  }

[Modified 7 years ago]


Best regards, Tobias Lingemann.

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

Hi Tanja,

In your text change you should specify the DocumentModificationOptions.RetainSelection flag.  I think that's what you're looking for.


Actipro Software Support

Posted 7 years ago by Tanja Lerbs - Germany
Avatar

Thanks for your help. That's what i was looking for. :-)

The latest build of this product (v2020.1 build 0400) was released 4 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.