public override void Run() { ITextEditor textArea = SearchReplaceUtilities.GetActiveTextEditor(); if (textArea == null) { return; } // Determine what text we should search for. string textToFind; string selectedText = textArea.SelectedText; if (selectedText.Length > 0) { if (Find.IsMultipleLines(selectedText)) { // Locate the nearest word at the selection start. textToFind = textArea.Document.GetWordAt(textArea.SelectionStart); } else { // Search for selected text. textToFind = selectedText; } } else { textToFind = textArea.Document.GetWordAt(textArea.Caret.Offset); } if (textToFind != null && textToFind.Length > 0) { SearchOptions.CurrentFindPattern = textToFind; if (SearchOptions.DocumentIteratorType == DocumentIteratorType.CurrentSelection) { SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument; } SearchReplaceManager.FindNext(null); } }