Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2389-EpsLexicase/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Editing/SelectionSegment.cs @ 15945

Last change on this file since 15945 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 3.1 KB
Line 
1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4// software and associated documentation files (the "Software"), to deal in the Software
5// without restriction, including without limitation the rights to use, copy, modify, merge,
6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7// to whom the Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20#if NREFACTORY
21using ICSharpCode.NRefactory.Editor;
22#else
23using ICSharpCode.AvalonEdit.Document;
24#endif
25
26namespace ICSharpCode.AvalonEdit.Editing
27{
28  /// <summary>
29  /// Represents a selected segment.
30  /// </summary>
31  public class SelectionSegment : ISegment
32  {
33    readonly int startOffset, endOffset;
34    readonly int startVC, endVC;
35   
36    /// <summary>
37    /// Creates a SelectionSegment from two offsets.
38    /// </summary>
39    public SelectionSegment(int startOffset, int endOffset)
40    {
41      this.startOffset = Math.Min(startOffset, endOffset);
42      this.endOffset = Math.Max(startOffset, endOffset);
43      this.startVC = this.endVC = -1;
44    }
45   
46    /// <summary>
47    /// Creates a SelectionSegment from two offsets and visual columns.
48    /// </summary>
49    public SelectionSegment(int startOffset, int startVC, int endOffset, int endVC)
50    {
51      if (startOffset < endOffset || (startOffset == endOffset && startVC <= endVC)) {
52        this.startOffset = startOffset;
53        this.startVC = startVC;
54        this.endOffset = endOffset;
55        this.endVC = endVC;
56      } else {
57        this.startOffset = endOffset;
58        this.startVC = endVC;
59        this.endOffset = startOffset;
60        this.endVC = startVC;
61      }
62    }
63   
64    /// <summary>
65    /// Gets the start offset.
66    /// </summary>
67    public int StartOffset {
68      get { return startOffset; }
69    }
70   
71    /// <summary>
72    /// Gets the end offset.
73    /// </summary>
74    public int EndOffset {
75      get { return endOffset; }
76    }
77   
78    /// <summary>
79    /// Gets the start visual column.
80    /// </summary>
81    public int StartVisualColumn {
82      get { return startVC; }
83    }
84   
85    /// <summary>
86    /// Gets the end visual column.
87    /// </summary>
88    public int EndVisualColumn {
89      get { return endVC; }
90    }
91   
92    /// <inheritdoc/>
93    int ISegment.Offset {
94      get { return startOffset; }
95    }
96   
97    /// <inheritdoc/>
98    public int Length {
99      get { return endOffset - startOffset; }
100    }
101   
102    /// <inheritdoc/>
103    public override string ToString()
104    {
105      return string.Format("[SelectionSegment StartOffset={0}, EndOffset={1}, StartVC={2}, EndVC={3}]", startOffset, endOffset, startVC, endVC);
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.