Пример #1
0
        public void VimBufferCreated(IVimBuffer vimBuffer)
        {
            var taggerList = new List<ITagger<ITag>>();
            var bufferAdapterList = new List<IExternalEditAdapter>();
            var textView = vimBuffer.TextView;

            foreach (var adapter in _adapterList)
            {
                ITagger<ITag> tagger;
                if (adapter.IsInterested(textView, out tagger))
                {
                    bufferAdapterList.Add(adapter);
                    if (tagger != null)
                    {
                        taggerList.Add(tagger);
                    }
                }
            }

            if (bufferAdapterList.Count > 0)
            {
                _monitorMap[vimBuffer] = new ExternalEditMonitor(
                    vimBuffer,
                    _protectedOperations,
                    _vsAdapter.GetTextLines(vimBuffer.TextBuffer),
                    taggerList.ToReadOnlyCollectionShallow(),
                    bufferAdapterList.ToReadOnlyCollectionShallow());
                vimBuffer.Closed += delegate { _monitorMap.Remove(vimBuffer); };
            }
        }
Пример #2
0
        void IVimBufferCreationListener.VimBufferCreated(IVimBuffer vimBuffer)
        {
            var taggerList        = new List <ITagger <ITag> >();
            var bufferAdapterList = new List <IExternalEditAdapter>();
            var textView          = vimBuffer.TextView;

            foreach (var adapter in _adapterList)
            {
                ITagger <ITag> tagger;
                if (adapter.IsInterested(textView, out tagger))
                {
                    bufferAdapterList.Add(adapter);
                    if (tagger != null)
                    {
                        taggerList.Add(tagger);
                    }
                }
            }

            if (bufferAdapterList.Count > 0)
            {
                var externalEditMonitor = new ExternalEditMonitor(
                    vimBuffer,
                    _protectedOperations,
                    _vsAdapter.GetTextLines(vimBuffer.TextBuffer),
                    taggerList.ToReadOnlyCollectionShallow(),
                    bufferAdapterList.ToReadOnlyCollectionShallow());
                _monitorMap[vimBuffer] = externalEditMonitor;
                vimBuffer.Closed      += delegate
                {
                    _monitorMap.Remove(vimBuffer);
                    externalEditMonitor.Close();
                };
            }
        }
        public void Create(bool hasTextLines, bool hasTagger, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Loose);
            _textView = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            _buffer = Vim.CreateVimBuffer(_textView);
            _vimApplicationSettings = _factory.Create<IVimApplicationSettings>();
            _vimApplicationSettings.SetupGet(x => x.EnableExternalEditMonitoring).Returns(true);

            // Have adatper ignore by default
            _adapter = _factory.Create<IExternalEditAdapter>(MockBehavior.Strict);
            _adapter.Setup(x => x.IsExternalEditTag(It.IsAny<ITag>())).Returns(false);
            _adapter.Setup(x => x.IsExternalEditMarker(It.IsAny<IVsTextLineMarker>())).Returns(false);
            var adapterList = new List<IExternalEditAdapter> { _adapter.Object };

            Result<IVsTextLines> textLines = Result.Error;
            if (hasTextLines)
            {
                _vsTextLines = _factory.Create<IVsTextLines>(MockBehavior.Strict);
                _vsTextLines.SetupNoEnumMarkers();
                textLines = Result.CreateSuccess(_vsTextLines.Object);
            }

            var taggerList = new List<ITagger<ITag>>();
            if (hasTagger)
            {
                _tagger = _factory.Create<ITagger<ITag>>(MockBehavior.Loose);
                _tagger.Setup(x => x.GetTags(It.IsAny<NormalizedSnapshotSpanCollection>())).Returns(new List<ITagSpan<ITag>>());
                taggerList.Add(_tagger.Object);
            }

            _monitor = new ExternalEditMonitor(
                _vimApplicationSettings.Object,
                _buffer,
                ProtectedOperations,
                textLines,
                taggerList.ToReadOnlyCollectionShallow(),
                adapterList.ToReadOnlyCollectionShallow());
        }