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
/// </summary> /// </summary>
int TotalLength { get; } int TotalLength { get; }
/// <summary>
/// Gets the length of this line, excluding the line delimiter.
/// </summary>
int EditableLength { get; }
/// <summary> /// <summary>
/// Gets the length of the line terminator. /// Gets the length of the line terminator.
/// Returns 1 or 2; or 0 at the end of the document. /// Returns 1 or 2; or 0 at the end of the document.

25
ICSharpCode.Editor/ISegment.cs

@ -27,4 +27,29 @@ namespace ICSharpCode.Editor
/// <remarks>EndOffset = Offset + Length;</remarks> /// <remarks>EndOffset = Offset + Length;</remarks>
int EndOffset { get; } 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
/// <param name="count">Length of the area to search.</param> /// <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> /// <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); 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> /// <summary>

115
ICSharpCode.Editor/LinkedElement.cs

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

Loading…
Cancel
Save