Overwrite registered highlightings
This commit is contained in:
Родитель
d12a78257b
Коммит
1c833b8f73
|
@ -45,6 +45,9 @@ bld/
|
|||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
|
||||
using ICSharpCode.AvalonEdit.Highlighting;
|
||||
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ICSharpCode.AvalonEdit.Tests.Highlighting
|
||||
{
|
||||
[TestFixture]
|
||||
public class HighlightingManagerTests
|
||||
{
|
||||
[Test]
|
||||
public void OverwriteHighlightingDefinitionWithSameName()
|
||||
{
|
||||
var highlightingManager = new HighlightingManager();
|
||||
|
||||
var definitionA = CreateDefinition("TestDefinition");
|
||||
var definitionB = CreateDefinition("TestDefinition");
|
||||
var definitionC = CreateDefinition("DifferentName");
|
||||
|
||||
Assert.That(highlightingManager.HighlightingDefinitions, Is.Empty);
|
||||
|
||||
highlightingManager.RegisterHighlighting(definitionA.Name, Array.Empty<string>(), definitionA);
|
||||
Assert.That(highlightingManager.HighlightingDefinitions, Is.EqualTo(new[] { definitionA }));
|
||||
|
||||
highlightingManager.RegisterHighlighting(definitionB.Name, Array.Empty<string>(), definitionB);
|
||||
Assert.That(highlightingManager.HighlightingDefinitions, Is.EqualTo(new[] { definitionB }));
|
||||
|
||||
highlightingManager.RegisterHighlighting(definitionC.Name, Array.Empty<string>(), definitionC);
|
||||
Assert.That(highlightingManager.HighlightingDefinitions, Is.EqualTo(new[] { definitionB, definitionC }));
|
||||
|
||||
XmlHighlightingDefinition CreateDefinition(string name)
|
||||
{
|
||||
return new XmlHighlightingDefinition(new XshdSyntaxDefinition { Name = name, Elements = { new XshdRuleSet() } }, highlightingManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -185,8 +185,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting
|
|||
throw new ArgumentNullException("highlighting");
|
||||
|
||||
lock (lockObj) {
|
||||
allHighlightings.Add(highlighting);
|
||||
if (name != null) {
|
||||
if (highlightingsByName.TryGetValue(name, out var existingDefinition))
|
||||
allHighlightings.Remove(existingDefinition);
|
||||
highlightingsByName[name] = highlighting;
|
||||
}
|
||||
if (extensions != null) {
|
||||
|
@ -194,6 +195,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
|
|||
highlightingsByExtension[ext] = highlighting;
|
||||
}
|
||||
}
|
||||
allHighlightings.Add(highlighting);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче