private void TextArea_PreviewKeyDown(object sender, KeyEventArgs e) { e.Handled = true; if (this.IntelliSensePopup.IsOpen) { if (Keyboard.IsKeyDown(Key.Tab) || Keyboard.IsKeyDown(Key.Enter)) { this.Editor.Document.Insert(this.Editor.CaretOffset, this.IntelliSenseEntrySelected.ContentToFinish); this.IntelliSensePopup.IsOpen = false; } else if (Keyboard.IsKeyDown(Key.Up)) { var index = this.IntelliSenseEntries.IndexOf(this.IntelliSenseEntrySelected) - 1; this.IntelliSenseEntrySelected = this.IntelliSenseEntries.ElementAt(index < 0 ? 0 : index); } else if (Keyboard.IsKeyDown(Key.Down)) { var index = this.IntelliSenseEntries.IndexOf(this.IntelliSenseEntrySelected) + 1; this.IntelliSenseEntrySelected = this.IntelliSenseEntries.ElementAt(index >= this.IntelliSenseEntries.Count ? this.IntelliSenseEntries.Count - 1 : index); } else { this.IntelliSensePopup.IsOpen = false; e.Handled = false; } } else { e.Handled = false; } }
private void ShowIntelliSense() { if (this.Editor == null) { return; } string curWord = this.Editor.Document.GetWordAround(this.Editor.CaretOffset - 1); this.IntelliSenseEntries = this.GetIntelliSenseEntries(this.Document, curWord, this.Editor.CaretOffset); this.IntelliSenseEntrySelected = this.IntelliSenseEntries.FirstOrDefault(); if (this.IntelliSenseEntries.Count > 0) { this.IntelliSensePopup.DataContext = this; var pos = this.Editor.TextArea.TextView.GetVisualPosition(this.Editor.TextArea.Caret.Position, ICSharpCode.AvalonEdit.Rendering.VisualYPosition.TextBottom); this.IntelliSensePopup.PlacementTarget = this.Editor; this.IntelliSensePopup.Placement = PlacementMode.Relative; this.IntelliSensePopup.HorizontalOffset = pos.X + 10 + 18 * 2; this.IntelliSensePopup.VerticalOffset = pos.Y; this.IntelliSensePopup.IsOpen = true; } }