Merge pull request #242 from yyjdelete/concat

Fix ArgumentOutOfRangeException in RichText.Concat()
This commit is contained in:
Daniel Grunwald 2020-09-06 21:11:26 +02:00 коммит произвёл GitHub
Родитель 6f24c1dd0a 2598da953f
Коммит 25a8c2a474
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 45 добавлений и 2 удалений

Просмотреть файл

@ -0,0 +1,43 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Highlighting
{
[TestFixture]
public class RichTextTests
{
[Test]
public void ConcatTest()
{
var textModel = new RichTextModel();
textModel.SetHighlighting(0, 5, new HighlightingColor { Name = "text1" });
var text1 = new RichText("text1", textModel);
var textModel2 = new RichTextModel();
textModel2.SetHighlighting(0, 5, new HighlightingColor { Name = "text2" });
var text2 = new RichText("text2", textModel2);
RichText text3 = RichText.Concat(text1, RichText.Empty, text2);
Assert.AreEqual(text1.GetHighlightingAt(0), text3.GetHighlightingAt(0));
Assert.AreNotEqual(text1.GetHighlightingAt(0), text3.GetHighlightingAt(5));
Assert.AreEqual(text2.GetHighlightingAt(0), text3.GetHighlightingAt(5));
}
}
}

Просмотреть файл

@ -154,8 +154,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting
{
Debug.Assert(newOffsets.Length == newColors.Length);
Debug.Assert(newOffsets[0] == 0);
// remove everything before offset:
while (stateChangeOffsets.Count > 0 && stateChangeOffsets.Last() <= offset) {
// remove everything not before offset:
while (stateChangeOffsets.Count > 0 && stateChangeOffsets.Last() >= offset) {
stateChangeOffsets.RemoveAt(stateChangeOffsets.Count - 1);
stateChanges.RemoveAt(stateChanges.Count - 1);
}