[11700] | 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team |
---|
| 2 | // |
---|
| 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this |
---|
| 4 | // software and associated documentation files (the "Software"), to deal in the Software |
---|
| 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, |
---|
| 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons |
---|
| 7 | // to whom the Software is furnished to do so, subject to the following conditions: |
---|
| 8 | // |
---|
| 9 | // The above copyright notice and this permission notice shall be included in all copies or |
---|
| 10 | // substantial portions of the Software. |
---|
| 11 | // |
---|
| 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
---|
| 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
---|
| 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
---|
| 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
---|
| 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
| 17 | // DEALINGS IN THE SOFTWARE. |
---|
| 18 | |
---|
| 19 | using System; |
---|
| 20 | using System.Collections.Generic; |
---|
| 21 | using System.Runtime.CompilerServices; |
---|
| 22 | |
---|
| 23 | using ICSharpCode.AvalonEdit.Document; |
---|
| 24 | using ICSharpCode.AvalonEdit.Utils; |
---|
| 25 | #if NREFACTORY |
---|
| 26 | using ICSharpCode.NRefactory; |
---|
| 27 | using ICSharpCode.NRefactory.Editor; |
---|
| 28 | #endif |
---|
| 29 | |
---|
| 30 | namespace ICSharpCode.AvalonEdit.Editing |
---|
| 31 | { |
---|
| 32 | sealed class EmptySelection : Selection |
---|
| 33 | { |
---|
| 34 | public EmptySelection(TextArea textArea) : base(textArea) |
---|
| 35 | { |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | public override Selection UpdateOnDocumentChange(DocumentChangeEventArgs e) |
---|
| 39 | { |
---|
| 40 | return this; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | public override TextViewPosition StartPosition { |
---|
| 44 | get { return new TextViewPosition(TextLocation.Empty); } |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | public override TextViewPosition EndPosition { |
---|
| 48 | get { return new TextViewPosition(TextLocation.Empty); } |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | public override ISegment SurroundingSegment { |
---|
| 52 | get { return null; } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | public override Selection SetEndpoint(TextViewPosition endPosition) |
---|
| 56 | { |
---|
| 57 | throw new NotSupportedException(); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | public override Selection StartSelectionOrSetEndpoint(TextViewPosition startPosition, TextViewPosition endPosition) |
---|
| 61 | { |
---|
| 62 | var document = textArea.Document; |
---|
| 63 | if (document == null) |
---|
| 64 | throw ThrowUtil.NoDocumentAssigned(); |
---|
| 65 | return Create(textArea, startPosition, endPosition); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | public override IEnumerable<SelectionSegment> Segments { |
---|
| 69 | get { return Empty<SelectionSegment>.Array; } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | public override string GetText() |
---|
| 73 | { |
---|
| 74 | return string.Empty; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | public override void ReplaceSelectionWithText(string newText) |
---|
| 78 | { |
---|
| 79 | if (newText == null) |
---|
| 80 | throw new ArgumentNullException("newText"); |
---|
| 81 | newText = AddSpacesIfRequired(newText, textArea.Caret.Position, textArea.Caret.Position); |
---|
| 82 | if (newText.Length > 0) { |
---|
| 83 | if (textArea.ReadOnlySectionProvider.CanInsert(textArea.Caret.Offset)) { |
---|
| 84 | textArea.Document.Insert(textArea.Caret.Offset, newText); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | textArea.Caret.VisualColumn = -1; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | public override int Length { |
---|
| 91 | get { return 0; } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | // Use reference equality because there's only one EmptySelection per text area. |
---|
| 95 | public override int GetHashCode() |
---|
| 96 | { |
---|
| 97 | return RuntimeHelpers.GetHashCode(this); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | public override bool Equals(object obj) |
---|
| 101 | { |
---|
| 102 | return this == obj; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | } |
---|