public bool IntersectsWith(Range otherRange) { return otherRange.PositionInRange(this._start) | otherRange.PositionInRange(this._end) | this.PositionInRange(otherRange.Start) | this.PositionInRange(otherRange.End); }
public Range Find(Range rangeToSearch, string searchString, SearchFlags searchflags, bool searchUp) { if (searchUp) return Find(rangeToSearch.End, rangeToSearch.Start, searchString, searchflags); else return Find(rangeToSearch.Start, rangeToSearch.End, searchString, searchflags); }
private string ReplaceAllEvaluator(Match m) { // So this method is called for every match // We make a replacement in the range based upon // the match range. string replacement = m.Result(_lastReplaceAllReplaceString); int start = _lastReplaceAllRangeToSearch.Start + m.Index + _lastReplaceAllOffset; int end = start + m.Length; Range r = new Range(start, end, Scintilla); _lastReplaceAllMatches.Add(r); r.Text = replacement; // But because we've modified the document, the RegEx // match ranges are going to be different from the // document ranges. We need to compensate _lastReplaceAllOffset += replacement.Length - m.Value.Length; return replacement; }
public Range Search(Range searchRange, Range startingAfterRange) { int start = startingAfterRange.End; if (start > NativeScintilla.GetTextLength()) return null; int foundStart = NativeScintilla.IndicatorEnd(this._number, start); int foundEnd = NativeScintilla.IndicatorEnd(this._number, foundStart); if (foundStart < 0 || foundStart > searchRange.End || foundStart == foundEnd) return null; return new Range(foundStart, foundEnd, Scintilla); }
public Range FindPrevious(Regex findExpression, bool wrap, Range searchRange) { int caret = Scintilla.Caret.Position; if (!searchRange.PositionInRange(caret)) return Find(searchRange.Start, searchRange.End, findExpression, true); int anchor = Scintilla.Caret.Anchor; if (!searchRange.PositionInRange(anchor)) anchor = caret; Range r = Find(searchRange.Start, anchor, findExpression, true); if (r != null) return r; else if (wrap) return Find(anchor, searchRange.End, findExpression, true); else return null; }
public List<Range> ReplaceAll(Range rangeToSearch, Regex findExpression, string replaceString) { Scintilla.UndoRedo.BeginUndoAction(); // I tried using an anonymous delegate for this but it didn't work too well. // It's too bad because it was a lot cleaner than using member variables as // psuedo globals. _lastReplaceAllMatches = new List<Range>(); _lastReplaceAllReplaceString = replaceString; _lastReplaceAllRangeToSearch = rangeToSearch; _lastReplaceAllOffset = 0; findExpression.Replace(rangeToSearch.Text, new MatchEvaluator(ReplaceAllEvaluator)); Scintilla.UndoRedo.EndUndoAction(); // No use having these values hanging around wasting memory :) List<Range> ret = _lastReplaceAllMatches; _lastReplaceAllMatches = null; _lastReplaceAllReplaceString = null; _lastReplaceAllRangeToSearch = null; return ret; }
private void btnFindAll_Click(object sender, EventArgs e) { if (this.cboFindF.Text == string.Empty) return; this.AddFindMru(); this.lblStatus.Text = string.Empty; List<Range> foundRanges = null; if (this.rdoRegexF.Checked) { Regex rr = null; try { rr = new Regex(this.cboFindF.Text, this.GetRegexOptions()); } catch (ArgumentException ex) { this.lblStatus.Text = "Error in Regular Expression: " + ex.Message; return; } if (this.chkSearchSelectionF.Checked) { if (this._searchRange == null) { this._searchRange = this.Scintilla.Selection.Range; } foundRanges = this.Scintilla.FindReplace.FindAll(this._searchRange, rr); } else { this._searchRange = null; foundRanges = this.Scintilla.FindReplace.FindAll(rr); } } else { if (this.chkSearchSelectionF.Checked) { if (this._searchRange == null) this._searchRange = this.Scintilla.Selection.Range; foundRanges = this.Scintilla.FindReplace.FindAll(this._searchRange, this.cboFindF.Text, this.GetSearchFlags()); } else { this._searchRange = null; foundRanges = this.Scintilla.FindReplace.FindAll(this.cboFindF.Text, this.GetSearchFlags()); } } this.lblStatus.Text = "Total found: " + foundRanges.Count.ToString(); this.btnClear_Click(null, null); if (this.chkMarkLine.Checked) this.Scintilla.FindReplace.MarkAll(foundRanges); if (this.chkHighlightMatches.Checked) this.Scintilla.FindReplace.HighlightAll(foundRanges); }
public Range FindNext(Regex findExpression, bool wrap, Range searchRange) { int caret = Scintilla.Caret.Position; if (!searchRange.PositionInRange(caret)) return Find(searchRange.Start, searchRange.End, findExpression, false); Range r = Find(caret, searchRange.End, findExpression); if (r != null) return r; else if (wrap) return Find(searchRange.Start, caret, findExpression); else return null; }
public List<Range> ReplaceAll(Range rangeToSearch, string searchString, string replaceString) { return this.ReplaceAll(rangeToSearch.Start, rangeToSearch.End, searchString, replaceString, this._flags); }
protected override void OnActivated(EventArgs e) { if (this.Scintilla.Selection.Length > 0) { this.chkSearchSelectionF.Enabled = true; this.chkSearchSelectionR.Enabled = true; } else { this.chkSearchSelectionF.Enabled = false; this.chkSearchSelectionR.Enabled = false; this.chkSearchSelectionF.Checked = false; this.chkSearchSelectionR.Checked = false; } // if they leave the dialog and come back any "Search Selection" // range they might have had is invalidated this._searchRange = null; this.lblStatus.Text = string.Empty; this.MoveFormAwayFromSelection(); base.OnActivated(e); }
public List<Range> FindAll(Range rangeToSearch, string searchString) { return this.FindAll(rangeToSearch.Start, rangeToSearch.End, searchString, this._flags); }
public Range Find(Range rangeToSearch, string searchString, bool searchUp) { if (searchUp) return this.Find(rangeToSearch.End, rangeToSearch.Start, searchString, this._flags); else return this.Find(rangeToSearch.Start, rangeToSearch.End, searchString, this._flags); }
public Range Find(Range rangeToSearch, string searchString) { return this.Find(rangeToSearch.Start, rangeToSearch.End, searchString, this._flags); }
public List<Range> FindAll(Range rangeToSearch, Regex findExpression) { List<Range> res = new List<Range>(); while (true) { Range r = Find(rangeToSearch, findExpression); if (r == null) { break; } else { res.Add(r); rangeToSearch = new Range(r.End, rangeToSearch.End, Scintilla); } } return res; }
private void btnReplaceAll_Click(object sender, EventArgs e) { if (this.cboFindR.Text == string.Empty) return; this.lblStatus.Text = string.Empty; List<Range> foundRanges = null; if (this.rdoRegexR.Checked) { Regex rr = null; try { rr = new Regex(this.cboFindR.Text, this.GetRegexOptions()); } catch (ArgumentException ex) { this.lblStatus.Text = "Error in Regular Expression: " + ex.Message; return; } if (this.chkSearchSelectionR.Checked) { if (this._searchRange == null) { this._searchRange = this.Scintilla.Selection.Range; } foundRanges = this.Scintilla.FindReplace.ReplaceAll(this._searchRange, rr, this.cboReplace.Text); } else { this._searchRange = null; foundRanges = this.Scintilla.FindReplace.ReplaceAll(rr, this.cboReplace.Text); } } else { if (this.chkSearchSelectionR.Checked) { if (this._searchRange == null) this._searchRange = this.Scintilla.Selection.Range; foundRanges = this.Scintilla.FindReplace.ReplaceAll(this._searchRange, this.cboFindR.Text, this.cboReplace.Text, this.GetSearchFlags()); } else { this._searchRange = null; foundRanges = this.Scintilla.FindReplace.ReplaceAll(this.cboFindR.Text, this.cboReplace.Text, this.GetSearchFlags()); } } this.lblStatus.Text = "Total Replaced: " + foundRanges.Count.ToString(); }
public List<Range> FindAll(Range rangeToSearch, string searchString, SearchFlags flags) { return FindAll(rangeToSearch.Start, rangeToSearch.End, searchString, _flags); }
private Range FindNextR(bool searchUp, ref Regex rr) { Range foundRange; if (this.rdoRegexR.Checked) { if (rr == null) rr = new Regex(this.cboFindR.Text, this.GetRegexOptions()); if (this.chkSearchSelectionR.Checked) { if (this._searchRange == null) this._searchRange = this.Scintilla.Selection.Range; if (searchUp) foundRange = this.Scintilla.FindReplace.FindPrevious(rr, this.chkWrapR.Checked, this._searchRange); else foundRange = this.Scintilla.FindReplace.FindNext(rr, this.chkWrapR.Checked, this._searchRange); } else { this._searchRange = null; if (searchUp) foundRange = this.Scintilla.FindReplace.FindPrevious(rr, this.chkWrapR.Checked); else foundRange = this.Scintilla.FindReplace.FindNext(rr, this.chkWrapR.Checked); } } else { if (this.chkSearchSelectionF.Checked) { if (this._searchRange == null) this._searchRange = this.Scintilla.Selection.Range; if (searchUp) foundRange = this.Scintilla.FindReplace.FindPrevious(this.cboFindR.Text, this.chkWrapR.Checked, this.GetSearchFlags(), this._searchRange); else foundRange = this.Scintilla.FindReplace.FindNext(this.cboFindR.Text, this.chkWrapR.Checked, this.GetSearchFlags(), this._searchRange); } else { this._searchRange = null; if (searchUp) foundRange = this.Scintilla.FindReplace.FindPrevious(this.cboFindR.Text, this.chkWrapF.Checked, this.GetSearchFlags()); else foundRange = this.Scintilla.FindReplace.FindNext(this.cboFindR.Text, this.chkWrapF.Checked, this.GetSearchFlags()); } } return foundRange; }
public Range FindNext(string searchString, bool wrap, SearchFlags flags, Range searchRange) { int caret = Scintilla.Caret.Position; if (!searchRange.PositionInRange(caret)) return Find(searchRange.Start, searchRange.End, searchString, flags); Range r = Find(caret, searchRange.End, searchString, flags); if (r != null) return r; else if (wrap) return Find(searchRange.Start, caret, searchString, flags); else return null; }
protected internal ManagedRange(Range range) : this(range.Start, range.End, range.Scintilla) { }
public Range FindPrevious(string searchString, bool wrap, SearchFlags flags, Range searchRange) { int caret = Scintilla.Caret.Position; if (!searchRange.PositionInRange(caret)) return Find(searchRange.End, searchRange.Start, searchString, flags); int anchor = Scintilla.Caret.Anchor; if (!searchRange.PositionInRange(anchor)) anchor = caret; Range r = Find(anchor, searchRange.Start, searchString, flags); if (r != null) return r; else if (wrap) return Find(searchRange.End, anchor, searchString, flags); else return null; }
public Range Find(Range r, Regex findExpression) { return Find(r, findExpression, false); }
public List<Range> ReplaceAll(Range rangeToSearch, string searchString, string replaceString, SearchFlags flags) { return ReplaceAll(rangeToSearch.Start, rangeToSearch.End, searchString, replaceString, _flags); }
public Range Find(Range r, Regex findExpression, bool searchUp) { // Single line and Multi Line in RegExp doesn't really effect // whether or not a match will include newline charaters. This // means we can't do a line by line search. We have to search // the entire range becuase it could potentially match the // entire range. Match m = findExpression.Match(r.Text); if (!m.Success) return null; if (searchUp) { // Since we can't search backwards with RegExp we // have to search the entire string and return the // last match. Not the most efficient way of doing // things but it works. Range range = null; while (m.Success) { range = new Range(r.Start + m.Index, r.Start + m.Index + m.Length, Scintilla); m = m.NextMatch(); } return range; } return new Range(r.Start + m.Index, r.Start + m.Index + m.Length, Scintilla); }
public Range Search(Range searchRange) { int foundStart = NativeScintilla.IndicatorEnd(this._number, searchRange.Start); int foundEnd = NativeScintilla.IndicatorEnd(this._number, foundStart); if (foundStart < 0 || foundStart > searchRange.End || foundStart == foundEnd) return null; return new Range(foundStart, foundEnd, Scintilla); }
public Range Find(Range rangeToSearch, string searchString, SearchFlags searchflags) { return Find(rangeToSearch.Start, rangeToSearch.End, searchString, searchflags); }
public List<Range> SearchAll(Range searchRange) { Range foundRange = Scintilla.GetRange(-1, -1); var ret = new List<Range>(); do { foundRange = this.Search(searchRange, foundRange); if (foundRange != null) ret.Add(foundRange); } while (foundRange != null); return ret; }
private Range FindNextF(bool searchUp) { Range foundRange; if (rdoRegexF.Checked) { Regex rr = new Regex(cboFindF.Text, GetRegexOptions()); if (chkSearchSelectionF.Checked) { if (_searchRange == null) _searchRange = Scintilla.Selection.Range; if (searchUp) foundRange = Scintilla.FindReplace.FindPrevious(rr, chkWrapF.Checked, _searchRange); else foundRange = Scintilla.FindReplace.FindNext(rr, chkWrapF.Checked, _searchRange); } else { _searchRange = null; if (searchUp) foundRange = Scintilla.FindReplace.FindPrevious(rr, chkWrapF.Checked); else foundRange = Scintilla.FindReplace.FindNext(rr, chkWrapF.Checked); } } else { if (chkSearchSelectionF.Checked) { if (_searchRange == null) _searchRange = Scintilla.Selection.Range; if (searchUp) foundRange = Scintilla.FindReplace.FindPrevious(cboFindF.Text, chkWrapF.Checked, GetSearchFlags(), _searchRange); else foundRange = Scintilla.FindReplace.FindNext(cboFindF.Text, chkWrapF.Checked, GetSearchFlags(), _searchRange); } else { _searchRange = null; if (searchUp) foundRange = Scintilla.FindReplace.FindPrevious(cboFindF.Text, chkWrapF.Checked, GetSearchFlags()); else foundRange = Scintilla.FindReplace.FindNext(cboFindF.Text, chkWrapF.Checked, GetSearchFlags()); } } return foundRange; }