Ejemplo n.º 1
0
        private void ShowNewAutocompleteWdw(IEnumerable <string> matches, string lastWord)
        {
            System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() =>
            {
                try
                {
                    var wdw = ContentUtils.GetFocusedHtmlWindow() as IHTMLWindow4;
                    var htmlDoc = ((IHTMLWindow2)wdw)?.document;
                    if (wdw == null || htmlDoc == null)
                    {
                        return;
                    }

                    LogTo.Debug("Creating and showing a new Autocomplete popup");
                    CurrentPopup = wdw.CreatePopup();
                    CurrentPopup.Show(matches, lastWord);
                }
                catch (UnauthorizedAccessException) { }
                catch (RemotingException) { }
            }));
        }
Ejemplo n.º 2
0
        private void HandleKeyUp(HtmlKeyInfo info)
        {
            if (!Enabled)
            {
                return;
            }

            if (info.Key == Keys.None || info.Modifiers != KeyModifiers.None || info.Key == Keys.Escape)
            {
                return;
            }

            if ((info.Key == Keys.Up) ||
                info.Key == Keys.Right ||
                info.Key == Keys.Down ||
                (info.Key == Keys.J && info.Modifiers == KeyModifiers.Ctrl) ||
                (info.Key == Keys.K && info.Modifiers == KeyModifiers.Ctrl))
            {
                LogTo.Debug("KeyUp: Ignoring because it was an arrow key.");
                return;
            }
            else if (info.Key == Keys.Escape)
            {
                LogTo.Debug("KeyUp: Escape pressed, closing popup");
                CurrentPopup?.Hide();
                return;
            }

            var selObj = ContentUtils.GetSelectionObject();

            if (selObj == null || !string.IsNullOrEmpty(selObj.text))
            {
                return;
            }

            var lastWord = ContentUtils.GetLastPartialWord(selObj);

            if (lastWord == null || string.IsNullOrEmpty(lastWord))
            {
                CurrentPopup?.Hide();
                return;
            }

            var matches = CurrentSuggestions.GetWords(lastWord);

            if (matches == null || !matches.Any())
            {
                CurrentPopup?.Hide();
                return;
            }

            if (matches.Count() == 1 && matches.First() == lastWord)
            {
                CurrentPopup?.Hide();
                return;
            }

            if (CurrentPopup == null)
            {
                ShowNewAutocompleteWdw(matches, lastWord);
            }
            else
            {
                CurrentPopup?.Show(matches, lastWord);
            }
        }