Browse Source

AvalonEdit: Fixed bugs in "Spaces to tabs" and "Remove trailing whitespace".

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4942 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
11e4bb94bb
  1. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/ChangeTrackingTest.cs
  2. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/CollapsingTests.cs
  3. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/HeightTests.cs
  4. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/LineManagerTests.cs
  5. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/RandomizedLineManagerTest.cs
  6. 42
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/TextAnchorTest.cs
  7. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/TextSegmentTreeTest.cs
  8. 80
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/TextUtilitiesTests.cs
  9. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Editing/TextSegmentReadOnlySectionTests.cs
  10. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.csproj
  11. 3
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Utils/CaretNavigationTests.cs
  12. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Utils/CompressingTreeListTests.cs
  13. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Utils/ExtensionMethodsTests.cs
  14. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Utils/IndentationStringTests.cs
  15. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Utils/RopeTests.cs
  16. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/WeakReferenceTests.cs
  17. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/XmlParser/ParserTests.cs
  18. 15
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/ISegment.cs
  19. 56
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs
  20. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextAnchorTree.cs
  21. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs
  22. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextUtilities.cs
  23. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/ChangeTrackingTest.cs

@ -9,7 +9,7 @@ using System; @@ -9,7 +9,7 @@ using System;
using System.Linq;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Document.Tests
namespace ICSharpCode.AvalonEdit.Document
{
[TestFixture]
public class ChangeTrackingTest

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/CollapsingTests.cs

@ -9,7 +9,7 @@ using System; @@ -9,7 +9,7 @@ using System;
using ICSharpCode.AvalonEdit.Rendering;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Document.Tests
namespace ICSharpCode.AvalonEdit.Document
{
[TestFixture]
public class CollapsingTests

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/HeightTests.cs

@ -10,7 +10,7 @@ using System.Linq; @@ -10,7 +10,7 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Rendering;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Document.Tests
namespace ICSharpCode.AvalonEdit.Document
{
[TestFixture]
public class HeightTests

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/LineManagerTests.cs

@ -9,7 +9,7 @@ using System; @@ -9,7 +9,7 @@ using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Document.Tests
namespace ICSharpCode.AvalonEdit.Document
{
[TestFixture]
public class LineManagerTests

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/RandomizedLineManagerTest.cs

@ -10,7 +10,7 @@ using System.Collections.Generic; @@ -10,7 +10,7 @@ using System.Collections.Generic;
using ICSharpCode.AvalonEdit.Rendering;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Document.Tests
namespace ICSharpCode.AvalonEdit.Document
{
/// <summary>
/// A randomized test for the line manager.

42
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/TextAnchorTest.cs

@ -9,7 +9,7 @@ using System; @@ -9,7 +9,7 @@ using System;
using NUnit.Framework;
using System.Collections.Generic;
namespace ICSharpCode.AvalonEdit.Document.Tests
namespace ICSharpCode.AvalonEdit.Document
{
[TestFixture]
public class TextAnchorTest
@ -273,5 +273,45 @@ namespace ICSharpCode.AvalonEdit.Document.Tests @@ -273,5 +273,45 @@ namespace ICSharpCode.AvalonEdit.Document.Tests
GC.Collect();
}
}
[Test]
public void ReplaceSpacesWithTab()
{
document.Text = "a b";
TextAnchor before = document.CreateAnchor(1);
before.MovementType = AnchorMovementType.AfterInsertion;
TextAnchor after = document.CreateAnchor(5);
TextAnchor survivingMiddle = document.CreateAnchor(2);
TextAnchor deletedMiddle = document.CreateAnchor(3);
document.Replace(1, 4, "\t", OffsetChangeMappingType.CharacterReplace);
Assert.AreEqual("a\tb", document.Text);
// yes, the movement is a bit strange; but that's how CharacterReplace works when the text gets shorter
Assert.AreEqual(1, before.Offset);
Assert.AreEqual(2, after.Offset);
Assert.AreEqual(2, survivingMiddle.Offset);
Assert.AreEqual(2, deletedMiddle.Offset);
}
[Test]
public void ReplaceTwoCharactersWithThree()
{
document.Text = "a12b";
TextAnchor before = document.CreateAnchor(1);
before.MovementType = AnchorMovementType.AfterInsertion;
TextAnchor after = document.CreateAnchor(3);
before.MovementType = AnchorMovementType.BeforeInsertion;
TextAnchor middleB = document.CreateAnchor(2);
before.MovementType = AnchorMovementType.BeforeInsertion;
TextAnchor middleA = document.CreateAnchor(2);
before.MovementType = AnchorMovementType.AfterInsertion;
document.Replace(1, 2, "123", OffsetChangeMappingType.CharacterReplace);
Assert.AreEqual("a123b", document.Text);
Assert.AreEqual(1, before.Offset);
Assert.AreEqual(4, after.Offset);
Assert.AreEqual(2, middleA.Offset);
Assert.AreEqual(2, middleB.Offset);
}
}
}

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/TextSegmentTreeTest.cs

@ -9,7 +9,7 @@ using System; @@ -9,7 +9,7 @@ using System;
using NUnit.Framework;
using System.Collections.Generic;
namespace ICSharpCode.AvalonEdit.Document.Tests
namespace ICSharpCode.AvalonEdit.Document
{
[TestFixture]
public class TextSegmentTreeTest

80
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/TextUtilitiesTests.cs

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Document
{
[TestFixture]
public class TextUtilitiesTests
{
#region GetWhitespaceAfter
[Test]
public void TestGetWhitespaceAfter()
{
Assert.AreEqual(new SimpleSegment(2, 3), TextUtilities.GetWhitespaceAfter(new StringTextSource("a \t \tb"), 2));
}
[Test]
public void TestGetWhitespaceAfterDoesNotSkipNewLine()
{
Assert.AreEqual(new SimpleSegment(2, 3), TextUtilities.GetWhitespaceAfter(new StringTextSource("a \t \tb"), 2));
}
[Test]
public void TestGetWhitespaceAfterEmptyResult()
{
Assert.AreEqual(new SimpleSegment(2, 0), TextUtilities.GetWhitespaceAfter(new StringTextSource("a b"), 2));
}
[Test]
public void TestGetWhitespaceAfterEndOfString()
{
Assert.AreEqual(new SimpleSegment(2, 0), TextUtilities.GetWhitespaceAfter(new StringTextSource("a "), 2));
}
[Test]
public void TestGetWhitespaceAfterUntilEndOfString()
{
Assert.AreEqual(new SimpleSegment(2, 3), TextUtilities.GetWhitespaceAfter(new StringTextSource("a \t \t"), 2));
}
#endregion
#region GetWhitespaceBefore
[Test]
public void TestGetWhitespaceBefore()
{
Assert.AreEqual(new SimpleSegment(1, 3), TextUtilities.GetWhitespaceBefore(new StringTextSource("a\t \t b"), 4));
}
[Test]
public void TestGetWhitespaceBeforeDoesNotSkipNewLine()
{
Assert.AreEqual(new SimpleSegment(2, 1), TextUtilities.GetWhitespaceBefore(new StringTextSource("a\n b"), 3));
}
[Test]
public void TestGetWhitespaceBeforeEmptyResult()
{
Assert.AreEqual(new SimpleSegment(2, 0), TextUtilities.GetWhitespaceBefore(new StringTextSource(" a b"), 2));
}
[Test]
public void TestGetWhitespaceBeforeStartOfString()
{
Assert.AreEqual(new SimpleSegment(0, 0), TextUtilities.GetWhitespaceBefore(new StringTextSource(" a"), 0));
}
[Test]
public void TestGetWhitespaceBeforeUntilStartOfString()
{
Assert.AreEqual(new SimpleSegment(0, 2), TextUtilities.GetWhitespaceBefore(new StringTextSource(" \t a"), 2));
}
#endregion
}
}

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Editing/TextSegmentReadOnlySectionTests.cs

@ -10,7 +10,7 @@ using System; @@ -10,7 +10,7 @@ using System;
using System.Linq;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Editing.Tests
namespace ICSharpCode.AvalonEdit.Editing
{
[TestFixture]
public class TextSegmentReadOnlySectionTests

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.csproj

@ -71,6 +71,7 @@ @@ -71,6 +71,7 @@
<Compile Include="Document\ChangeTrackingTest.cs" />
<Compile Include="Document\TextAnchorTest.cs" />
<Compile Include="Document\TextSegmentTreeTest.cs" />
<Compile Include="Document\TextUtilitiesTests.cs" />
<Compile Include="Editing\TextSegmentReadOnlySectionTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Document\CollapsingTests.cs" />

3
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Utils/CaretNavigationTests.cs

@ -8,10 +8,9 @@ @@ -8,10 +8,9 @@
using System;
using System.Windows.Documents;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Utils;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Tests.Utils
namespace ICSharpCode.AvalonEdit.Utils
{
[TestFixture]
public class CaretNavigationTests

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Utils/CompressingTreeListTests.cs

@ -10,7 +10,7 @@ using System; @@ -10,7 +10,7 @@ using System;
using System.Linq;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Utils.Tests
namespace ICSharpCode.AvalonEdit.Utils
{
[TestFixture]
public class CompressingTreeListTests

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Utils/ExtensionMethodsTests.cs

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
using System;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Utils.Tests
namespace ICSharpCode.AvalonEdit.Utils
{
[TestFixture]
public class ExtensionMethodsTests

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Utils/IndentationStringTests.cs

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
using System;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Tests.Utils
namespace ICSharpCode.AvalonEdit.Utils
{
[TestFixture]
public class IndentationStringTests

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Utils/RopeTests.cs

@ -12,7 +12,7 @@ using System.IO; @@ -12,7 +12,7 @@ using System.IO;
using NUnit.Framework;
using System.Text;
namespace ICSharpCode.AvalonEdit.Utils.Tests
namespace ICSharpCode.AvalonEdit.Utils
{
[TestFixture]
public class RopeTests

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/WeakReferenceTests.cs

@ -11,7 +11,7 @@ using ICSharpCode.AvalonEdit.Editing; @@ -11,7 +11,7 @@ using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Rendering;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Tests
namespace ICSharpCode.AvalonEdit
{
[TestFixture]
public class WeakReferenceTests

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/XmlParser/ParserTests.cs

@ -16,7 +16,7 @@ using ICSharpCode.AvalonEdit.Xml; @@ -16,7 +16,7 @@ using ICSharpCode.AvalonEdit.Xml;
using ICSharpCode.SharpZipLib.Zip;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Xml.Tests
namespace ICSharpCode.AvalonEdit.Xml
{
class TestFile
{

15
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/ISegment.cs

@ -5,9 +5,10 @@ @@ -5,9 +5,10 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.AvalonEdit.Utils;
using System;
using System.Diagnostics;
using ICSharpCode.AvalonEdit.Utils;
using System.Globalization;
namespace ICSharpCode.AvalonEdit.Document
{
@ -126,6 +127,12 @@ namespace ICSharpCode.AvalonEdit.Document @@ -126,6 +127,12 @@ namespace ICSharpCode.AvalonEdit.Document
{
return !left.Equals(right);
}
/// <inheritdoc/>
public override string ToString()
{
return "[Offset=" + Offset.ToString(CultureInfo.InvariantCulture) + ", Length=" + Length.ToString(CultureInfo.InvariantCulture) + "]";
}
}
/// <summary>
@ -200,5 +207,11 @@ namespace ICSharpCode.AvalonEdit.Document @@ -200,5 +207,11 @@ namespace ICSharpCode.AvalonEdit.Document
this.end.SurviveDeletion = true;
this.start.MovementType = AnchorMovementType.BeforeInsertion;
}
/// <inheritdoc/>
public override string ToString()
{
return "[Offset=" + Offset.ToString(CultureInfo.InvariantCulture) + ", EndOffset=" + EndOffset.ToString(CultureInfo.InvariantCulture) + "]";
}
}
}

56
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs

@ -22,7 +22,8 @@ namespace ICSharpCode.AvalonEdit.Document @@ -22,7 +22,8 @@ namespace ICSharpCode.AvalonEdit.Document
/// <summary>
/// Normal replace.
/// Anchors in front of the replaced region will stay in front, anchors after the replaced region will stay after.
/// Anchors in the middle of the removed region will move depending on their AnchorMovementType.
/// Anchors in the middle of the removed region will be deleted. Ifthey survive deletion,
/// they move depending on their AnchorMovementType.
/// </summary>
/// <remarks>
/// This is the default implementation of DocumentChangeEventArgs when OffsetChangeMap is null,
@ -51,7 +52,8 @@ namespace ICSharpCode.AvalonEdit.Document @@ -51,7 +52,8 @@ namespace ICSharpCode.AvalonEdit.Document
/// with itself and the additional text segment. A simple insertion of the additional text would have the undesired
/// effect of moving anchors immediately after the replaced text into the replacement text if they used
/// AnchorMovementStyle.BeforeInsertion.
/// Shrinking text is implemented by removing the text segment that's too long.
/// Shrinking text is implemented by removing the text segment that's too long; but in a special mode that
/// causes anchors to always survive irrespective of their <see cref="TextAnchor.SurviveDeletion"/> setting.
/// If the text keeps its old size, this is implemented as OffsetChangeMap.Empty.
/// </remarks>
CharacterReplace
@ -203,9 +205,11 @@ namespace ICSharpCode.AvalonEdit.Document @@ -203,9 +205,11 @@ namespace ICSharpCode.AvalonEdit.Document
public struct OffsetChangeMapEntry : IEquatable<OffsetChangeMapEntry>
{
readonly int offset;
readonly int removalLength;
readonly int insertionLength;
// MSB: RemovalNeverCausesAnchorDeletion; other 31 bits: RemovalLength
readonly uint removalLengthWithDeletionFlag;
/// <summary>
/// The offset at which the change occurs.
/// </summary>
@ -213,20 +217,27 @@ namespace ICSharpCode.AvalonEdit.Document @@ -213,20 +217,27 @@ namespace ICSharpCode.AvalonEdit.Document
get { return offset; }
}
/// <summary>
/// The number of characters inserted.
/// Returns 0 if this entry represents a removal.
/// </summary>
public int InsertionLength {
get { return insertionLength; }
}
/// <summary>
/// The number of characters removed.
/// Returns 0 if this entry represents an insertion.
/// </summary>
public int RemovalLength {
get { return removalLength; }
get { return (int)(removalLengthWithDeletionFlag & 0x7fffffff); }
}
/// <summary>
/// The number of characters inserted.
/// Returns 0 if this entry represents a removal.
/// Gets whether the removal should not cause any anchor deletions.
/// </summary>
public int InsertionLength {
get { return insertionLength; }
public bool RemovalNeverCausesAnchorDeletion {
get { return (removalLengthWithDeletionFlag & 0x80000000) != 0; }
}
/// <summary>
@ -234,25 +245,26 @@ namespace ICSharpCode.AvalonEdit.Document @@ -234,25 +245,26 @@ namespace ICSharpCode.AvalonEdit.Document
/// </summary>
public int GetNewOffset(int oldOffset, AnchorMovementType movementType)
{
if (!(this.removalLength == 0 && oldOffset == this.offset)) {
int removalLength = this.RemovalLength;
if (!(removalLength == 0 && oldOffset == offset)) {
// we're getting trouble (both if statements in here would apply)
// if there's no removal and we insert at the offset
// -> we'd need to disambiguate by movementType, which is handled after the if
// offset is before start of change: no movement
if (oldOffset <= this.offset)
if (oldOffset <= offset)
return oldOffset;
// offset is after end of change: movement by normal delta
if (oldOffset >= this.offset + this.removalLength)
return oldOffset + this.insertionLength - this.removalLength;
if (oldOffset >= offset + removalLength)
return oldOffset + insertionLength - removalLength;
}
// we reach this point if
// a) the oldOffset is inside the deleted segment
// b) there was no removal and we insert at the caret position
if (movementType == AnchorMovementType.AfterInsertion)
return this.offset + this.insertionLength;
return offset + insertionLength;
else
return this.offset;
return offset;
}
/// <summary>
@ -265,15 +277,25 @@ namespace ICSharpCode.AvalonEdit.Document @@ -265,15 +277,25 @@ namespace ICSharpCode.AvalonEdit.Document
ThrowUtil.CheckNotNegative(insertionLength, "insertionLength");
this.offset = offset;
this.removalLength = removalLength;
this.removalLengthWithDeletionFlag = (uint)removalLength;
this.insertionLength = insertionLength;
}
/// <summary>
/// Creates a new OffsetChangeMapEntry instance.
/// </summary>
public OffsetChangeMapEntry(int offset, int removalLength, int insertionLength, bool removalNeverCausesAnchorDeletion)
: this(offset, removalLength, insertionLength)
{
if (removalNeverCausesAnchorDeletion)
this.removalLengthWithDeletionFlag |= 0x80000000;
}
/// <inheritdoc/>
public override int GetHashCode()
{
unchecked {
return offset + 3559 * insertionLength + 3571 * removalLength;
return offset + 3559 * insertionLength + 3571 * (int)removalLengthWithDeletionFlag;
}
}
@ -286,7 +308,7 @@ namespace ICSharpCode.AvalonEdit.Document @@ -286,7 +308,7 @@ namespace ICSharpCode.AvalonEdit.Document
/// <inheritdoc/>
public bool Equals(OffsetChangeMapEntry other)
{
return offset == other.offset && insertionLength == other.insertionLength && removalLength == other.removalLength;
return offset == other.offset && insertionLength == other.insertionLength && removalLengthWithDeletionFlag == other.removalLengthWithDeletionFlag;
}
/// <summary>

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextAnchorTree.cs

@ -204,7 +204,7 @@ namespace ICSharpCode.AvalonEdit.Document @@ -204,7 +204,7 @@ namespace ICSharpCode.AvalonEdit.Document
// go forward through the tree and delete all nodes in the removal segment
while (node != null && offset + remainingRemovalLength > node.length) {
TextAnchor anchor = (TextAnchor)node.Target;
if (anchor != null && anchor.SurviveDeletion) {
if (anchor != null && (anchor.SurviveDeletion || entry.RemovalNeverCausesAnchorDeletion)) {
if (firstDeletionSurvivor == null)
firstDeletionSurvivor = node;
// This node should be deleted, but it wants to survive.

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs

@ -447,11 +447,11 @@ namespace ICSharpCode.AvalonEdit.Document @@ -447,11 +447,11 @@ namespace ICSharpCode.AvalonEdit.Document
Replace(offset, length, text, null);
} else if (text.Length > length) {
// look at OffsetChangeMappingType.CharacterReplace XML comments on why we need to replace
// the last
// the last character
OffsetChangeMapEntry entry = new OffsetChangeMapEntry(offset + length - 1, 1, 1 + text.Length - length);
Replace(offset, length, text, OffsetChangeMap.FromSingleElement(entry));
} else if (text.Length < length) {
OffsetChangeMapEntry entry = new OffsetChangeMapEntry(offset + length - text.Length, length - text.Length, 0);
OffsetChangeMapEntry entry = new OffsetChangeMapEntry(offset + text.Length, length - text.Length, 0, true);
Replace(offset, length, text, OffsetChangeMap.FromSingleElement(entry));
} else {
Replace(offset, length, text, OffsetChangeMap.Empty);

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextUtilities.cs

@ -118,6 +118,7 @@ namespace ICSharpCode.AvalonEdit.Document @@ -118,6 +118,7 @@ namespace ICSharpCode.AvalonEdit.Document
if (c != ' ' && c != '\t')
break;
}
pos++; // go back the one character that isn't whitespace
return new SimpleSegment(pos, offset - pos);
}

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs

@ -457,7 +457,7 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -457,7 +457,7 @@ namespace ICSharpCode.AvalonEdit.Editing
if (document.GetCharAt(offset) == ' ') {
spacesCount++;
if (spacesCount == indentationSize) {
document.Replace(offset, indentationSize, "\t", OffsetChangeMappingType.CharacterReplace);
document.Replace(offset - (indentationSize - 1), indentationSize, "\t", OffsetChangeMappingType.CharacterReplace);
spacesCount = 0;
offset -= indentationSize - 1;
endOffset -= indentationSize - 1;

Loading…
Cancel
Save