Ejemplo n.º 1
0
        private Task OnTextContentChangedAsync(PythonTextBufferInfo sender, TextContentChangedEventArgs e)
        {
            if (e == null)
            {
                Debug.Fail("Invalid type passed to event");
            }

            var snapshot = e.After;

            if (!snapshot.IsReplBufferWithCommand())
            {
                _tokenCache.EnsureCapacity(snapshot.LineCount);

                var tokenizer = GetTokenizer(snapshot);
                foreach (var change in e.Changes)
                {
                    if (change.LineCountDelta > 0)
                    {
                        _tokenCache.InsertLines(snapshot.GetLineNumberFromPosition(change.NewEnd) + 1 - change.LineCountDelta, change.LineCountDelta);
                    }
                    else if (change.LineCountDelta < 0)
                    {
                        _tokenCache.DeleteLines(snapshot.GetLineNumberFromPosition(change.NewEnd) + 1, -change.LineCountDelta);
                    }

                    ApplyChange(tokenizer, snapshot, change.NewSpan);
                }
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        private void BufferChanged(object sender, TextContentChangedEventArgs e)
        {
            var snapshot = e.After;

            _tokenCache.EnsureCapacity(snapshot.LineCount);

            var tokenizer = GetTokenizer();

            foreach (var change in e.Changes)
            {
                if (change.LineCountDelta > 0)
                {
                    _tokenCache.InsertLines(snapshot.GetLineNumberFromPosition(change.NewEnd) + 1 - change.LineCountDelta, change.LineCountDelta);
                }
                else if (change.LineCountDelta < 0)
                {
                    _tokenCache.DeleteLines(snapshot.GetLineNumberFromPosition(change.NewEnd) + 1, -change.LineCountDelta);
                }

                ApplyChange(tokenizer, snapshot, change.NewSpan, 0, 0);
            }
        }