Maybe a dumb question?

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Matt Whitfield
Version: 4.0.0261
Avatar
I am trying to set up auto replace triggers in my language (sql) - so i'd like begin to be replaced with:

begin

end

so what I do is replace begin with begin\r\n\t\r\nend

Then in autoreplaceperformed, i use the following:

switch (e.AutoReplaceEntry.FindText)
{
case "begin":
{
shtb.Caret.Offset = e.Offset + 7;
} break;
}

However, this makes me end up

begin


end

- it seems like the enter after the auto replace is added after the autoreplaceperformed event - but i cannot find where to cancel this.

Doing it in KeyTyping doesn't seem to make any difference - KeyTyped seems to be too late, and handling it in KeyPress doesn't seem to make any difference either...

any ideas?

Comments (7)

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

KeyTyping lets you cancel or change the Command that will execute. Try that instead of KeyTyped.


Actipro Software Support

Posted 12 years ago by Matt Whitfield
Avatar
erm - i did?

I did say i'd tried that - i tried setting a variable to true when the auto replace happens (in my handler for AutoReplacePerformed), then if that variable is true, setting e.Cancel

What happens is it cancels the keypress afterwards, not the keypress that caused AutoReplacePerformed to fire.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ahh, sorry I didn't see the part about KeyTyping.

Here's what is happening in our code:
1) It fires KeyTyping, which determines which command will be raised.
2) It looks and fires auto-replace if appropriate.
3) It raises the command determined in #1.
4) It fires KeyTyped.

So based on that, I'm not sure there's a way for you to prevent this. You basically want to not insert the \n if it matches an auto-replace item, right? What about the other types of characters that can kick off an auto-replace?


Actipro Software Support

Posted 12 years ago by Matt Whitfield
Avatar
Yep that pretty much concurs with what I get.

Bascially I'd like an e.CancelKeypress in the AutoReplaceEventArgs which, when set, would cancel the keypress afterwards.

It's a similar functionality seen to the VB editor in VS2005 - when you type in an If statement, it will put the End If in, and put the cursor on the middle of the two lines, one tab in...
Posted 12 years ago by Matt Whitfield
Avatar
If you could let me know whether the above is something you will consider adding, then that would be good.

I'd just like to know, because if it's not something that you would add, then i'd just like to know so i can get on with finding some hideous hack way around the problem...

edit ->

My hideous hack is to set a flag, and call Undo() based on that flag in the KeyTyped event. But this still poses me a problem, in that then the redo stack contains the action that I have then undone. I can clear both the Undo and Redo stacks - but there doesn't seem to be a way to clear the Redo stack only.

So, please actipro, could i have either

a) A cancelKeyPress command to negate the keypress processing in the autoReplace event
or
b) A Document.UndoRedo.RedoStack.Clear() method

I am guessing b) would be easier - and would suit me just fine...

Thanks

[Modified at 10/08/2007 06:16 PM]
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We've made a couple enhancements for you for the next maintenance release:
1) Added KeyChar to AutoReplaceEventArgs. This tells you the character being typed that triggered the auto-replace.
2) Added CancelKeyPress to AutomReplaceEventArgs. If set to true, it will cancel the KeyChar from being inserted.

Sound good?


Actipro Software Support

Posted 12 years ago by Matt Whitfield
Avatar
Absolutely! You guys are certified stars!
The latest build of this product (v2020.1 build 0400) was released 7 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.