private void richTextBox_PreviewKeyUp(object sender, KeyEventArgs e) { if (((e.Key != Key.Up) && (e.Key != Key.Down)) && ((e.Key != Key.Space) || !this.IgnorePrefix)) { if ((e.Key == Key.Space) || (e.Key == Key.Escape)) { this.HideMethodsPopup(); } if (((((e.Key == Key.Escape) || (e.Key == Key.Left)) || ((e.Key == Key.Right) || (e.Key == Key.Return))) || ((this.IgnorePrefix && (e.Key == Key.D2)) && (Keyboard.Modifiers == ModifierKeys.Shift))) || this.ignoreDisplay) { this.HideMethodsPopup(); this.ignoreDisplay = false; } else { IEnumerable<IntellisenseItem> results = null; string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text; int startIndex = text.LastIndexOf(' '); string input = (startIndex != -1) ? text.Substring(startIndex).TrimStart(new char[0]) : text.TrimStart(new char[0]); if (((input == "@") || (input == "#")) && this.IgnorePrefix) { this.HideMethodsPopup(); this.ignoreDisplay = false; } else if (!(this.ExcludeMentions || (((input != "@") && !input.EndsWith("@")) && !(text == "d ")))) { results = IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.GetMatches("@"); Rect rect = this.richTextBox.CaretPosition.GetCharacterRect(LogicalDirection.Forward); this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.ContainsEntries, delegate { this.ShowMethodsPopup(rect, this.richTextBox); this.intellisenseListBox.SelectedIndex = -1; }); } else if ((input == "#") || input.EndsWith("#")) { results = IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.GetMatches("#"); Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward); this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.ContainsEntries, delegate { this.ShowMethodsPopup(rect, this.richTextBox); this.intellisenseListBox.SelectedIndex = -1; }); } else if (!(this.ExcludeMentions || (!MENTION_EXPRESSION.IsMatch(input) && !this.IgnorePrefix))) { string currentWordExcludingPrefix = string.Empty; currentWordExcludingPrefix = this.IgnorePrefix ? input : MENTION_EXPRESSION.Match(input).Groups[1].Value; results = IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.GetMatches(currentWordExcludingPrefix); Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward); this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.ContainsEntries, delegate { this.ShowMethodsPopup(rect, this.richTextBox); this.SetSelection(currentWordExcludingPrefix); }); } else if (!((this.ExcludeMentions || !DM_EXPRESSION.IsMatch(text)) || DM_EXPRESSION_WITH_END_SPACE.IsMatch(text))) { string currentWordExcludingPrefix = DM_EXPRESSION.Match(text).Groups[1].Value; results = IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.GetMatches(currentWordExcludingPrefix); Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward); this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.ContainsEntries, delegate { this.ShowMethodsPopup(rect, this.richTextBox); this.SetSelection(currentWordExcludingPrefix); }); } else if (TAG_EXPRESSION.IsMatch(input)) { string partialWord = TAG_EXPRESSION.Match(input).Groups[1].Value; results = IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.GetMatches(partialWord); Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward); this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.ContainsEntries, delegate { this.ShowMethodsPopup(rect, this.richTextBox); this.intellisenseListBox.SelectedIndex = -1; }); } else { this.HideMethodsPopup(); } } } }
private void InsertSelectedEntry(char characterInsertion) { if (this.intellisenseListBox.SelectedIndex <= -1 || !this.intellisensePopup.IsOpen) return; string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text; int startIndex = text.LastIndexOf(' '); string currentWord = startIndex != -1 ? text.Substring(startIndex).TrimStart(new char[0]) : text.TrimStart(new char[0]); IntellisenseItem intellisenseItem = this.intellisenseListBox.SelectedItem as IntellisenseItem; bool flag = text.StartsWith("d ", StringComparison.InvariantCultureIgnoreCase) && !IntellisenseAdorner.DM_EXPRESSION_WITH_END_SPACE.IsMatch(text); string textData = this.IgnorePrefix || flag ? intellisenseItem.FilterValue : intellisenseItem.DisplayValue; if (textData.StartsWith("@") || textData.StartsWith("#")) { int charactersToDelete = IntellisenseAdorner.GetNumberOfCharactersToDelete(currentWord, textData.StartsWith("@") ? "@" : "#"); if (currentWord.EndsWith(" ")) this.richTextBox.CaretPosition.DeleteTextInRun(-(charactersToDelete - 1)); else this.richTextBox.CaretPosition.DeleteTextInRun(-charactersToDelete); } else if (currentWord.EndsWith(" ")) this.richTextBox.CaretPosition.DeleteTextInRun(-(currentWord.Length - 1)); else this.richTextBox.CaretPosition.DeleteTextInRun(-currentWord.Length); if ((int)characterInsertion != 0 && !this.IgnorePrefix) textData = textData + (object)characterInsertion; this.richTextBox.CaretPosition = this.richTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward) ?? this.richTextBox.CaretPosition; if (!flag) { this.richTextBox.CaretPosition.InsertTextInRun(textData); } else { this.richTextBox.CaretPosition.InsertTextInRun(textData); Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)intellisenseItem.FilterValue), (object)CommonCommands.MultiAccountifyToken((Enum)ViewModelMessages.DirectMessage, intellisenseItem.TwitterAccountID)); } this.ignoreDisplay = true; }