DocumentTextChanging

SyntaxEditor for Silverlight Forum

Posted 9 years ago by Christel
Version: 10.2.0105
Avatar
Hi again,
Problem:
The user edit action should be immediately manipulated in that way, that every sign input should be transformed to upper case.
E.g. The user types "qwertz" but he should see "QWERTZ"

I try to solved this in the xaml.cs-File of teh syntaxeditor-Page:
but it didn't work, no changes can be seen in the editor whily typing. What did I made wrong?

private bool doFireChangeEvent = true;

private void editor_DocumentTextChanging(object sender, EditorSnapshotChangingEventArgs e)
{
if (doFireChangeEvent)
{
doFireChangeEvent = false;
string changedtoTUpper = e.NewSnapshot.Text.ToUpper();
ITextChange change =
e.NewSnapshot.CreateTextChange(TextChangeTypes.AutoReplace);
change.ReplaceText(e.NewSnapshot.TextRange, changedtoTUpper);
change.Apply();
doFireChangeEvent = true;
}
}

Thanks again for the help!

Comments (8)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Christel,

Check out the document's AutoCharacterCasing property. That might be what you want. Just set it to Upper.


Actipro Software Support

Posted 9 years ago by Christel
Avatar
Hi,
sounds perfect, but didn't work for now.
Where should it be initialised?

I tried it in the Control.constructor after InitializeComponent
or when the language is loaded.
When the text is formatted in the Textformatter I look at the property for the document. it is set to upper.
But inserting text by editing will not transform the letters to upper.

Thanks
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Christel,

We discovered a bug that prevented it from working. We've fixed it for the next maintenance release.


Actipro Software Support

Posted 9 years ago by Christel
Avatar
Hi,
thanks for the information and testing!
When will the next maintenance release be provided. How can I get it?
I need this feature until end of November...
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Sorry but there probably won't be a maintenance release until after November since we need to collect some more updates before releasing a new one.

Perhaps a workaround for now would be to handle the EditorView's (via editor.ActiveView) TextInput event. Mark e.Handled = true there if the e.Text is not all uppercase and then set the view's SelectedText property to the uppercased version of e.Text.


Actipro Software Support

Posted 9 years ago by Christel
Avatar
Hallo,
There is no TextInput-Event for the ActiveView(ITextView).
Therefore I tried it with
(SyntaxEditor)editor.TextInput +=
new TextCompositionEventHandler(VisualElement_TextInput);
and
editor.AtiveView.VisualElement.TextInput +=
new TextCompositionEventHandler(VisualElement_TextInput);

like this:

void VisualElement_TextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = true;
string uppertext = e.Text.ToUpper();
editor.ActiveView.SelectedText = uppertext;
}

But the event is never called. Setting breakpoint in the delegate shows, that the code is never reached.

What did I miss?
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Christel,

You are right, IEditorView is an interface so you'd need to get to VisualElement. However I see what you mean now, our call to base.OnTextInput isn't raising the event since our override of OnTextInput itself is a handler of the event and fires before yours would kick in.

Our OnTextInput override notifies a IEditorViewTextInputEventSink language service before our default code kicks in. If your language registers that event sink service type (see documentation on Event Sinks) and sets e.Handled there, that will accomplish that same thing that I had tried to suggest as a temporary workaround before.


Actipro Software Support

Posted 9 years ago by Christel
Avatar
Hi,
brilliant!!
It works and the implementation is so easy!
Thousand Thanks for such professional help!
The latest build of this product (v2018.1 build 0232) 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.