コード例 #1
0
        private TextLine FindLine(int absoluteIndex)
        {
            TextLine selected = null;

            if (_currentLine != null)
            {
                if (_currentLine.Contains(absoluteIndex))
                {
                    // This index is on the last read line
                    selected = _currentLine;
                }
                else if (absoluteIndex > _currentLine.Index && _currentLine.Index + 1 < _lines.Count)
                {
                    // This index is ahead of the last read line
                    selected = ScanLines(absoluteIndex, _currentLine.Index);
                }
            }

            // Have we found a line yet?
            if (selected == null)
            {
                // Scan from line 0
                selected = ScanLines(absoluteIndex, 0);
            }

            Debug.Assert(selected == null || selected.Contains(absoluteIndex));
            _currentLine = selected;
            return(selected);
        }
コード例 #2
0
        private TextLine FindLine(int absoluteIndex)
        {
            TextLine selected = null;

            if (_currentLine == null)
            {
                // Scan from line 0
                selected = ScanLines(absoluteIndex, 0, _lines.Count);
            }
            else if (absoluteIndex >= _currentLine.End)
            {
                if (_currentLine.Index + 1 < _lines.Count)
                {
                    // This index is after the last read line
                    var nextLine = _lines[_currentLine.Index + 1];

                    // Optimization to not search if it's the common case where the line after _currentLine is being requested.
                    if (nextLine.Contains(absoluteIndex))
                    {
                        selected = nextLine;
                    }
                    else
                    {
                        selected = ScanLines(absoluteIndex, _currentLine.Index, _lines.Count);
                    }
                }
            }
            else if (absoluteIndex < _currentLine.Start)
            {
                if (_currentLine.Index > 0)
                {
                    // This index is before the last read line
                    var prevLine = _lines[_currentLine.Index - 1];

                    // Optimization to not search if it's the common case where the line before _currentLine is being requested.
                    if (prevLine.Contains(absoluteIndex))
                    {
                        selected = prevLine;
                    }
                    else
                    {
                        selected = ScanLines(absoluteIndex, 0, _currentLine.Index);
                    }
                }
            }
            else
            {
                // This index is on the last read line
                selected = _currentLine;
            }

            Debug.Assert(selected == null || selected.Contains(absoluteIndex));
            _currentLine = selected;
            return(selected);
        }