Undo, Text property, and selection questions.

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Kelly Leahy - Software Architect, Milliman
Version: 4.0.0260
Avatar
In my application, when the user makes certain changes via the UI, I rewrite a portion of the code in the editor for them. Because of the nature of the changes I'm making, it's much easier to replace the entire text in the editor than to make the changes piecemeal within the document.

I originally tried replacing the text by setting the Text property, but that didn't seem to add the change to the Undo list. Since I want this change to participate in the undo/redo chain, I then figured I need to use Document.ReplaceText to make my change. I've done so and it seemed to fix the problem of the change not appearing in the Undo list.

Question #1) is this the preferred way of replacing the entire text of the document in an 'undoable' operation?

Now, things seem to work ok with undo / redo, except that I've noticed that when I undo a change, the entire text of the document gets selected automatically. I've figured out how to unselect this text by just doing Collapse() on the selection, but it causes a bit of flicker. Before I go about looking for beginupdate / endupdate type functionality in the editor (I'm sure it's there), I wanted to ask if this is the desired behavior of Undo and whether there are any properties to control it, so here goes:

Question #2) should Undo select the text in the buffer, following the undo of an operation that replaced all the text in the buffer? If so, what is the preferred way of preventing the text from being selected without flicker in the UI, as my UI does not desire this behavior?

Thanks,

Kelly Leahy Software Architect Milliman, USA

Comments (1)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kelly,

Yes Document.ReplaceText is what you would want to do to keep the undo history.

I think there is a SyntaxEditor.SuspendPainting and related resume method you can use to wrap this with. See if that helps.

I believe Visual Studio processes the undo selection the same way. But if you have any specific suggestions for something, go ahead and post them. Your solution with the suspend/resume painting might be best though.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.