Preventing insertion when Intelli-prompt list is closing

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Kevin Phillips
Avatar
Hi,

I've just bought the syntax editor (version 3.1.202.0 - I'm using vs.net 2003) and it seems to be doing the job really well, except I haven't been able to solve a little problem I have with the intelli-prompt that I'm hoping someone can shed some light on.

I'm using it to show the available attributes for an XML tag, so when you hit space and you're inside an XML tag I show it. I set the pre-text to be the item you've selected followed by =" and the post-test to be " so you can then just type in the value. This is fine unless you type one of the items in the intelli-prompt list by hand and then type =. The = closes the intelli-prompt list but it still adds the extra stuff which is not what I want. I would have thought that as I didn't actually pick anything from the list it would "Cancel" the intelli-prompt and therefore not do any text insertion (I tried attaching an event listener to the closing and closed events and both have the Cancel property set to false).

Did that make sense? If not, here's some code. Create a new winforms project and drop the syntax editor onto the Form1 form then open up the Form1 code and paste this into the constructor:
KeyPressTrigger trigger = new KeyPressTrigger("MyTrigger", false, ' ');
trigger.ValidLexicalStates.Add(syntaxEditor1.Document.Language.LexicalStates[0]);
syntaxEditor1.Document.Language.Triggers.Add(trigger);
Then add an event handler for the Trigger event of the syntax editor and put the following code in it:
IntelliPromptMemberList memberList = syntaxEditor1.IntelliPrompt.MemberList;
memberList.Clear();
memberList.Add(new IntelliPromptMemberListItem("item", 0, null, "item=\"", "\""));
memberList.Show();
Now run it and type the following string into the syntax editor:

<hello item=

You'll see that after you type = you end up with this:

<hello item="="

I'd rather it just closed the intelli-prompt list and inserted nothing in this case, is there a way I could achieve this? Thanks for your help,

Kev

Comments (7)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kev,

The way the logic works is that if you have a full match (fully highlighted) when you type the = char, it will do an insert. If you have a partial match (just a border around the selected item), it will not do an insert. In this case, since you typed "item", you have a full match, therefore an insert is occurring.

Maybe in KeyTyping, cancel the member list if you see a "=" being typed. We're also open to suggestions for improving our object model to aid in situations like this if you would like to post any.


Actipro Software Support

Posted 12 years ago by Heiko Polenz
Avatar
Hey,

is there any news on this Task?!

I have the same (or kindda same) issue here when just typing code.
For example, I type HTML code as follows:

- Typing "<div"
- Intelli-promp is showing the tag list and selects the "div"
- but if I dont care about the list - means: i dont use it - it takes the div tag and runs the "auto-complete"
(as desribed in the posting above)
- Problem is: In the meantime I have continued to type the code myself, means right the same moment the Intelli-prompt has completed the tag, I have typed the closing ">" to the div.
- In the result I have <div>></div> ...you see the unwanted and unneccesary > there.

The SyntaxEditor should recognize and ignore the typed >
OR the SyntaxEditor should use the item from the Intelli-prompt ONLY when the User hits ENTER.

How can I workaround this?
Is there an event to use to check whats inserted?
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Heiko,

Our member list works exactly like Visual Studio does. Note that if you are in an XML comment in Visual Studio you can see similar behavior... Type < in a C# XML comment. Highlight the "include" item and press the ' key. You will get this with the caret in the file attribute:
<include file=''' path='[@name=""]'/>

It seems like what you want to do is filter out that extra ' character. You can do that in the SyntaxEditor.IntelliPromptMemberListClosing event by looking at the selected item in the member list if e.Cancel is not true and changing its pre/post text.

A word of advice... Note that for tags like div tags you should not put the end tag in there like you are. It's better design to simply put the tag name and then handle the > key so that it auto-completes whatever tag you are on and creates an end tag for it if appropriate. That is what Visual Studio does and it eliminates the issue you are facing in your div tag example.


Actipro Software Support

Posted 12 years ago by Heiko Polenz
Avatar
First: Thanks for the really fast answer (I didnt expect that, thats because I see it just today) :)

Quote:
Our member list works exactly like Visual Studio does.

Nope, sorry. You are wrong.
If I do what I have described above (typing a div tag) VS completes the div tag without adding an unnecessary '>' to the output.
Thats what I have suggested your CodeEditor should work too. Ignoring my typed '>' when autocomplete the tag.

Maybe your control works the right way (means: can work the right way) and just the example I have (from you) does not (because a bit older) ?!

Anyway, I will try your hint. Thanks for that. :)

Best regards
Heiko Polenz

[Modified at 09/09/2006 09:18 AM]
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Don't mean to go back and forth on this but our code does work exactly like VS and how I described. But as you said, our HTML sample code in MainForm doesn't follow our own advice. :) Let me explain in more detail.

Back on VS. If you type <d and select "div" and press TAB then it only inserts the <div. It doesn't complete the tag. When you type > instead of TAB it is inserting the <div (per auto-complete) then adding the > that you typed which triggers code to auto-complete the tag in front of the caret. This is the same as if you didn't use the member list at all, typed <div and then typed >. Again in that scenario, the tag auto-completes. So in VS, when you press > with a member list open you are seeing the auto-complete of the selected item and then a secondary auto-complete that inserts the end tag because of the > trigger.

Back to what is happening with SyntaxEditor. You need to do two things to get it to work as described above. First, all the HTML tag member list items should NOT insert the end tags. As you said, that sample is pretty old so we really should update it.

So code like:
memberList.Add(new IntelliPromptMemberListItem("a", imageIndex, null, "a>", "</a>"));
should really be:
memberList.Add(new IntelliPromptMemberListItem("a", imageIndex));
Then in your SyntaxLanguage implementation code, overwrite OnSyntaxEditorKeyTyped and look for a > character. In that, use a TextStream to go backwards and see if the previous tag is a start tag. If it is, grab its name then insert the appropriate close tag after the caret by using a call to:
editor.SelectedView.InsertSurroundingText(String.Empty, "</closetag>");
If you add that code, then the functionality is the same as VS. In terms of our core member list code implementation, it already does work exactly like VS. However if you feed it the wrong member list item data (as we somewhat did by our old sample), then it won't behave exactly as you'd like.

In the XML language we have in our beta web languages add-on we just added code in the release yesterday to do the end tag insertion when you type a > by using the above pseudocode. Maybe we'll update our dynamic HTML language in the next v4.0 beta release to demonstrate that same sort of code and we'll fix up the HTML member list items so they also work like described above. Then it will mimic VS functionality exactly.

I hope that clarifies everything.


Actipro Software Support

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
As a side note, the dynamic HTML sample in the next 4.0 beta now has all the code to do this properly.


Actipro Software Support

Posted 12 years ago by Heiko Polenz
Avatar
Well, what's left to say?!
Thank you very much and "ThumbsUp" for your support at all.
Very good!!

Best regards
Heiko Polenz
The latest build of this product (v2018.1 build 0341) 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.