Reputation: 339
I know you can disable input altogether if you handle the PreviewKeyDown event of the editor and then set the e.Handled of the KeyEventArgs to true.
However, I'm trying to figure out how to prevent the document text from updating after the text is modified. I want to handle the Document.Changing event, like so:
textEditor.Document.Changing += Document_Changing;
where textEditor is my AvalonEdit editor. I want to retrieve the text that is being modified, in the function
private void Document_Changing(object sender, DocumentChangeEventArgs e)
and then do some computation based on it. However, I do not want the text to be updated in the editor before it's being processed. I'm doing some async processing in the Document_Changing, and I fire another event when it's finished, and only then I want it to update. I don't want to disable just visual updating, but updating the document altogether.
So is there a way to disable this update, similar to how you can prevent input when handling keyboard-related events?
Thank you in advance
Upvotes: 2
Views: 1886
Reputation: 16464
You can use the textEditor.TextArea.TextEntering
event to prevent the user from typing.
However that event only is used for typing; other operations (e.g. Cut/Paste/Drag'n'Drop) currently do not cause any editor events (only the document event, but at that point it's too late to abort).
Another option is to implement IReadOnlySectionProvider
to mark the text as read-only. This works for both text input and clipboard operations, and even disables the 'Paste' menu command when the caret is inside a read-only section.
The TextSegmentReadOnlySectionProvider
class provides a useful default implementation for the interface.
For turning the whole document read-only, simply set textEditor.IsReadOnly = true;
.
Upvotes: 6