Esempio n. 1
0
        void TextBufferChanged(int position, int newLength, int dif)
        {
            int startLex = Math.Max(position - _lookahead, 0);

            EnsureLexed(Buffer.CurrentSnapshot, startLex);

            if (dif > 0)
            {
                _tokens.InsertSpace(position, dif);
            }
            else if (_tokens.Count > position)
            {
                _tokens.RemoveRange(position, Math.Min(-dif, _tokens.Count - position));
            }

            int endLex = position + newLength + _lookahead;

            endLex   = _tokens.NextHigherIndex(endLex - 1) ?? _tokens.Count;
            startLex = _tokens.NextLowerIndex(startLex + 1) ?? 0;

            _lexer = PrepareLexer(_lexer, _wrappedBuffer, startLex);
            int stoppedAt = RunLexerUntil(endLex);

            if (ClassificationChanged != null)
            {
                var span = new SnapshotSpan(Buffer.CurrentSnapshot, new Span(startLex, stoppedAt - startLex));
                ClassificationChanged(this, new ClassificationChangedEventArgs(span));
            }
        }