/// <summary>
		/// Finds all segments that overlap with the given segment (including touching segments).
		/// Segments are returned in the order given by GetNextSegment/GetPreviousSegment.
		/// </summary>
		/// <returns>Returns a new collection containing the results of the query.
		/// This means it is safe to modify the TextSegmentCollection while iterating through the result collection.</returns>
		public ReadOnlyCollection<T> FindOverlappingSegments(int offset, int length)
		{
			ThrowUtil.CheckNotNegative(length, "length");
			List<T> results = new List<T>();
			if (root != null) {
				FindOverlappingSegments(results, root, offset, offset + length);
			}
			return results.AsReadOnly();
		}
Пример #2
0
        /// <summary>
        /// Creates a new OffsetChangeMapEntry instance.
        /// </summary>
        public OffsetChangeMapEntry(int offset, int removalLength, int insertionLength)
        {
            ThrowUtil.CheckNotNegative(offset, "offset");
            ThrowUtil.CheckNotNegative(removalLength, "removalLength");
            ThrowUtil.CheckNotNegative(insertionLength, "insertionLength");

            this.offset          = offset;
            this.removalLength   = removalLength;
            this.insertionLength = insertionLength;
        }
Пример #3
0
        /// <summary>
        /// Creates a new OffsetChangeMapEntry instance.
        /// </summary>
        public OffsetChangeMapEntry(int offset, int removalLength, int insertionLength)
        {
            ThrowUtil.CheckNotNegative(offset, "offset");
            ThrowUtil.CheckNotNegative(removalLength, "removalLength");
            ThrowUtil.CheckNotNegative(insertionLength, "insertionLength");

            this.offset = offset;
            this.removalLengthWithDeletionFlag   = (uint)removalLength;
            this.insertionLengthWithMovementFlag = (uint)insertionLength;
        }
 /// <summary>
 /// Gets the visual column from a document offset relative to the first line start.
 /// </summary>
 public int GetVisualColumn(int relativeTextOffset)
 {
     ThrowUtil.CheckNotNegative(relativeTextOffset, "relativeTextOffset");
     foreach (VisualLineElement element in elements)
     {
         if (element.RelativeTextOffset <= relativeTextOffset &&
             element.RelativeTextOffset + element.DocumentLength >= relativeTextOffset)
         {
             return(element.GetVisualColumn(relativeTextOffset));
         }
     }
     return(VisualLength);
 }
        /// <summary>
        /// Gets the document offset (relative to the first line start) from a visual column.
        /// </summary>
        public int GetRelativeOffset(int visualColumn)
        {
            ThrowUtil.CheckNotNegative(visualColumn, "visualColumn");
            int documentLength = 0;

            foreach (VisualLineElement element in elements)
            {
                if (element.VisualColumn <= visualColumn &&
                    element.VisualColumn + element.VisualLength > visualColumn)
                {
                    return(element.GetRelativeOffset(visualColumn));
                }
                documentLength += element.DocumentLength;
            }
            return(documentLength);
        }
Пример #6
0
        /// <summary>
        /// Creates a new DocumentChangeEventArgs object.
        /// </summary>
        public DocumentChangeEventArgs(int offset, string removedText, string insertedText, OffsetChangeMap offsetChangeMap)
        {
            ThrowUtil.CheckNotNegative(offset, "offset");
            ThrowUtil.CheckNotNull(removedText, "removedText");
            ThrowUtil.CheckNotNull(insertedText, "insertedText");

            Offset       = offset;
            RemovedText  = removedText;
            InsertedText = insertedText;

            if (offsetChangeMap != null)
            {
                if (!offsetChangeMap.IsFrozen)
                {
                    throw new ArgumentException("The OffsetChangeMap must be frozen before it can be used in DocumentChangeEventArgs");
                }
                if (!offsetChangeMap.IsValidForDocumentChange(offset, removedText.Length, insertedText.Length))
                {
                    throw new ArgumentException("OffsetChangeMap is not valid for this document change", nameof(offsetChangeMap));
                }
                this.offsetChangeMap = offsetChangeMap;
            }
        }