private void FindNextMatch(int startIndex, string searchString, bool reverse) { if (_gridView.RowCount == 0) { return; } var matchIndex = reverse ? SearchBackwards() : SearchForward(); if (matchIndex.HasValue) { _label.ForeColor = SystemColors.InfoText; // Prevent flickering when further typing is selecting the same row if (_gridView.SelectedRows.Count != 1 || _gridView.SelectedRows[0].Index != matchIndex) { using (WaitCursorScope.Enter()) { _gridView.ClearSelection(); _gridView.Rows[matchIndex.Value].Selected = true; _gridView.CurrentCell = _gridView.Rows[matchIndex.Value].Cells[1]; } } } else { _label.ForeColor = Color.DarkRed; } int?SearchForward() { // Check for out of bounds roll over if required int index; if (startIndex < 0 || startIndex >= _gridView.RowCount) { startIndex = 0; } for (index = startIndex; index < _gridView.RowCount; ++index) { if (_gitRevisionTester.Matches(_gridView.GetRevision(index), searchString)) { return(index); } } // We didn't find it so start searching from the top for (index = 0; index < startIndex; ++index) { if (_gitRevisionTester.Matches(_gridView.GetRevision(index), searchString)) { return(index); } } return(null); } int?SearchBackwards() { // Check for out of bounds roll over if required int index; if (startIndex < 0 || startIndex >= _gridView.RowCount) { startIndex = _gridView.RowCount - 1; } for (index = startIndex; index >= 0; --index) { if (_gitRevisionTester.Matches(_gridView.GetRevision(index), searchString)) { return(index); } } // We didn't find it so start searching from the bottom for (index = _gridView.RowCount - 1; index > startIndex; --index) { if (_gitRevisionTester.Matches(_gridView.GetRevision(index), searchString)) { return(index); } } return(null); } }
public void Matches_should_not_throw_if_revsion_null() { _tester.Matches(null, null).Should().BeFalse(); }