Undoing a ReplaceText operation selects the text

SyntaxEditor for WPF Forum

Posted 12 years ago by Kasper
Version: 11.2.0551
Avatar
Hi guys,

A quick question: When I perform a ReplaceText operation, like this:

editor.Document.ReplaceText(TextChangeTypes.Custom, property.StartOffset, property.EndOffset - property.StartOffset, newCode);

and then undo it (a simple Ctrl+Z), the original text (replaced by the operation) is selected in the editor, despite the fact that no text was selected before. I'm not sure why, and this is not the behavior of SE for WinForms. I don't do anything else besides the line of code shown above, so you should be able to see the problem easily. Is this some sort of option that I can disable or is it a bug?

[Modified at 01/25/2012 09:50 AM]

Comments (4)

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

I did a test in the WinForms editor and it works the same, and always has been the same as far as I remember.

In WPF, there is a way you can change the selection on undo. Basically if you manually create a text change and set its SelectionPositionRange to something, that will be used on undo. Here is some sample code that shows this:
var doc = control.editor.Document;
var change =  doc.CreateTextChange(TextChangeTypes.Custom);
change.ReplaceText(control.editor.Caret.Offset, 1, "test");
change.SelectionPositionRange = new TextPositionRange(control.editor.Caret.Position);
change.Apply();


Actipro Software Support

Posted 12 years ago by Kasper
Avatar
Hi,

>I did a test in the WinForms editor and it works the same, and always has been the same as far as I remember.

With the WinForms edition, I passed the DocumentModificationOptions.RetainSelection flag, but I had of course already tried that for WPF with no luck (and no change in behavior, I think?). So, is this difference by design? I'm not really sure why anyone would want a piece of text re-selected just because of an undo operation, and this is not how Visual Studio does it either. In VS, if I search/and replace a word, jump to the next occurrence and then undo the previous replace, the text is simply changed back, while preserving my current cursor position. That's what I want :)

With your solution, I would have to change the behavior of the built-in Undo action, I suppose? I would be more comfortable if it just worked out-of-the-box, to be honest.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kasper,

Ok, I didn't know you had used the RetainSelection flag in the WinForms version. Yes when I tried it with that set in WPF, it didn't behave the same.

It appears that flag wasn't being persisted into the undo history. This has been fixed for the next maintenance release.


Actipro Software Support

Posted 12 years ago by Kasper
Avatar
Excellent, thank you very much. I'm looking forward to it :)
The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.