private void btnHighlightAll_Click(object sender, EventArgs e) { if (!_highlightGroups.ContainsKey(Editor)) { _highlightGroups[Editor] = new HighlightGroup(Editor); } HighlightGroup group = _highlightGroups[Editor]; if (string.IsNullOrEmpty(LookFor)) { // Clear highlights group.ClearMarkers(); } else { _search.LookFor = txtLookFor.Text; _search.MatchCase = chkMatchCase.Checked; _search.MatchWholeWordOnly = chkMatchWholeWord.Checked; bool looped = false; int offset = 0, count = 0; for (;;) { TextRange range = _search.FindNext(offset, false, out looped); if (range == null || looped) { break; } offset = range.Offset + range.Length; count++; var m = new TextMarker(range.Offset, range.Length, TextMarkerType.SolidBlock, Color.Yellow, Color.Black); group.AddMarker(m); } if (count == 0) { MessageBox.Show("Search text not found."); } else { Close(); } } }
public void ShowFor(frmMain frm, bool replaceMode) { _frm = frm; _search.ClearScanRegion(); _search.Document = Editor.Document; if (_highlightGroups.ContainsKey(Editor)) { HighlightGroup group = _highlightGroups[Editor]; group.ClearMarkers(); } var sm = Editor.ActiveTextAreaControl.SelectionManager; if (sm.HasSomethingSelected && sm.SelectionCollection.Count == 1) { var sel = sm.SelectionCollection[0]; if (sel.StartPosition.Line == sel.EndPosition.Line) { txtLookFor.Text = sm.SelectedText; } else { _search.SetScanRegion(sel); } } else { // Get the current word that the caret is on Caret caret = Editor.ActiveTextAreaControl.Caret; int start = TextUtilities.FindWordStart(Editor.Document, caret.Offset); int endAt = TextUtilities.FindWordEnd(Editor.Document, caret.Offset); txtLookFor.Text = Editor.Document.GetText(start, endAt - start); } ReplaceMode = replaceMode; this.Owner = (Form)Editor.TopLevelControl; this.Show(); txtLookFor.SelectAll(); txtLookFor.Focus(); }