Esempio n. 1
0
        // This method should only be called once (it is normally called from the ctor unless we're using
        // ITextEditorFactoryService2.CreateTextViewWithoutInitialization on the factory to delay initialization).
        internal void Initialize()
        {
            if (hasInitializeBeenCalled)
            {
                throw new InvalidOperationException("Attempted to Initialize a WpfTextView twice");
            }

            bufferGraph = factoryService.BufferGraphFactoryService.CreateBufferGraph(this.TextViewModel.VisualBuffer);

            //_editorFormatMap = _factoryService.EditorFormatMapService.GetEditorFormatMap(this);

            selection = new TextSelection(this);

            //			this.Loaded += OnLoaded;

            // TODO: *Someone* needs to call this to execute UndoHistoryRegistry.RegisterHistory -- VS does this via the ShimCompletionControllerFactory.
            factoryService.EditorOperationsProvider.GetEditorOperations(this);

            connectionManager = new ConnectionManager(this, factoryService.TextViewConnectionListeners, factoryService.GuardedOperations);

            SubscribeToEvents();

            // Binding content type specific assets includes calling out to content-type
            // specific view creation listeners.  We need to do this as late as possible.
            this.BindContentTypeSpecificAssets(null, TextViewModel.DataModel.ContentType);

            //Subscribe now so that there is no chance that a layout could be forced by a text change.
            //_visualBuffer.ChangedLowPriority += OnVisualBufferChanged;
            //_visualBuffer.ContentTypeChanged += OnVisualBufferContentTypeChanged;

            hasInitializeBeenCalled = true;
        }
Esempio n. 2
0
        public void Dispose()
        {
            if (this.disposed)
            {
                return;
            }

            try
            {
                if (this.textView != null)
                {
                    this.textView.Closed -= this.OnTextView_Closed;
                }

                this.BufferGraph.GraphBufferContentTypeChanged -= BufferGraph_GraphBufferContentTypeChanged;
                this.BufferGraph.GraphBuffersChanged           -= BufferGraph_GraphBuffersChanged;

                this.DisposeAllTaggers();
            }
            finally
            {
                this.taggers = null;
                this.TagAggregatorFactoryService = null;
                this.BufferGraph   = null;
                this.textView      = null;
                this.uniqueTaggers = null;

                disposed = true;
            }
        }
Esempio n. 3
0
        // This method should only be called once (it is normally called from the ctor unless we're using
        // ITextEditorFactoryService2.CreateTextViewWithoutInitialization on the factory to delay initialization).
        internal void Initialize()
        {
            if (_hasInitializeBeenCalled)
            {
                throw new InvalidOperationException("Attempted to Initialize a WpfTextView twice");
            }

            _bufferGraph = _factoryService.BufferGraphFactoryService.CreateBufferGraph(this.TextViewModel.VisualBuffer);

            //_editorFormatMap = _factoryService.EditorFormatMapService.GetEditorFormatMap(this);

            _selection = new TextSelection(_textEditor, this);

            // Create caret
            _caret = new TextCaret(_textEditor, this);

            //			this.Loaded += OnLoaded;

            _connectionManager = new ConnectionManager(this, _factoryService.TextViewConnectionListeners, _factoryService.GuardedOperations);

            SubscribeToEvents();

            // Binding content type specific assets includes calling out to content-type
            // specific view creation listeners.  We need to do this as late as possible.
            this.BindContentTypeSpecificAssets(null, TextViewModel.DataModel.ContentType);

            //Subscribe now so that there is no chance that a layout could be forced by a text change.
            //_visualBuffer.ChangedLowPriority += OnVisualBufferChanged;
            //_visualBuffer.ContentTypeChanged += OnVisualBufferContentTypeChanged;

            _hasInitializeBeenCalled = true;
        }
Esempio n. 4
0
        public TemplateProjectionBuffer(IContentTypeRegistryService contentRegistry, IProjectionBufferFactoryService bufferFactory, ITextBuffer diskBuffer, IBufferGraphFactoryService bufferGraphFactory, IContentType contentType)
        {
            _diskBuffer      = diskBuffer;
            _contentRegistry = contentRegistry;
            _contentType     = contentType;

            _projBuffer = bufferFactory.CreateProjectionBuffer(
                this,
                new object[0],
                ProjectionBufferOptions.None
                );
            _projBuffer.Properties.AddProperty(typeof(TemplateProjectionBuffer), this);

            _bufferGraph = bufferGraphFactory.CreateBufferGraph(_projBuffer);

            _htmlBuffer     = CreateHtmlBuffer(bufferFactory);
            _templateBuffer = CreateTemplateBuffer(bufferFactory);

            IVsTextBuffer buffer;

            if (_diskBuffer.Properties.TryGetProperty <IVsTextBuffer>(typeof(IVsTextBuffer), out buffer))
            {
                // keep the Venus HTML classifier happy - it wants to find a site via IVsTextBuffer
                _htmlBuffer.Properties.AddProperty(typeof(IVsTextBuffer), buffer);
            }

            var reader = new SnapshotSpanSourceCodeReader(new SnapshotSpan(diskBuffer.CurrentSnapshot, new Span(0, diskBuffer.CurrentSnapshot.Length)));

            UpdateTemplateSpans(reader);
        }
Esempio n. 5
0
 private TSLParser(ITextBuffer buffer, IBufferGraph bufferGraph)
 {
     _textBuffer     = buffer;
     _bufferGraph    = bufferGraph;
     buffer.Changed += this.BufferChangedEventHandler;
     TryTriggerGlobalParse();
 }
Esempio n. 6
0
        public void Dispose()
        {
            if (this.disposed)
            {
                return;
            }

            try
            {
                if (this.textView != null)
                {
                    this.textView.Closed -= this.OnTextView_Closed;
                }

                foreach (var bufferAndTaggers in bufferStates)
                {
                    this.UnregisterBuffer(bufferAndTaggers.Key, bufferAndTaggers.Value);
                }

                Debug.Assert(this.uniqueTaggers.Count == 0);
            }
            finally
            {
                this.bufferStates.Clear();
                this.uniqueTaggers.Clear();
                this.TagAggregatorFactoryService = null;
                this.BufferGraph = null;
                this.textView    = null;

                disposed = true;
            }
        }
        public static SnapshotSpan?MapUpOrDownToBuffer(this IBufferGraph bufferGraph, SnapshotSpan span, ITextBuffer targetBuffer)
        {
            var direction = ClassifyBufferMapDirection(span.Snapshot.TextBuffer, targetBuffer);

            switch (direction)
            {
            case BufferMapDirection.Identity:
                return(span);

            case BufferMapDirection.Down:
            {
                var spans = bufferGraph.MapDownToBuffer(span, SpanTrackingMode.EdgeExclusive, targetBuffer);
                return(spans.Select(s => (SnapshotSpan?)s).FirstOrDefault());
            }

            case BufferMapDirection.Up:
            {
                var spans = bufferGraph.MapUpToBuffer(span, SpanTrackingMode.EdgeExclusive, targetBuffer);
                return(spans.Select(s => (SnapshotSpan?)s).FirstOrDefault());
            }

            default:
                return(null);
            }
        }
        public PhpProjectionBuffer(
            IContentTypeRegistryService contentRegistry,
            IProjectionBufferFactoryService bufferFactory,
            IBufferTagAggregatorFactoryService bufferTagAggregatorFactory,
            ITextBuffer diskBuffer,
            IBufferGraphFactoryService bufferGraphFactory,
            IContentType contentType)
        {
            _diskBuffer      = diskBuffer;
            _contentRegistry = contentRegistry;
            _contentType     = contentType;

            _projBuffer     = CreateProjectionBuffer(bufferFactory);
            _htmlBuffer     = CreateHtmlBuffer(bufferFactory);
            _templateBuffer = CreateTemplateBuffer(bufferFactory);

            _bufferGraph = bufferGraphFactory.CreateBufferGraph(_projBuffer);

            _contentTypeTagger              = bufferTagAggregatorFactory.CreateTagAggregator <ContentTypeTag>(_diskBuffer);
            _contentTypeTagger.TagsChanged += HandleContentTypeTagsChanged;

            IVsTextBuffer buffer;

            if (_diskBuffer.Properties.TryGetProperty <IVsTextBuffer>(typeof(IVsTextBuffer), out buffer))
            {
                // keep the Venus HTML classifier happy - it wants to find a site via IVsTextBuffer
                _htmlBuffer.Properties.AddProperty(typeof(IVsTextBuffer), buffer);
            }

            HandleContentTypeTagsChanged();
        }
Esempio n. 9
0
        public static Mock <ITextView> CreateTextView(
            ITextBuffer textBuffer                = null,
            ITextCaret caret                      = null,
            ITextSelection selection              = null,
            ITextViewRoleSet textViewRoleSet      = null,
            ITextViewModel textViewModel          = null,
            IEditorOptions editorOptions          = null,
            IBufferGraph bufferGraph              = null,
            PropertyCollection propertyCollection = null,
            MockRepository factory                = null)
        {
            factory            = factory ?? new MockRepository(MockBehavior.Strict);
            textBuffer         = textBuffer ?? CreateTextBuffer(100, factory: factory).Object;
            caret              = caret ?? CreateCaret(factory: factory).Object;
            selection          = selection ?? CreateSelection(factory: factory).Object;
            propertyCollection = propertyCollection ?? new PropertyCollection();
            textViewRoleSet    = textViewRoleSet ?? CreateTextViewRoleSet(factory: factory).Object;
            editorOptions      = editorOptions ?? CreateEditorOptions(factory: factory).Object;
            bufferGraph        = bufferGraph ?? CreateBufferGraph(factory: factory).Object;
            textViewModel      = textViewModel ?? CreateTextViewModel(textBuffer: textBuffer, factory: factory).Object;
            var view = factory.Create <ITextView>();

            view.SetupGet(x => x.Caret).Returns(caret);
            view.SetupGet(x => x.Selection).Returns(selection);
            view.SetupGet(x => x.TextBuffer).Returns(textBuffer);
            view.SetupGet(x => x.TextSnapshot).Returns(() => textBuffer.CurrentSnapshot);
            view.SetupGet(x => x.Properties).Returns(propertyCollection);
            view.SetupGet(x => x.Roles).Returns(textViewRoleSet);
            view.SetupGet(x => x.Options).Returns(editorOptions);
            view.SetupGet(x => x.BufferGraph).Returns(bufferGraph);
            view.SetupGet(x => x.TextViewModel).Returns(textViewModel);
            return(view);
        }
Esempio n. 10
0
        public IEditorNavigationDropdownBarClient CreateEditorNavigationDropdownBar(IVsCodeWindow codeWindow, IVsEditorAdaptersFactoryService editorAdaptersFactory)
        {
            // a code window can only be associated with a single buffer, so the primary view will get us the correct information
            IVsTextView  primaryViewAdapter = codeWindow.GetPrimaryView();
            IWpfTextView textView           = editorAdaptersFactory.GetWpfTextView(primaryViewAdapter);

            IBufferGraph             bufferGraph = BufferGraphFactoryService.CreateBufferGraph(textView.TextBuffer);
            Collection <ITextBuffer> buffers     = bufferGraph.GetTextBuffers(i => true);

            List <IEditorNavigationSource> sources = new List <IEditorNavigationSource>();

            foreach (ITextBuffer buffer in buffers)
            {
                var bufferProviders = NavigationSourceProviders.Where(provider => provider.Metadata.ContentTypes.Any(contentType => buffer.ContentType.IsOfType(contentType)));

                var bufferSources =
                    bufferProviders
                    .Select(provider => provider.Value.TryCreateEditorNavigationSource(buffer))
                    .Where(source => source != null);

                sources.AddRange(bufferSources);
            }

            return(new EditorNavigationDropdownBar(codeWindow, editorAdaptersFactory, sources, BufferGraphFactoryService, EditorNavigationTypeRegistryService));
        }
        public static SnapshotPoint?MapUpOrDownToBuffer(this IBufferGraph bufferGraph, SnapshotPoint point, ITextBuffer targetBuffer)
        {
            var direction = ClassifyBufferMapDirection(point.Snapshot.TextBuffer, targetBuffer);

            switch (direction)
            {
            case BufferMapDirection.Identity:
                return(point);

            case BufferMapDirection.Down:
            {
                // TODO (https://github.com/dotnet/roslyn/issues/5281): Remove try-catch.
                try
                {
                    return(bufferGraph.MapDownToInsertionPoint(point, PointTrackingMode.Positive, s => s == targetBuffer.CurrentSnapshot));
                }
                catch (ArgumentOutOfRangeException) when(bufferGraph.TopBuffer.ContentType.TypeName == "Interactive Content")
                {
                    // Suppress this to work around DevDiv #144964.
                    // Note: Other callers might be affected, but this is the narrowest workaround for the observed problems.
                    // A fix is already being reviewed, so a broader change is not required.
                    return(null);
                }
            }

            case BufferMapDirection.Up:
            {
                return(bufferGraph.MapUpToBuffer(point, PointTrackingMode.Positive, PositionAffinity.Predecessor, targetBuffer));
            }

            default:
                return(null);
            }
        }
Esempio n. 12
0
		public MappingSpan(IBufferGraph bufferGraph, SnapshotSpan snapshotSpan, SpanTrackingMode trackingMode) {
			if (bufferGraph == null)
				throw new ArgumentNullException(nameof(bufferGraph));
			if (snapshotSpan.Snapshot == null)
				throw new ArgumentException();
			BufferGraph = bufferGraph;
			this.snapshotSpan = snapshotSpan;
			spanTrackingMode = trackingMode;
		}
Esempio n. 13
0
 public DebuggerTextView(
     IWpfTextView innerTextView,
     IBufferGraph bufferGraph,
     bool isImmediateWindow)
 {
     _innerTextView = innerTextView;
     this.BufferGraph = bufferGraph;
     this.IsImmediateWindow = isImmediateWindow;
 }
Esempio n. 14
0
 public LanguageElementManager(ITextBuffer textBuffer, IBufferGraph bufferGraph, ITagAggregator<ILanguageElementTag> tagAggregator)
 {
     this.enabled = true;
     this.textBuffer = textBuffer;
     this.bufferGraph = bufferGraph;
     this.tagAggregator = tagAggregator;
     this.tagAggregator.TagsChanged += LanguageElementTagsChanged;
     this.textBuffer.Changed += SourceTextChanged;
 }
Esempio n. 15
0
		public MappingPoint(IBufferGraph bufferGraph, SnapshotPoint snapshotPoint, PointTrackingMode trackingMode) {
			if (bufferGraph == null)
				throw new ArgumentNullException(nameof(bufferGraph));
			if (snapshotPoint.Snapshot == null)
				throw new ArgumentException();
			BufferGraph = bufferGraph;
			this.snapshotPoint = snapshotPoint;
			this.trackingMode = trackingMode;
		}
        public static Collection <ITextBuffer> GetRazorBuffers(this IBufferGraph bufferGraph)
        {
            if (bufferGraph == null)
            {
                throw new ArgumentNullException(nameof(bufferGraph));
            }

            return(bufferGraph.GetTextBuffers(TextBufferExtensions.IsRazorBuffer));
        }
Esempio n. 17
0
 public DebuggerTextView(
     IWpfTextView innerTextView,
     IBufferGraph bufferGraph,
     bool isImmediateWindow)
 {
     _innerTextView         = innerTextView;
     this.BufferGraph       = bufferGraph;
     this.IsImmediateWindow = isImmediateWindow;
 }
 public LanguageElementManager(ITextBuffer textBuffer, IBufferGraph bufferGraph, ITagAggregator <ILanguageElementTag> tagAggregator)
 {
     this.enabled                    = true;
     this.textBuffer                 = textBuffer;
     this.bufferGraph                = bufferGraph;
     this.tagAggregator              = tagAggregator;
     this.tagAggregator.TagsChanged += LanguageElementTagsChanged;
     this.textBuffer.Changed        += SourceTextChanged;
 }
Esempio n. 19
0
 protected TagAggregatorBase(IBufferGraph bufferGraph, ITextBuffer textBuffer, TagAggregatorOptions options)
 {
     dispatcher             = Dispatcher.CurrentDispatcher;
     batchedTagsChangedList = new List <IMappingSpan>();
     lockObj     = new object();
     BufferGraph = bufferGraph ?? throw new ArgumentNullException(nameof(bufferGraph));
     TextBuffer  = textBuffer ?? throw new ArgumentNullException(nameof(textBuffer));
     TextBuffer.ContentTypeChanged += TextBuffer_ContentTypeChanged;
     taggers = Array.Empty <ITagger <T> >();
 }
Esempio n. 20
0
 public MappingSpan(IBufferGraph bufferGraph, SnapshotSpan snapshotSpan, SpanTrackingMode trackingMode)
 {
     if (snapshotSpan.Snapshot is null)
     {
         throw new ArgumentException();
     }
     BufferGraph       = bufferGraph ?? throw new ArgumentNullException(nameof(bufferGraph));
     this.snapshotSpan = snapshotSpan;
     spanTrackingMode  = trackingMode;
 }
Esempio n. 21
0
 public MappingPoint(IBufferGraph bufferGraph, SnapshotPoint snapshotPoint, PointTrackingMode trackingMode)
 {
     if (snapshotPoint.Snapshot == null)
     {
         throw new ArgumentException();
     }
     BufferGraph        = bufferGraph ?? throw new ArgumentNullException(nameof(bufferGraph));
     this.snapshotPoint = snapshotPoint;
     this.trackingMode  = trackingMode;
 }
        public static SnapshotSpan?MapUpOrDownToFirstMatch(this IBufferGraph bufferGraph, SnapshotSpan span, Predicate <ITextSnapshot> match)
        {
            var spans = bufferGraph.MapDownToFirstMatch(span, SpanTrackingMode.EdgeExclusive, match);

            if (!spans.Any())
            {
                spans = bufferGraph.MapUpToFirstMatch(span, SpanTrackingMode.EdgeExclusive, match);
            }

            return(spans.Select(s => (SnapshotSpan?)s).FirstOrDefault());
        }
Esempio n. 23
0
 public DebuggerTextView(
     IWpfTextView innerTextView,
     IBufferGraph bufferGraph,
     IVsTextLines debuggerTextLinesOpt,
     bool isImmediateWindow)
 {
     _innerTextView        = innerTextView;
     _debuggerTextLinesOpt = debuggerTextLinesOpt;
     BufferGraph           = bufferGraph;
     IsImmediateWindow     = isImmediateWindow;
 }
Esempio n. 24
0
        public WpfTextViewLine(IBufferGraph bufferGraph, LinePartsCollection linePartsCollection, int startColumn, int endColumn, ITextSnapshotLine bufferLine, SnapshotSpan span, ITextSnapshot visualSnapshot, TextLine textLine, double indentation, double virtualSpaceWidth)
        {
            if (bufferGraph == null)
            {
                throw new ArgumentNullException(nameof(bufferGraph));
            }
            if (linePartsCollection == null)
            {
                throw new ArgumentNullException(nameof(linePartsCollection));
            }
            if (bufferLine == null)
            {
                throw new ArgumentNullException(nameof(bufferLine));
            }
            if (span.Snapshot != bufferLine.Snapshot)
            {
                throw new ArgumentException();
            }
            if (visualSnapshot == null)
            {
                throw new ArgumentNullException(nameof(visualSnapshot));
            }
            if (textLine == null)
            {
                throw new ArgumentNullException(nameof(textLine));
            }

            this.IsValid             = true;
            this.bufferGraph         = bufferGraph;
            this.linePartsCollection = linePartsCollection;
            this.endColumn           = endColumn;
            this.visualSnapshot      = visualSnapshot;
            this.textLines           = new ReadOnlyCollection <TextLine>(new[] { textLine });
            Debug.Assert(textLines.Count == 1);            // Assumed by all code accessing TextLine prop
            this.realTopSpace    = 0;
            this.realBottomSpace = 0;
            this.realBaseline    = TextLine.Baseline;
            this.isFirstTextViewLineForSnapshotLine = span.Start == bufferLine.Start;
            this.isLastTextViewLineForSnapshotLine  = span.End == bufferLine.EndIncludingLineBreak;
            IsLastVisualLine              = bufferLine.LineNumber + 1 == bufferLine.Snapshot.LineCount && IsLastTextViewLineForSnapshotLine;
            this.lineBreakLength          = isLastTextViewLineForSnapshotLine ? bufferLine.LineBreakLength : 0;
            this.virtualSpaceWidth        = virtualSpaceWidth;
            this.textLeft                 = indentation;
            this.textWidth                = textLine.WidthIncludingTrailingWhitespace;
            this.extentIncludingLineBreak = span;
            this.realHeight               = textLine.Height + DEFAULT_TOP_SPACE + DEFAULT_BOTTOM_SPACE;
            this.realTextHeight           = textLine.TextHeight;
            this.endOfLineWidth           = Math.Floor(this.realTextHeight * 0.58333333333333337);  // Same as VS
            this.width  = this.textWidth + (this.lineBreakLength == 0 ? 0 : this.endOfLineWidth);
            this.change = TextViewLineChange.NewOrReformatted;
            SetLineTransform(DefaultLineTransform);
        }
Esempio n. 25
0
 public void Dispose()
 {
     IsValid = false;
     foreach (var t in textLines)
     {
         t.Dispose();
     }
     bufferGraph = null !;
     extentIncludingLineBreak = default;
     visualSnapshot           = null !;
     linePartsCollection      = null !;
     textLines     = null !;
     drawingVisual = null;
 }
Esempio n. 26
0
        internal static TSLParser GetParser(ITextBuffer buffer)
        {
            Debug.Assert(Ready);
            IBufferGraph bufferGraph = null;

            bufferGraph = buffer.Properties.GetOrCreateSingletonProperty <IBufferGraph>(() =>
            {
                return(_bufferGraphFactory.CreateBufferGraph(buffer));
            });
            var parser = buffer.Properties.GetOrCreateSingletonProperty <TSLParser>(() =>
            {
                return(new TSLParser(buffer, bufferGraph));
            });

            return(parser);
        }
Esempio n. 27
0
        public DebuggerTextView(
            IWpfTextView innerTextView,
            IBufferGraph bufferGraph,
            IVsTextLines debuggerTextLinesOpt,
            bool isImmediateWindow)
        {
            _innerTextView        = innerTextView;
            _debuggerTextLinesOpt = debuggerTextLinesOpt;
            BufferGraph           = bufferGraph;
            IsImmediateWindow     = isImmediateWindow;

            // The editor requires the current top buffer.
            // TODO it seems to be a hack. It should be removed.
            // Here is an issue to track: https://github.com/dotnet/roslyn/issues/31189
            // Starting debugging for the second time, we already have the property set.
            _innerTextView.Properties[CompletionRoot] = bufferGraph.TopBuffer;
        }
Esempio n. 28
0
 public MappingSpan(SnapshotSpan anchorSpan, SpanTrackingMode trackingMode, IBufferGraph bufferGraph)
 {
     if (anchorSpan.Snapshot == null)
     {
         throw new ArgumentNullException("anchorSpan");
     }
     if (trackingMode < SpanTrackingMode.EdgeExclusive || trackingMode > SpanTrackingMode.EdgeNegative)
     {
         throw new ArgumentOutOfRangeException("trackingMode");
     }
     if (bufferGraph == null)
     {
         throw new ArgumentNullException("bufferGraph");
     }
     this.anchorSpan   = anchorSpan;
     this.trackingMode = trackingMode;
     this.bufferGraph  = bufferGraph;
 }
Esempio n. 29
0
 public MappingPoint(SnapshotPoint anchorPoint, PointTrackingMode trackingMode, IBufferGraph bufferGraph)
 {
     if (anchorPoint.Snapshot == null)
     {
         throw new ArgumentNullException("anchorPoint");
     }
     if (trackingMode < PointTrackingMode.Positive || trackingMode > PointTrackingMode.Negative)
     {
         throw new ArgumentOutOfRangeException("trackingMode");
     }
     if (bufferGraph == null)
     {
         throw new ArgumentNullException("bufferGraph");
     }
     this.anchorPoint  = anchorPoint;
     this.trackingMode = trackingMode;
     this.bufferGraph  = bufferGraph;
 }
Esempio n. 30
0
        private MappingSpanSnapshot(ITextSnapshot root, SnapshotSpan anchor, SpanTrackingMode trackingMode, IBufferGraph graph)
        {
            //Anchor and root are expected to be from concurrent snapshots
            ITextSnapshot correspondingAnchorSnapshot = MappingHelper.FindCorrespondingSnapshot(root, anchor.Snapshot.TextBuffer);

            _root = root;
            if (correspondingAnchorSnapshot != null)
            {
                _anchor = anchor.TranslateTo(correspondingAnchorSnapshot, trackingMode);
            }
            else
            {
                _anchor     = anchor;
                _unmappable = true;
            }
            _trackingMode = trackingMode;
            _graph        = graph;
        }
        private SnapshotSpan MapTo(SnapshotSpan span, ITextSnapshot snapshot, SpanTrackingMode spanTrackingMode)
        {
            if (span.Snapshot.TextBuffer == snapshot.TextBuffer)
            {
                return(span.TranslateTo(snapshot, spanTrackingMode));
            }

            IBufferGraph graph       = _bufferGraphFactoryService.CreateBufferGraph(snapshot.TextBuffer);
            IMappingSpan mappingSpan = graph.CreateMappingSpan(span, spanTrackingMode);
            NormalizedSnapshotSpanCollection mapped = mappingSpan.GetSpans(snapshot);

            if (mapped.Count == 1)
            {
                return(mapped[0]);
            }

            return(new SnapshotSpan(mapped[0].Start, mapped[mapped.Count - 1].End));
        }
Esempio n. 32
0
        public void RefreshBuffers(IBufferGraph graph)
        {
            this.bufferGraph.Clear();
            var buffers = graph.GetTextBuffers(b => true);
            int index   = 0;

            foreach (var buffer in buffers)
            {
                this.bufferGraph.Add(new BufferInfoViewModel {
                    ContentType       = buffer.ContentType.DisplayName,
                    BufferType        = buffer.GetType(),
                    ActualContentType = new ContentTypeViewModel(buffer.ContentType),
                    Index             = index++
                });
            }
            NotifyChanged("BufferGraph");
            this.SelectedBuffer = this.bufferGraph.FirstOrDefault(
                b => TextEditor.IsNonProjectionOrElisionBufferType(b.BufferType));
        }
Esempio n. 33
0
        void Initialize()
        {
            _bufferGraph = _factoryService.BufferGraphFactoryService.CreateBufferGraph(this.TextViewModel.VisualBuffer);

            _editorFormatMap = _factoryService.EditorFormatMapService.GetEditorFormatMap(this);

            _baseLayer    = new ViewStack(_factoryService.OrderedViewLayerDefinitions, this);
            _overlayLayer = new ViewStack(_factoryService.OrderedOverlayLayerDefinitions, this, isOverlayLayer: true);

            // Create selection and make sure it's created before the caret as the caret relies on the selection being
            // available in its constructor
            _selection = new SkiaTextSelection(this, _editorFormatMap, _factoryService.GuardedOperations);

            // Create caret
            _caretElement = new SkiaTextCaret(this, _selection,
                                              _factoryService.SmartIndentationService,
                                              _editorFormatMap,
                                              _factoryService.GuardedOperations);
        }
Esempio n. 34
0
        public static SnapshotPoint?MapUpOrDownToBuffer(this IBufferGraph bufferGraph, SnapshotPoint point, ITextBuffer targetBuffer)
        {
            var direction = ClassifyBufferMapDirection(point.Snapshot.TextBuffer, targetBuffer);

            switch (direction)
            {
            case BufferMapDirection.Identity:
                return(point);

            case BufferMapDirection.Down:
            {
                return(bufferGraph.MapDownToBuffer(point, PointTrackingMode.Positive, targetBuffer, PositionAffinity.Predecessor));
            }

            case BufferMapDirection.Up:
            {
                return(bufferGraph.MapUpToBuffer(point, PointTrackingMode.Positive, PositionAffinity.Predecessor, targetBuffer));
            }

            default:
                return(null);
            }
        }
        static SnapshotPoint? MapUpOrDownToBuffer(IBufferGraph bufferGraph, SnapshotPoint point, ITextBuffer destinationBuffer)
        {
            var startBuffer = point.Snapshot.TextBuffer;

            if (startBuffer == destinationBuffer)
            {
                return point;
            }

            // Are we trying to map down or up?
            var startProjBuffer = startBuffer as IProjectionBufferBase;
            if (startProjBuffer != null && IsSourceBuffer(startProjBuffer, destinationBuffer))
            {
                return bufferGraph.MapDownToInsertionPoint(point, PointTrackingMode.Positive, s => s == destinationBuffer.CurrentSnapshot);
            }

            var destProjBuffer = destinationBuffer as IProjectionBufferBase;
            if (destProjBuffer != null && IsSourceBuffer(destProjBuffer, startBuffer))
            {
                return bufferGraph.MapUpToBuffer(point, PointTrackingMode.Positive, PositionAffinity.Predecessor, destinationBuffer);
            }

            return null;
        }
Esempio n. 36
0
 public void RefreshBuffers(IBufferGraph graph)
 {
     this.bufferGraph.Clear();
       var buffers = graph.GetTextBuffers(b => true);
       int index = 0;
       foreach ( var buffer in buffers ) {
     this.bufferGraph.Add(new BufferInfoViewModel {
       ContentType = buffer.ContentType.DisplayName,
       BufferType = buffer.GetType(),
       ActualContentType = new ContentTypeViewModel(buffer.ContentType),
       Index = index++
     });
       }
       NotifyChanged("BufferGraph");
       this.SelectedBuffer = this.bufferGraph.FirstOrDefault(
     b => TextEditor.IsNonProjectionOrElisionBufferType(b.BufferType));
 }
Esempio n. 37
0
		public WpfTextViewLine(IBufferGraph bufferGraph, LinePartsCollection linePartsCollection, int linePartsIndex, int linePartsLength, int startColumn, int endColumn, ITextSnapshotLine bufferLine, SnapshotSpan span, ITextSnapshot visualSnapshot, TextLine textLine, double indentation, double virtualSpaceWidth) {
			if (bufferGraph == null)
				throw new ArgumentNullException(nameof(bufferGraph));
			if (linePartsCollection == null)
				throw new ArgumentNullException(nameof(linePartsCollection));
			if (linePartsIndex < 0)
				throw new ArgumentOutOfRangeException(nameof(linePartsIndex));
			if (linePartsLength < 0)
				throw new ArgumentOutOfRangeException(nameof(linePartsLength));
			if (linePartsIndex + linePartsLength > linePartsCollection.LineParts.Count)
				throw new ArgumentOutOfRangeException(nameof(linePartsLength));
			if (bufferLine == null)
				throw new ArgumentNullException(nameof(bufferLine));
			if (span.Snapshot != bufferLine.Snapshot)
				throw new ArgumentException();
			if (visualSnapshot == null)
				throw new ArgumentNullException(nameof(visualSnapshot));
			if (textLine == null)
				throw new ArgumentNullException(nameof(textLine));

			IsValid = true;
			this.linePartsIndex = linePartsIndex;
			this.linePartsLength = linePartsLength;
			this.bufferGraph = bufferGraph;
			this.linePartsCollection = linePartsCollection;
			this.startColumn = startColumn;
			this.endColumn = endColumn;
			this.visualSnapshot = visualSnapshot;
			textLines = new ReadOnlyCollection<TextLine>(new[] { textLine });
			Debug.Assert(textLines.Count == 1);// Assumed by all code accessing TextLine prop

			realTopSpace = 0;
			realBottomSpace = 0;
			realBaseline = TextLine.Baseline;
			double baseLineHeight = TextLine.TextHeight - TextLine.Baseline;
			var lineParts = linePartsCollection.LineParts;
			for (int i = 0; i < linePartsLength; i++) {
				var adornmentElement = lineParts[linePartsIndex + i].AdornmentElement;
				if (adornmentElement == null)
					continue;
				double adornmentBaseLineHeight = adornmentElement.TextHeight - adornmentElement.Baseline;
				if (adornmentBaseLineHeight > baseLineHeight)
					baseLineHeight = adornmentBaseLineHeight;
				if (adornmentElement.Baseline > realBaseline)
					realBaseline = adornmentElement.Baseline;
				if (adornmentElement.TopSpace > realTopSpace)
					realTopSpace = adornmentElement.TopSpace;
				if (adornmentElement.BottomSpace > realBottomSpace)
					realBottomSpace = adornmentElement.BottomSpace;
			}
			realTextHeight = Math.Ceiling(baseLineHeight + realBaseline);

			isFirstTextViewLineForSnapshotLine = span.Start == bufferLine.Start;
			isLastTextViewLineForSnapshotLine = span.End == bufferLine.EndIncludingLineBreak;
			IsLastVisualLine = bufferLine.LineNumber + 1 == bufferLine.Snapshot.LineCount && IsLastTextViewLineForSnapshotLine;
			lineBreakLength = isLastTextViewLineForSnapshotLine ? bufferLine.LineBreakLength : 0;
			this.virtualSpaceWidth = virtualSpaceWidth;
			textLeft = indentation;
			textWidth = TextLine.WidthIncludingTrailingWhitespace;
			extentIncludingLineBreak = span;
			endOfLineWidth = Math.Floor(realTextHeight * 0.58333333333333337);// Same as VS
			width = textWidth + (lineBreakLength == 0 ? 0 : endOfLineWidth);
			change = TextViewLineChange.NewOrReformatted;
			SetLineTransform(DefaultLineTransform);
		}
Esempio n. 38
0
 public static Mock<ITextView> CreateTextView(
     ITextBuffer textBuffer = null,
     ITextCaret caret = null,
     ITextSelection selection = null,
     ITextViewRoleSet textViewRoleSet = null,
     ITextViewModel textViewModel = null,
     IEditorOptions editorOptions = null,
     IBufferGraph bufferGraph = null,
     PropertyCollection propertyCollection = null,
     MockRepository factory = null)
 {
     factory = factory ?? new MockRepository(MockBehavior.Strict);
     textBuffer = textBuffer ?? CreateTextBuffer(100, factory: factory).Object;
     caret = caret ?? CreateCaret(factory: factory).Object;
     selection = selection ?? CreateSelection(factory: factory).Object;
     propertyCollection = propertyCollection ?? new PropertyCollection();
     textViewRoleSet = textViewRoleSet ?? CreateTextViewRoleSet(factory: factory).Object;
     editorOptions = editorOptions ?? CreateEditorOptions(factory: factory).Object;
     bufferGraph = bufferGraph ?? CreateBufferGraph(factory: factory).Object;
     textViewModel = textViewModel ?? CreateTextViewModel(textBuffer: textBuffer, factory: factory).Object;
     var view = factory.Create<ITextView>();
     view.SetupGet(x => x.Caret).Returns(caret);
     view.SetupGet(x => x.Selection).Returns(selection);
     view.SetupGet(x => x.TextBuffer).Returns(textBuffer);
     view.SetupGet(x => x.TextSnapshot).Returns(() => textBuffer.CurrentSnapshot);
     view.SetupGet(x => x.Properties).Returns(propertyCollection);
     view.SetupGet(x => x.Roles).Returns(textViewRoleSet);
     view.SetupGet(x => x.Options).Returns(editorOptions);
     view.SetupGet(x => x.BufferGraph).Returns(bufferGraph);
     view.SetupGet(x => x.TextViewModel).Returns(textViewModel);
     return view;
 }
Esempio n. 39
0
		public void Dispose() {
			IsValid = false;
			foreach (var t in textLines)
				t.Dispose();
			bufferGraph = null;
			extentIncludingLineBreak = default(SnapshotSpan);
			visualSnapshot = null;
			linePartsCollection = null;
			textLines = null;
			drawingVisual = null;
		}
 public ReplAggregateClassifier(IBufferGraphFactoryService bufferGraphFactory, ITextBuffer buffer) {            
     _primaryBuffer = buffer;
     _bufGraphFact = bufferGraphFactory;
     _bufferGraph = bufferGraphFactory.CreateBufferGraph(buffer);
 }
 public ElisionInfo(ITextBuffer buffer, IClassifier classifier, IBufferGraph bufferGraph) {
     Buffer = buffer;
     Classifier = classifier;
     BufferGraph = bufferGraph;
 }