Adapt inserted text from intelli prompt depending on surrounding text

SyntaxEditor for WPF Forum

Posted 2 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Version: 21.1.3
Avatar

Hi,

we have elements in our custom language that are like attributes in C#. 

[AttributeKey="value"]

After the assignment operator we show the possible values, where the display text doesn't have the quotation marks, but they are added anyway. So far so good. Now the problem starts when the quotation marks are already there. Then the entire text including the quotation marks is still added.

We'd like to adapt the inserted text depending on the surrounding text. So don't add the quotation marks when they are already present. I tried working with the pre-text and post-text properties of CompletionItem, but this didn't change anything.

Any idea how we could achieve this?


Best regards, Tobias Lingemann.

Comments (3)

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

Hi Tobias,

I'm not entirely clear on why using pre/post text was not a solution. Could you expand on why it didn't work for you?

The quotes should only be inserted if they are either part of the value or part of the pre/post text. Before opening your completion session, you could look at the tokens around the offset to determine if the quotation marks are already there. If they are, don't include them in the pre/post text. If they are not present, add them to pre/post text.


Actipro Software Support

Posted 2 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

Well my initial thought was that pre text and post text are what is surrounding the inserted text, but that is not the case. Only pre and post text are inserted. The first in front of the caret, the other afterwards. In our case pre text is the combination of prefix, text and postfix while post text is empty. Other combinations don't work at all or have the same problem.

I improved the behavior by getting the current token and checking if the prefix and postfix are part of the token text. But this doesn't work in all situations and depends on where the caret is.

[Modified 2 years ago]


Best regards, Tobias Lingemann.

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

The Text property primarily controls the display text. If explicit values are not given for AutoCompletePreText or AutoCompletePostText, the same Text property is also used for the inserted text. If Pre/Post text are given, those values are solely used for the inserted text around the caret and the Text property only serves to control what is displayed in the completion list.  You've probably already seen this topic, but here's more information on text insertion for others who may stuble upon this thread:

https://www.actiprosoftware.com/docs/controls/wpf/syntaxeditor/user-interface/intelliprompt/completion-list#text-insertion

As you stated, the values for pre/post text would vary depending on the caret's position relative to any existing quotation marks.

Another option might be to avoid including the quotation marks in the completion list and handle the quotation marks after a selection is inserted. There are Committing and Committed events that can be used for more control over what gets inserted. More details on those are available here:

https://www.actiprosoftware.com/docs/controls/wpf/syntaxeditor/user-interface/intelliprompt/completion-list#commit-and-cancel

You could, for instance, listen to the Committing event to determing the selection, cancel the default operation, and then manually insert the corresponding text with surrounding quotation marks (as needed) around the text.


Actipro Software Support

The latest build of this product (v24.1.2) was released 0 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.