コード例 #1
0
        private void KeydownEventHandler(object sender, IControlHtmlEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }

            LogTo.Debug("Handling key down");
            var ev = e?.EventObj;

            if (ev == null)
            {
                return;
            }

            if (CurrentPopup == null || !CurrentPopup.IsOpen())
            {
                return;
            }

            var info = new HtmlKeyInfo(ev);

            if (info.Key == Keys.None)
            {
                return;
            }

            if (info.Key == Keys.Escape)
            {
                CurrentPopup?.Hide();
                ev.returnValue = false;
            }
            else if ((info.Key == Keys.Up && info.Modifiers == KeyModifiers.None) ||
                     (info.Key == Keys.K && info.Modifiers == KeyModifiers.Ctrl))
            {
                CurrentPopup?.SelectPreviousItem();
                ev.returnValue = false;
            }
            else if ((info.Key == Keys.Down && info.Modifiers == KeyModifiers.None) ||
                     (info.Key == Keys.J && info.Modifiers == KeyModifiers.Ctrl))
            {
                CurrentPopup?.SelectNextItem();
                ev.returnValue = false;
            }
            else if ((info.Key == Keys.Right && info.Modifiers == KeyModifiers.None) ||
                     info.Key == Keys.Tab)
            {
                CurrentPopup?.InsertSelectedItem();
                ev.returnValue = false;
            }
        }
コード例 #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);
            }
        }