Switching between filters in a completion session

SyntaxEditor for WPF Forum

Posted 8 years ago by Matt Whitfield
Version: 16.1.0630
Avatar

I'm looking to have filters implemented in a completion session by separating items into 'Suggested' and 'All'. My scenario is a SQL editor, and, for example, after the keyword SELECT I want to pop up a suggested list of tables/views, with other things such as built-in functions on the 'All' tab. It's important to me that people can use camelhumps as well as substring matches - so being able to type 'tilc' for TransactionItemLookupCodes or 'LookupCodes' for the same result. So I enabled both UseAcronyms and UseShorthand in the MatchOptions for the completion session.

Currently, if I type 'DATEADD' then I get 'database_audit_specification_details' - and what I wanted was the 'DATEADD' entry on the 'All' list.

So - a couple of specific questions:

1) Does it match that entry because shorthand translates to a regex like '.*h.*e.*l.*l.*o.*' for the text 'hello' rather than '.*hello.*'? If so I am guessing I can just implement a custom filter that allows substring matches without allowing characters in between.

2) Is there any way that I can switch between tabs at runtime so that if a user begins typing something that is on the 'all' list then the UI changes and an item from the 'all' list is selected? I thought maybe the right way to go about that would be inheriting from CompletionSession, checking if there is a match in the 'suggested' list currently, and flipping to the 'all' list if any of the matchers would match an item in there.

3) In the above scenario - when I have typed 'DATEADD' and then manually click on 'All' - the list is scrolled so that the currently selected item isn't visible - and it becomes visible after a keypress. Is there anything I can do about that?

Thanks in advance, and please let me know if I haven't explained anything clearly enough...

Matt

Comments (3)

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

Hi Matt,

Let me answer your questions...

1) Yes shorthand is effectively like ".*h.*e.*l.*l.*o.*" so you could make a custom filter if you like.

2) We'll update the next build's code so that if you set a tab filter's IsActive property to true before the completion list is displayed, that tab will be selected by default.

3) We'll update the next build to scroll to the selected item when a tab is clicked.

I hope that helps!


Actipro Software Support

Posted 8 years ago by Matt Whitfield
Avatar

Thanks for the reply... on 2) I wasn't looking for a way to set IsActive before the completion list is displayed - I'd like to be able to switch to a different tab during a session, based on a better match existing on another tab. So is there any way I can achieve that? I'm happy to programatically determine which tab is best myself, and I'm pretty sure that I want to over-ride CompletionSession, override OnDocumentTextChanged, then check for the selection state being partial - and then see if there is a better match on another tab. The bit I'm struggling with is finding out how to apply the matchers to the currently filtered items. Are there any code examples around for that or hints you can give?

Posted 8 years ago by Matt Whitfield
Avatar

Actually, don't worry, I figured it out. For anyone interested, here's the code I used in a derived CompletionSession:

        protected override void OnDocumentTextChanged(SyntaxEditor editor, EditorSnapshotChangedEventArgs e)
        {
            base.OnDocumentTextChanged(editor, e);

            if (_allFilter == null || _suggestedFilter == null)
            {
                return;
            }

            if (Selection != null && Selection.State == CompletionSelectionState.Partial && _suggestedFilter.IsActive)
            {
                var lowPriorityItems = Items.OfType<ISqlCompletionItem>().Where(x => !x.IsHighPriority).ToList();
                foreach (var matcher in ItemMatchers)
                {
                    var completionSelection = matcher.Match(this, lowPriorityItems, TypedText, false);
                    if (completionSelection != null && completionSelection.State == CompletionSelectionState.Full)
                    {
                        ActivateAllFilter();
                        Selection = completionSelection;
                        return;
                    }
                }
            }
        }

        protected override IntelliPromptCompletionList CreatePopupContent()
        {
            _list = base.CreatePopupContent();
            return _list;
        }

        private void ActivateAllFilter()
        {
            var border = _list.FilterElement as Border;
            if (border != null)
            {
                var child = border.Child as ListBox;
                if (child != null)
                {
                    for (var i = child.Items.Count - 1; i >= 0; i--)
                    {
                        var item = child.Items[i] as ListBoxItem;
                        if (item != null && item.Tag == _allFilter)
                        {
                            child.SelectedItem = item;
                            break;
                        }
                    }
                }
            }
        }
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.