Can I make Intelliprompt work like Visual Studio when typing an open paren

SyntaxEditor for Windows Forms Forum

Posted 6 years ago by Mike Dempsey - Sr. Developer, Teradata Corp
Version: 12.1.0303
Avatar

My intelliprompt member list contains both keywords and functions.

For the functions (eg. AVG) I specify preText="AVG(" and postText=")".

If I select the item by pressing Enter then it correctly inserts "AVG()" and places the cursor between the parens.

If I select the item by pressing Space then it inserts "AVG( )" and places the cursor after the space character (between the parens).
(Not ideal but I can live with it)

If I select the item by pressing "(" then it inserts "AVG(()" which is obviously not correct.

I tried setting MatchBasedOnItemPreText to both True and False but that made no difference.
How do I make it ignore the typed letter when it is an open paren (or even a space).
(More generally perhaps - when it matches the last letter of what it is going to insert)

Thanks
Mike

Comments (7)

Answer - Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mike,

What works better here is if you simplify your member list items to not include parens.  Then watch events like the one that fires when a member list completes and in there you can see if there are parens in the text already or if some should be added.  And use the view's InsertSurroundingText feature in that case.


Actipro Software Support

Posted 6 years ago by Mike Dempsey - Sr. Developer, Teradata Corp
Avatar

I had tried using the OnSyntaxEditorIntelliPromptMemberListClosed function but I don't see a parameter or variable in the MemberList or IntelliPrompt classes that tells me what the trigger character was that the user typed.

I managed to get it using
    Dim c As String = editor.Document.GetSubstring(editor.Caret.Offset - 1, 1)
but I'm hoping there is an easier/safer way to get it.

I then used
    editor.SelectedView.InsertSurroundingText("(", ")")
to add the parens. So far so good...

But after the member list item is inserted I need to make the "(" keypress trigger fire.
I thought the InsertSurroundingText would fire the trigger but I guess it really does apply only to keypresses.

So rather than use this can I use Commands to tell it to insert the ")", than backspace, then insert the "(" AS A KEYPRESS?

For example if I insert
    MAX()
I want the carat to be between the parens and for my "(" trigger to fire. (No matter whether the user typed a "(", space or enter.)

Thanks

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mike,

It shouldn't really matter what the last typed character was.  You should examine the characters by the caret instead (with range checking of course so you don't pass -1, etc.).

But anyway, you can mimic a key type if you do:

editor.SelectedView.PerformInsertTyping('(');

 Perhaps that will fire the trigger.


Actipro Software Support

Posted 6 years ago by Mike Dempsey - Sr. Developer, Teradata Corp
Avatar

I definately need to know the last character typed since the logic varies based on that.

At the time fires the intelliPrompt member item has been inserted into the document but the typed character has not.
If the user typed an "(" then I must NOT insert another "("
but if they typed anything else then I MUST insert the "(".

I solved this by adding a lastTypedCharvariable to my language class and setting this variable in the OnSyntaxEditorKeyTyping() function.
That should be a minor overhead even if it does get executed with every keypress.

So now in OnSyntaxEditorIntelliPromptMemberListClosed() I can use:

    Dim itm As IntelliPromptMemberListItem = editor.IntelliPrompt.MemberList.SelectedItem
    If itm IsNot Nothing AndAlso itm.AutoCompletePostText = ")" AndAlso lastTypedChar <> "(" Then
        editor.SelectedView.PerformInsertTyping("(")

This works great.

Note that when creating the IntelliPromptMemberListItem I have to set the PreText to the function name and the PostText to ')', since otherwise I don't know which items require the parens.
I was unable to set PostText without providing the PreText also (in the constructor).
I tried specifying Nothing and also "" but both of those resulted in no text at all being inserted before the carat.

Mike

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

I still don't thnk the parens should be part of the member list.  You can store data in the member list item's Tag field so you know which need parens.


Actipro Software Support

Posted 6 years ago by Mike Dempsey - Sr. Developer, Teradata Corp
Avatar

What's the difference (internally) between storing the ")" in the PostText field or in the Tag field?

If I store it in the post text field then Syntax Editor inserts it for me.
If store it in the tag field I have to cast it to a string (or Char) and insert it manually, then back up one position before 'typing' the "(".

So what is the disadvantage of using the PostText field that makes up for having to do all that manual work?

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mike,

The idea is that then you make the determination of whether or not to insert parens after the member list auto-completes by looking at the tokens that are in the editor.  But if what you have is working fine for you, then go with it.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.