/// <summary> /// Determines whether <paramref name="virtualSpan"/> overlaps this span. Two spans are considered to overlap /// if they have positions in common and neither is empty. Empty spans do not overlap with any /// other span. /// </summary> /// <param name="virtualSpan"> /// The virtual span to check. /// </param> /// <returns> /// <c>true</c> if the spans overlap, otherwise <c>false</c>. /// </returns> public bool OverlapsWith(VirtualSnapshotSpan virtualSpan) { VirtualSnapshotPoint overlapStart = (_start > virtualSpan._start) ? _start : virtualSpan._start; VirtualSnapshotPoint overlapEnd = (_end < virtualSpan._end) ? _end : virtualSpan._end; return(overlapStart < overlapEnd); }
/// <summary> /// Determines whether two <see cref="VirtualSnapshotSpan"/> objects are the same. /// </summary> /// <param name="obj">The object to compare.</param> /// <returns><c>true</c> if the objects are the same, otherwise <c>false</c>.</returns> public override bool Equals(object obj) { if (obj is VirtualSnapshotSpan) { VirtualSnapshotSpan other = (VirtualSnapshotSpan)obj; return(other == this); } else { return(false); } }
/// <summary> /// Returns the intersection with the given virtual span, or null if there is no intersection. /// </summary> /// <param name="virtualSpan"> /// The virtual span to check. /// </param> /// <returns> /// The intersection of the spans, or null if the intersection is empty. /// </returns> public VirtualSnapshotSpan?Intersection(VirtualSnapshotSpan virtualSpan) { VirtualSnapshotPoint intersectStart = (_start > virtualSpan._start) ? _start : virtualSpan._start; VirtualSnapshotPoint intersectEnd = (_end < virtualSpan._end) ? _end : virtualSpan._end; if (intersectStart <= intersectEnd) { return(new VirtualSnapshotSpan(intersectStart, intersectEnd)); } return(null); }
/// <summary> /// Returns the overlap with the given virtual span, or null if there is no overlap. /// </summary> /// <param name="virtualSpan"> /// The virtual span to check. /// </param> /// <returns> /// The overlap of the spans, or null if the overlap is empty. /// </returns> public VirtualSnapshotSpan?Overlap(VirtualSnapshotSpan virtualSpan) { VirtualSnapshotPoint overlapStart = (_start > virtualSpan._start) ? _start : virtualSpan._start; VirtualSnapshotPoint overlapEnd = (_end < virtualSpan._end) ? _end : virtualSpan._end; if (overlapStart < overlapEnd) { return(new VirtualSnapshotSpan(overlapStart, overlapEnd)); } return(null); }
/// <summary> /// Instantiates a new Selection with the given extent. Anchor and active points are defined by isReversed, and the /// insertion point is located at the active point. /// </summary> /// <param name="extent">The span that the selection covers.</param> /// <param name="isReversed"> /// True implies that <see cref="ActivePoint"/> comes before <see cref="AnchorPoint"/>. /// The <see cref="InsertionPoint"/> is set to the <see cref="ActivePoint"/>. /// <see cref="InsertionPointAffinity"/> is set to <see cref="PositionAffinity.Predecessor"/> when isReversed is true. /// <see cref="PositionAffinity.Successor"/> otherwise. /// </param> public Selection(VirtualSnapshotSpan extent, bool isReversed = false) { if (isReversed) { AnchorPoint = extent.End; ActivePoint = InsertionPoint = extent.Start; InsertionPointAffinity = PositionAffinity.Successor; } else { AnchorPoint = extent.Start; ActivePoint = InsertionPoint = extent.End; // The goal here is to keep the caret with the selection box. If we're wordwrapped, and the // box is at the end of a line, Predecessor will keep the caret on the previous line. InsertionPointAffinity = PositionAffinity.Predecessor; } }
/// <summary> /// Determines whether <paramref name="virtualSpan"/> intersects this span. Two spans are considered to /// intersect if they have positions in common or the end of one span /// coincides with the start of the other span. /// </summary> /// <param name="virtualSpan"> /// The virtual span to check. /// </param> /// <returns> /// <c>true</c> if the spans intersect, otherwise <c>false</c>. /// </returns> public bool IntersectsWith(VirtualSnapshotSpan virtualSpan) { return(virtualSpan._start <= _end && virtualSpan._end >= _start); }
/// <summary> /// Determines whether <paramref name="virtualSpan"/> falls completely within /// this virtual span. /// </summary> /// <param name="virtualSpan"> /// The virtual span to check. /// </param> /// <returns> /// <c>true</c> if the specified span falls completely within this span, /// otherwise <c>false</c>. /// </returns> public bool Contains(VirtualSnapshotSpan virtualSpan) { return(virtualSpan._start >= _start && virtualSpan._end <= _end); }