public void ResetTextCache() { cachedText = null; charsValid = false; frameValid = false; highlightRegex = null; }
public void UpdateHighlight(int index, int count) { FixRange(ref index, ref count); bool isOutFrame = index <_frameCharsIndex || index + count> _frameCharsIndex + _frameCharsCount; if (highlightRegex != ClipboardExecutor.ViRegex || isOutFrame || !frameValid) { frameValid = true; highlightRegex = ClipboardExecutor.ViRegex; matches.Clear(); if (highlightRegex != null) { int frameCharsIndex = index - count / 2; int frameCharsCount = count * 2; FixRange(ref frameCharsIndex, ref frameCharsCount); if (_frameCharsIndex != frameCharsIndex || _frameCharsCount != frameCharsCount) { _frameCharsIndex = frameCharsIndex; _frameCharsCount = frameCharsCount; _frameChars.Resize(_frameCharsCount); } if (_frameCharsCount > 0) { GetText(_frameCharsIndex, _frameCharsCount, _frameChars.buffer); } char[] chars = _frameChars.buffer; int ii = 0; while (ii < _frameCharsCount) { CharsRegularExpressions.Match match = null; try { match = highlightRegex.Match(chars, ii, _frameCharsCount - ii); } catch { } if (match == null || !match.IsMatched(0)) { break; } SimpleRange range = new SimpleRange(); range.index = _frameCharsIndex + match.Index; range.count = match.Length; matches.Add(range); ii = match.Index + (match.Length > 0 ? match.Length : 1); } } } }
public static void PutToSearch(Pattern pattern) { string text = pattern.text; if (!pattern.regex) { text = Escape(pattern.text); } registers[26] = text; if (string.IsNullOrEmpty(text)) { _viRegex = null; _viBackwardRegex = null; } else { for (int i = 0; i < 2; i++) { if (i == 1) { text = Escape(text); } try { System.TimeSpan span = new System.TimeSpan(0, 0, 0, 0, 200); CharsRegularExpressions.RegexOptions options = CharsRegularExpressions.RegexOptions.None; if (text.Length < 50) { options |= CharsRegularExpressions.RegexOptions.Compiled; } if (pattern.ignoreCase) { options |= CharsRegularExpressions.RegexOptions.IgnoreCase; } _viRegex = new CharsRegularExpressions.Regex(text, options, span); _viBackwardRegex = new CharsRegularExpressions.Regex( text, CharsRegularExpressions.RegexOptions.RightToLeft | options, span); break; } catch { _viRegex = null; _viBackwardRegex = null; } } } }