public void OnTextInput(TextInputEventArgs e, int caretIndex, int line, int column)
        {
            if (e.Source == editor)
            {
                intellisenseJobRunner.InvokeAsync(() =>
                {
                    if (e.Text.Length == 1)
                    {
                        char currentChar = e.Text[0];

                        if (completionAssistant.IsVisible)
                        {
                            if (caretIndex < completionAssistant.CurrentSignatureHelp.Offset)
                            {
                                Dispatcher.UIThread.InvokeTaskAsync(() =>
                                {
                                    completionAssistant.PopMethod();
                                }).Wait();
                            }

                            if (completionAssistant.CurrentSignatureHelp != null)
                            {
                                int index = 0;
                                int level = 0;
                                int offset = completionAssistant.CurrentSignatureHelp.Offset;

                                while (offset < caretIndex)
                                {
                                    var curChar = '\0';

                                    Dispatcher.UIThread.InvokeTaskAsync(() =>
                                    {
                                        curChar = editor.TextDocument.GetCharAt(offset++);
                                    }).Wait();

                                    switch (curChar)
                                    {
                                        case ',':
                                            if (level == 0)
                                            {
                                                index++;
                                            }
                                            break;

                                        case '(':
                                            level++;
                                            break;

                                        case ')':
                                            level--;
                                            break;
                                    }
                                }

                                completionAssistant.SetParameterIndex(index);
                            }
                        }

                        if (currentChar == '(' && (completionAssistant.CurrentSignatureHelp == null || completionAssistant.CurrentSignatureHelp.Offset != editor.CaretIndex))
                        {
                            string currentWord = string.Empty;

                            char behindBehindCaretChar = '\0';

                            Dispatcher.UIThread.InvokeTaskAsync(() =>
                            {
                                behindBehindCaretChar = editor.TextDocument.GetCharAt(caretIndex - 2);
                            }).Wait();

                            if (behindBehindCaretChar.IsWhiteSpace() && behindBehindCaretChar != '\0')
                            {
                                Dispatcher.UIThread.InvokeTaskAsync(() =>
                                {
                                    currentWord = editor.GetPreviousWordAtIndex(editor.CaretIndex - 1);
                                }).Wait();
                            }
                            else
                            {
                                Dispatcher.UIThread.InvokeTaskAsync(() =>
                                {
                                    currentWord = editor.GetWordAtIndex(editor.CaretIndex - 1);
                                }).Wait();
                            }

                            var signatureHelpTask = languageService.SignatureHelp(file, EditorModel.UnsavedFiles.FirstOrDefault(), EditorModel.UnsavedFiles.ToList(), line, column, editor.CaretIndex, currentWord);
                            signatureHelpTask.Wait();

                            var signatureHelp = signatureHelpTask.Result;

                            if (signatureHelp != null)
                            {
                                Dispatcher.UIThread.InvokeTaskAsync(() =>
                                {
                                    completionAssistant.PushMethod(signatureHelp);
                                }).Wait();
                            }
                        }
                        else if (currentChar == ')')
                        {
                            Dispatcher.UIThread.InvokeTaskAsync(() =>
                            {
                                completionAssistant.PopMethod();
                            }).Wait();
                        }

                        if (IsCompletionChar(currentChar))
                        {
                            DoComplete(true);
                        }

                        if (currentChar.IsWhiteSpace() || IsSearchChar(currentChar))
                        {
                            SetCursor(caretIndex, line, column, EditorModel.UnsavedFiles.ToList(), false);
                        }

                        if (IsTriggerChar(currentChar, intellisenseControl.IsVisible) || IsLanguageSpecificTriggerChar(currentChar))
                        {
                            if (!intellisenseControl.IsVisible)
                            {
                                OpenIntellisense(currentChar, caretIndex);
                            }
                            else if (caretIndex > intellisenseStartedAt)
                            {
                                UpdateFilter(caretIndex);
                            }
                            else
                            {
                                CloseIntellisense();
                                SetCursor(caretIndex, line, column, EditorModel.UnsavedFiles.ToList(), false);
                            }

                            isProcessingKey = intellisenseControl.IsVisible;
                        }
                    }
                });
            }
        }
 protected override void OnTextInput(TextInputEventArgs e)
 {
     HandleTextInput(e.Text);
 }
Exemple #3
0
 /// <summary>
 /// Called before the <see cref="TextInput"/> event occurs.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnTextInput(TextInputEventArgs e)
 {
 }
        private void ProcessRawEvent(RawInputEventArgs e)
        {
            IInputElement element = FocusedElement;

            if (element != null)
            {
                var keyInput = e as RawKeyEventArgs;

                if (keyInput != null)
                {
                    switch (keyInput.Type)
                    {
                        case RawKeyEventType.KeyDown:
                        case RawKeyEventType.KeyUp:
                            var routedEvent = keyInput.Type == RawKeyEventType.KeyDown
                                ? InputElement.KeyDownEvent
                                : InputElement.KeyUpEvent;

                            KeyEventArgs ev = new KeyEventArgs
                            {
                                RoutedEvent = routedEvent,
                                Device = this,
                                Key = keyInput.Key,
                                Modifiers = keyInput.Modifiers,
                                Source = element,
                            };

                            IVisual currentHandler = element;
                            while (currentHandler != null && !ev.Handled && keyInput.Type == RawKeyEventType.KeyDown)
                            {
                                var bindings = (currentHandler as IInputElement)?.KeyBindings;
                                if(bindings!=null)
                                    foreach (var binding in bindings)
                                    {
                                        if(ev.Handled)
                                            break;
                                        binding.TryHandle(ev);
                                    }
                                currentHandler = currentHandler.VisualParent;
                            }

                            element.RaiseEvent(ev);
                            e.Handled = ev.Handled;
                            break;
                    }
                }

                var text = e as RawTextInputEventArgs;

                if (text != null)
                {
                    var ev = new TextInputEventArgs()
                    {
                        Device = this,
                        Text = text.Text,
                        Source = element,
                        RoutedEvent = InputElement.TextInputEvent
                    };

                    element.RaiseEvent(ev);
                    e.Handled = ev.Handled;
                }
            }
        }
        /// <summary>
        /// Handles a key being pressed in the menu.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnTextInput(object sender, TextInputEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(e.Text))
            {
                var text = e.Text.ToUpper();
                var focus = _registered
                    .FirstOrDefault(x => x.Item1 == text && x.Item2.IsEffectivelyVisible)?.Item2;

                focus?.RaiseEvent(new RoutedEventArgs(AccessKeyHandler.AccessKeyPressedEvent));

                e.Handled = true;
            }
        }