Welcome to mirror list, hosted at ThFree Co, Russian Federation.

VacuousTextViewModel.cs « TextUIUtil « Util « Text « src - github.com/microsoft/vs-editor-api.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 341ed2af2b8a3e8eba8bb82509859d5c526b9691 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//  Licensed under the MIT License. See License.txt in the project root for license information.
//
namespace Microsoft.VisualStudio.Text.Utilities
{
    using System;
    using Microsoft.VisualStudio.Utilities;
    using Microsoft.VisualStudio.Text;
    using Microsoft.VisualStudio.Text.Editor;

    /// <summary>
    /// Implements a text view model that simply reexposes the data buffer and an optional edit buffer. The VisualBuffer
    /// is the same as the edit buffer, which is in turn the same as the data buffer if no edit buffer is specified.
    /// This is the default if no view model provider is specified or if the specified one declines to build a model.
    /// </summary>
    public class VacuousTextViewModel : ITextViewModel
    {
        private ITextDataModel dataModel;
        private ITextBuffer editBuffer;

        public VacuousTextViewModel(ITextDataModel dataModel) : this(dataModel, dataModel.DataBuffer) { }

        public VacuousTextViewModel(ITextDataModel dataModel, ITextBuffer editBuffer)
        {
            this.dataModel = dataModel;
            this.editBuffer = editBuffer;
            this.Properties = new PropertyCollection();
        }

        public ITextDataModel DataModel
        {
            get { return this.dataModel; }
        }

        public ITextBuffer DataBuffer
        {
            get { return this.dataModel.DataBuffer; }
        }

        public ITextBuffer EditBuffer
        {
            get { return this.editBuffer; }
        }

        public ITextBuffer VisualBuffer
        {
            get { return this.EditBuffer; }
        }

        public void Dispose() 
        { 
            GC.SuppressFinalize(this);
        }

        public PropertyCollection Properties { get; internal set; }


        public SnapshotPoint GetNearestPointInVisualBuffer(SnapshotPoint editBufferPoint)
        {
            // The edit buffer is the same as the visual buffer, so just return the passed-in point.
            return editBufferPoint;
        }

        public SnapshotPoint GetNearestPointInVisualSnapshot(SnapshotPoint editBufferPoint, ITextSnapshot targetVisualSnapshot, PointTrackingMode trackingMode)
        {
            // The edit buffer is the same as the visual buffer, so just return the passed-in point translated to the correct snapshot.
            return editBufferPoint.TranslateTo(targetVisualSnapshot, trackingMode);
        }

        public bool IsPointInVisualBuffer(SnapshotPoint editBufferPoint, PositionAffinity affinity)
        {
            // The edit buffer is the same as the visual buffer, so just return true.
            return true;
        }
    }
}