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; } } }); } }
/// <summary> /// Called before the <see cref="TextInput"/> event occurs. /// </summary> /// <param name="e">The event args.</param> protected virtual void OnTextInput(TextInputEventArgs e) { }
/// <summary> /// Processes an input event. /// </summary> /// <param name="e">The input event arguments.</param> 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; } } }
public void ProcessRawEvent(RawInputEventArgs e) { if (e.Handled) { return; } var element = FocusedElement ?? e.Root; if (e is RawKeyEventArgs keyInput) { 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, KeyModifiers = KeyModifiersUtils.ConvertToKey(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) { KeyBinding[]? bindingsCopy = null; // Create a copy of the KeyBindings list if there's a binding which matches the event. // If we don't do this the foreach loop will throw an InvalidOperationException when the KeyBindings list is changed. // This can happen when a new view is loaded which adds its own KeyBindings to the handler. foreach (var binding in bindings) { if (binding.Gesture?.Matches(ev) == true) { bindingsCopy = bindings.ToArray(); break; } } if (bindingsCopy is object) { foreach (var binding in bindingsCopy) { if (ev.Handled) { break; } binding.TryHandle(ev); } } } currentHandler = currentHandler.VisualParent; } element.RaiseEvent(ev); e.Handled = ev.Handled; break; } } if (e is RawTextInputEventArgs text) { var ev = new TextInputEventArgs() { Device = this, Text = text.Text, Source = element, RoutedEvent = InputElement.TextInputEvent }; element.RaiseEvent(ev); e.Handled = ev.Handled; } }
protected override void OnTextInput(TextInputEventArgs e) { HandleTextInput(e.Text); }
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; } } }
public void ProcessRawEvent(RawInputEventArgs e) { if (e.Handled) { return; } var element = FocusedElement ?? e.Root; if (e is RawKeyEventArgs keyInput) { 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, KeyModifiers = KeyModifiersUtils.ConvertToKey(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; } } if (e is RawTextInputEventArgs text) { 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; } }