Ejemplo n.º 1
0
        List <VirtualSnapshotSpan> GetSelectedSpans()
        {
            var list = new List <VirtualSnapshotSpan>();

            if (Mode == TextSelectionMode.Stream)
            {
                list.Add(StreamSelectionSpan);
            }
            else
            {
                var helper = new BoxSelectionHelper(this);
                var start  = Start;
                while (start <= End)
                {
                    var line = TextView.GetTextViewLineContainingBufferPosition(start.Position);
                    list.Add(helper.GetSpan(line));
                    if (line.IsLastDocumentLine())
                    {
                        break;
                    }
                    start = new VirtualSnapshotPoint(line.GetPointAfterLineBreak());
                }
            }

            // At least one span must be included, even if the span's empty
            if (list.Count == 0)
            {
                list.Add(StreamSelectionSpan);
            }

            return(list);
        }
Ejemplo n.º 2
0
 public VirtualSnapshotSpan?GetSelectionOnTextViewLine(ITextViewLine line)
 {
     if (line == null)
     {
         throw new ArgumentNullException(nameof(line));
     }
     if (line.Snapshot != TextView.TextSnapshot)
     {
         throw new ArgumentException();
     }
     if (IsEmpty)
     {
         if (line.ContainsBufferPosition(ActivePoint.Position))
         {
             return(new VirtualSnapshotSpan(ActivePoint, ActivePoint));
         }
         return(null);
     }
     if (Mode == TextSelectionMode.Stream)
     {
         var spanTmp = line.ExtentIncludingLineBreak.Intersection(StreamSelectionSpan.SnapshotSpan);
         if (spanTmp == null)
         {
             return(null);
         }
         var span = spanTmp.Value;
         if (End > new VirtualSnapshotPoint(line.End))
         {
             span = new SnapshotSpan(span.Start, line.EndIncludingLineBreak);
         }
         if (span.Length == 0)
         {
             return(null);
         }
         return(new VirtualSnapshotSpan(span));
     }
     else
     {
         Debug.Assert(Mode == TextSelectionMode.Box);
         if (!line.IntersectsBufferSpan(StreamSelectionSpan.SnapshotSpan))
         {
             return(null);
         }
         var helper = new BoxSelectionHelper(this);
         return(helper.GetSpan(line));
     }
 }
Ejemplo n.º 3
0
		List<VirtualSnapshotSpan> GetSelectedSpans() {
			var list = new List<VirtualSnapshotSpan>();

			if (Mode == TextSelectionMode.Stream)
				list.Add(StreamSelectionSpan);
			else {
				var helper = new BoxSelectionHelper(this);
				var start = Start;
				while (start <= End) {
					var line = TextView.GetTextViewLineContainingBufferPosition(start.Position);
					list.Add(helper.GetSpan(line));
					if (line.IsLastDocumentLine())
						break;
					start = new VirtualSnapshotPoint(line.GetPointAfterLineBreak());
				}
			}

			// At least one span must be included, even if the span's empty
			if (list.Count == 0)
				list.Add(StreamSelectionSpan);

			return list;
		}
Ejemplo n.º 4
0
		public VirtualSnapshotSpan? GetSelectionOnTextViewLine(ITextViewLine line) {
			if (line == null)
				throw new ArgumentNullException(nameof(line));
			if (line.Snapshot != TextView.TextSnapshot)
				throw new ArgumentException();
			if (IsEmpty) {
				if (line.ContainsBufferPosition(ActivePoint.Position))
					return new VirtualSnapshotSpan(ActivePoint, ActivePoint);
				return null;
			}
			if (Mode == TextSelectionMode.Stream) {
				var spanTmp = line.ExtentIncludingLineBreak.Intersection(StreamSelectionSpan.SnapshotSpan);
				if (spanTmp == null)
					return null;
				var span = spanTmp.Value;
				if (End > new VirtualSnapshotPoint(line.End))
					span = new SnapshotSpan(span.Start, line.EndIncludingLineBreak);
				if (span.Length == 0)
					return null;
				return new VirtualSnapshotSpan(span);
			}
			else {
				Debug.Assert(Mode == TextSelectionMode.Box);
				if (!line.IntersectsBufferSpan(StreamSelectionSpan.SnapshotSpan))
					return null;
				var helper = new BoxSelectionHelper(this);
				return helper.GetSpan(line);
			}
		}