17 changed files with 400 additions and 196 deletions
@ -0,0 +1,75 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Runtime.CompilerServices; |
||||||
|
using ICSharpCode.AvalonEdit.Document; |
||||||
|
using ICSharpCode.AvalonEdit.Utils; |
||||||
|
|
||||||
|
namespace ICSharpCode.AvalonEdit.Editing |
||||||
|
{ |
||||||
|
sealed class EmptySelection : Selection |
||||||
|
{ |
||||||
|
public EmptySelection(TextArea textArea) : base(textArea) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override Selection UpdateOnDocumentChange(DocumentChangeEventArgs e) |
||||||
|
{ |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public override ISegment SurroundingSegment { |
||||||
|
get { return null; } |
||||||
|
} |
||||||
|
|
||||||
|
public override Selection SetEndpoint(TextViewPosition endPosition) |
||||||
|
{ |
||||||
|
throw new NotSupportedException(); |
||||||
|
} |
||||||
|
|
||||||
|
public override Selection StartSelectionOrSetEndpoint(TextViewPosition startPosition, TextViewPosition endPosition) |
||||||
|
{ |
||||||
|
var document = textArea.Document; |
||||||
|
if (document == null) |
||||||
|
throw ThrowUtil.NoDocumentAssigned(); |
||||||
|
return Create(textArea, document.GetOffset(startPosition), document.GetOffset(endPosition)); |
||||||
|
} |
||||||
|
|
||||||
|
public override IEnumerable<SelectionSegment> Segments { |
||||||
|
get { return Empty<SelectionSegment>.Array; } |
||||||
|
} |
||||||
|
|
||||||
|
public override string GetText() |
||||||
|
{ |
||||||
|
return string.Empty; |
||||||
|
} |
||||||
|
|
||||||
|
public override void ReplaceSelectionWithText(string newText) |
||||||
|
{ |
||||||
|
if (newText == null) |
||||||
|
throw new ArgumentNullException("newText"); |
||||||
|
if (newText.Length > 0) { |
||||||
|
if (textArea.ReadOnlySectionProvider.CanInsert(textArea.Caret.Offset)) { |
||||||
|
textArea.Document.Insert(textArea.Caret.Offset, newText); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override int Length { |
||||||
|
get { return 0; } |
||||||
|
} |
||||||
|
|
||||||
|
// Use reference equality because there's only one EmptySelection per text area.
|
||||||
|
public override int GetHashCode() |
||||||
|
{ |
||||||
|
return RuntimeHelpers.GetHashCode(this); |
||||||
|
} |
||||||
|
|
||||||
|
public override bool Equals(object obj) |
||||||
|
{ |
||||||
|
return this == obj; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,63 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.AvalonEdit.Document; |
||||||
|
|
||||||
|
namespace ICSharpCode.AvalonEdit.Editing |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Represents a selected segment.
|
||||||
|
/// </summary>
|
||||||
|
public class SelectionSegment : ISegment |
||||||
|
{ |
||||||
|
int startOffset, endOffset; |
||||||
|
int startVC, endVC; |
||||||
|
|
||||||
|
public SelectionSegment(int startOffset, int endOffset) |
||||||
|
{ |
||||||
|
this.startOffset = Math.Min(startOffset, endOffset); |
||||||
|
this.endOffset = Math.Max(startOffset, endOffset); |
||||||
|
} |
||||||
|
|
||||||
|
public SelectionSegment(int startOffset, int startVC, int endOffset, int endVC) |
||||||
|
{ |
||||||
|
if (startOffset <= endOffset) { |
||||||
|
this.startOffset = startOffset; |
||||||
|
this.startVC = startVC; |
||||||
|
this.endOffset = endOffset; |
||||||
|
this.endVC = endVC; |
||||||
|
} else { |
||||||
|
this.startOffset = endOffset; |
||||||
|
this.startVC = endVC; |
||||||
|
this.endOffset = startOffset; |
||||||
|
this.endVC = startVC; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int StartOffset { |
||||||
|
get { return startOffset; } |
||||||
|
} |
||||||
|
|
||||||
|
public int EndOffset { |
||||||
|
get { return endOffset; } |
||||||
|
} |
||||||
|
|
||||||
|
public int StartVisualColumn { |
||||||
|
get { return startVC; } |
||||||
|
} |
||||||
|
|
||||||
|
public int EndVisualColumn { |
||||||
|
get { return endVC; } |
||||||
|
} |
||||||
|
|
||||||
|
int ISegment.Offset { |
||||||
|
get { return startOffset; } |
||||||
|
} |
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public int Length { |
||||||
|
get { return endOffset - startOffset; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue