Browse Source

Added some proposals.

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
3048d668c8
  1. 5
      ICSharpCode.Editor/IDocumentLine.cs
  2. 25
      ICSharpCode.Editor/ISegment.cs
  3. 16
      ICSharpCode.Editor/ITextBuffer.cs
  4. 115
      ICSharpCode.Editor/LinkedElement.cs
  5. 12
      ICSharpCode.Editor/TextLocation.cs

5
ICSharpCode.Editor/IDocumentLine.cs

@ -15,6 +15,11 @@ namespace ICSharpCode.Editor @@ -15,6 +15,11 @@ namespace ICSharpCode.Editor
/// </summary>
int TotalLength { get; }
/// <summary>
/// Gets the length of this line, excluding the line delimiter.
/// </summary>
int EditableLength { get; }
/// <summary>
/// Gets the length of the line terminator.
/// Returns 1 or 2; or 0 at the end of the document.

25
ICSharpCode.Editor/ISegment.cs

@ -27,4 +27,29 @@ namespace ICSharpCode.Editor @@ -27,4 +27,29 @@ namespace ICSharpCode.Editor
/// <remarks>EndOffset = Offset + Length;</remarks>
int EndOffset { get; }
}
public static class ISegmentExtensions
{
/// <summary>
/// True, if the segment contains the specified offset, false otherwise.
/// </summary>
/// <param name='offset'>
/// The offset.
/// </param>
public static bool Contains (this ISegment segment, int offset)
{
return segment.Offset <= offset && offset < segment.EndOffset;
}
/// <summary>
/// True, if the segment contains the specified segment, false otherwise.
/// </summary>
/// <param name='segment'>
/// The segment.
/// </param>
public static bool Contains (this ISegment thisSegment, ISegment segment)
{
return segment != null && thisSegment.Offset <= segment.Offset && segment.EndOffset <= thisSegment.EndOffset;
}
}
}

16
ICSharpCode.Editor/ITextBuffer.cs

@ -91,6 +91,22 @@ namespace ICSharpCode.Editor @@ -91,6 +91,22 @@ namespace ICSharpCode.Editor
/// <param name="count">Length of the area to search.</param>
/// <returns>The first index where any character was found; or -1 if no occurrence was found.</returns>
int IndexOfAny(char[] anyOf, int startIndex, int count);
/* What about:
void Insert (int offset, string value);
void Remove (int offset, int count);
void Remove (ISegment segment);
void Replace (int offset, int count, string value);
Or more search operations:
IEnumerable<int> SearchForward (string pattern, int startIndex);
IEnumerable<int> SearchForwardIgnoreCase (string pattern, int startIndex);
IEnumerable<int> SearchBackward (string pattern, int startIndex);
IEnumerable<int> SearchBackwardIgnoreCase (string pattern, int startIndex);
*/
}
/// <summary>

115
ICSharpCode.Editor/LinkedElement.cs

@ -5,59 +5,64 @@ using System; @@ -5,59 +5,64 @@ using System;
namespace ICSharpCode.Editor
{
/// <summary>
/// Represents an element in the text editor that is either editable, or bound to another editable element.
/// Used with <see cref="ITextEditor.ShowLinkedElements"/>
/// </summary>
public class LinkedElement
{
LinkedElement boundTo;
/// <summary>
/// Gets/Sets the start offset of this linked element.
/// </summary>
public int StartOffset { get; set; }
/// <summary>
/// Gets/Sets the end offset of this linked element.
/// </summary>
public int EndOffset { get; set; }
/// <summary>
/// Gets the linked element to which this element is bound.
/// </summary>
public LinkedElement BoundTo {
get { return boundTo; }
}
/// <summary>
/// Gets whether this element is editable. Returns true if this element is not bound.
/// </summary>
public bool IsEditable {
get { return boundTo == null; }
}
/// <summary>
/// Creates a new editable element.
/// </summary>
public LinkedElement(int startOffset, int endOffset)
{
this.StartOffset = startOffset;
this.EndOffset = endOffset;
}
/// <summary>
/// Creates a new element that is bound to <paramref name="boundTo"/>.
/// </summary>
public LinkedElement(int startOffset, int endOffset, LinkedElement boundTo)
{
if (boundTo == null)
throw new ArgumentNullException("boundTo");
this.StartOffset = startOffset;
this.EndOffset = endOffset;
while (boundTo.boundTo != null)
boundTo = boundTo.boundTo;
this.boundTo = boundTo;
}
}
// I'm not sure if we need this.
// How about a method in the context - this method could wrap the internal representation.
// public void StartTextLinkMode (int linkLength, IEnumerable<int> offsets)
// and maybe then variations taking more than one link element ?
// /// <summary>
// /// Represents an element in the text editor that is either editable, or bound to another editable element.
// /// Used with <see cref="ITextEditor.ShowLinkedElements"/>
// /// </summary>
// public class LinkedElement
// {
// LinkedElement boundTo;
//
// /// <summary>
// /// Gets/Sets the start offset of this linked element.
// /// </summary>
// public int StartOffset { get; set; }
//
// /// <summary>
// /// Gets/Sets the end offset of this linked element.
// /// </summary>
// public int EndOffset { get; set; }
//
// /// <summary>
// /// Gets the linked element to which this element is bound.
// /// </summary>
// public LinkedElement BoundTo {
// get { return boundTo; }
// }
//
// /// <summary>
// /// Gets whether this element is editable. Returns true if this element is not bound.
// /// </summary>
// public bool IsEditable {
// get { return boundTo == null; }
// }
//
// /// <summary>
// /// Creates a new editable element.
// /// </summary>
// public LinkedElement(int startOffset, int endOffset)
// {
// this.StartOffset = startOffset;
// this.EndOffset = endOffset;
// }
//
// /// <summary>
// /// Creates a new element that is bound to <paramref name="boundTo"/>.
// /// </summary>
// public LinkedElement(int startOffset, int endOffset, LinkedElement boundTo)
// {
// if (boundTo == null)
// throw new ArgumentNullException("boundTo");
// this.StartOffset = startOffset;
// this.EndOffset = endOffset;
// while (boundTo.boundTo != null)
// boundTo = boundTo.boundTo;
// this.boundTo = boundTo;
// }
// }
}

12
ICSharpCode.Editor/TextLocation.cs

@ -22,6 +22,16 @@ namespace ICSharpCode.Editor @@ -22,6 +22,16 @@ namespace ICSharpCode.Editor
/// </summary>
public static readonly TextLocation Empty = new TextLocation(0, 0);
/// <summary>
/// Constant of the minimum line.
/// </summary>
public const int MinLine = 1;
/// <summary>
/// Constant of the minimum column.
/// </summary>
public const int MinColumn = 1;
/// <summary>
/// Creates a TextLocation instance.
/// </summary>
@ -52,7 +62,7 @@ namespace ICSharpCode.Editor @@ -52,7 +62,7 @@ namespace ICSharpCode.Editor
/// </summary>
public bool IsEmpty {
get {
return column <= 0 && line <= 0;
return column < MinLine && line < MinColumn;
}
}

Loading…
Cancel
Save