// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Windows.Media;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Projection;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.Structure
{
///
/// Shared state object we use for and RoslynBlockTag
/// (in EditorFeatures.Next).
///
internal struct BlockTagState
{
private const string OutliningRegionTextViewRole = nameof(OutliningRegionTextViewRole);
private const string Ellipsis = "...";
private const int MaxPreviewText = 1000;
private readonly ITextEditorFactoryService _textEditorFactoryService;
private readonly IProjectionBufferFactoryService _projectionBufferFactoryService;
private readonly IEditorOptionsFactoryService _editorOptionsFactoryService;
private readonly ITextBuffer _subjectBuffer;
private readonly ITrackingSpan _hintSpan;
public bool IsDefaultCollapsed => BlockSpan.IsDefaultCollapsed;
public bool IsImplementation => BlockSpan.AutoCollapse;
public object CollapsedForm => BlockSpan.BannerText;
public readonly BlockSpan BlockSpan;
public BlockTagState(
ITextEditorFactoryService textEditorFactoryService,
IProjectionBufferFactoryService projectionBufferFactoryService,
IEditorOptionsFactoryService editorOptionsFactoryService,
ITextSnapshot snapshot,
BlockSpan blockSpan)
{
_textEditorFactoryService = textEditorFactoryService;
_projectionBufferFactoryService = projectionBufferFactoryService;
_editorOptionsFactoryService = editorOptionsFactoryService;
_subjectBuffer = snapshot.TextBuffer;
BlockSpan = blockSpan;
_hintSpan = snapshot.CreateTrackingSpan(BlockSpan.HintSpan.ToSpan(), SpanTrackingMode.EdgeExclusive);
}
public override bool Equals(object obj)
=> obj is BlockTagState s && Equals(s);
public bool Equals(BlockTagState tag)
=> IsImplementation == tag.IsImplementation &&
Equals(this.CollapsedForm, tag.CollapsedForm);
public override int GetHashCode()
=> Hash.Combine(IsImplementation,
EqualityComparer