Browse Source

Changed highlighting engine to avoid 'merging' colors when both the <Span> and <Begin> tags have a color specified.

Instead, we create a nested HighlightingSection for the <Begin>-color within the section for the <Span>-color.
This fixes customization of such colors.
pull/24/head
Daniel Grunwald 14 years ago
parent
commit
d617374336
  1. 10
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/DocumentHighlighter.cs
  2. 12
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingSpan.cs
  3. 19
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XmlHighlightingDefinition.cs

10
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/DocumentHighlighter.cs

@ -282,11 +282,14 @@ namespace ICSharpCode.AvalonEdit.Highlighting
Debug.Assert(position == firstMatch.Index); Debug.Assert(position == firstMatch.Index);
if (firstMatch == endSpanMatch) { if (firstMatch == endSpanMatch) {
PopColor(); // pop SpanColor
HighlightingSpan poppedSpan = spanStack.Peek(); HighlightingSpan poppedSpan = spanStack.Peek();
if (!poppedSpan.SpanColorIncludesEnd)
PopColor(); // pop SpanColor
PushColor(poppedSpan.EndColor); PushColor(poppedSpan.EndColor);
position = firstMatch.Index + firstMatch.Length; position = firstMatch.Index + firstMatch.Length;
PopColor(); // pop EndColor PopColor(); // pop EndColor
if (poppedSpan.SpanColorIncludesEnd)
PopColor(); // pop SpanColor
spanStack = spanStack.Pop(); spanStack = spanStack.Pop();
currentRuleSet = this.CurrentRuleSet; currentRuleSet = this.CurrentRuleSet;
//FreeMatchArray(matches); //FreeMatchArray(matches);
@ -312,10 +315,13 @@ namespace ICSharpCode.AvalonEdit.Highlighting
currentRuleSet = this.CurrentRuleSet; currentRuleSet = this.CurrentRuleSet;
storedMatchArrays.Push(matches); storedMatchArrays.Push(matches);
matches = AllocateMatchArray(currentRuleSet.Spans.Count); matches = AllocateMatchArray(currentRuleSet.Spans.Count);
if (newSpan.SpanColorIncludesStart)
PushColor(newSpan.SpanColor);
PushColor(newSpan.StartColor); PushColor(newSpan.StartColor);
position = firstMatch.Index + firstMatch.Length; position = firstMatch.Index + firstMatch.Length;
PopColor(); PopColor();
PushColor(newSpan.SpanColor); if (!newSpan.SpanColorIncludesStart)
PushColor(newSpan.SpanColor);
} }
endSpanMatch = null; endSpanMatch = null;
} }

12
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingSpan.cs

@ -43,6 +43,18 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// </summary> /// </summary>
public HighlightingColor EndColor { get; set; } public HighlightingColor EndColor { get; set; }
/// <summary>
/// Gets/Sets whether the span color includes the start.
/// The default is <c>false</c>.
/// </summary>
public bool SpanColorIncludesStart { get; set; }
/// <summary>
/// Gets/Sets whether the span color includes the end.
/// The default is <c>false</c>.
/// </summary>
public bool SpanColorIncludesEnd { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
public override string ToString() public override string ToString()
{ {

19
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XmlHighlightingDefinition.cs

@ -317,22 +317,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
StartExpression = CreateRegex(span, span.BeginRegex, span.BeginRegexType), StartExpression = CreateRegex(span, span.BeginRegex, span.BeginRegexType),
EndExpression = CreateRegex(span, endRegex, span.EndRegexType), EndExpression = CreateRegex(span, endRegex, span.EndRegexType),
RuleSet = GetRuleSet(span, span.RuleSetReference), RuleSet = GetRuleSet(span, span.RuleSetReference),
StartColor = MergeColor(wholeSpanColor, GetColor(span, span.BeginColorReference)), StartColor = GetColor(span, span.BeginColorReference),
SpanColor = wholeSpanColor, SpanColor = wholeSpanColor,
EndColor = MergeColor(wholeSpanColor, GetColor(span, span.EndColorReference)), EndColor = GetColor(span, span.EndColorReference),
}; SpanColorIncludesStart = true,
} SpanColorIncludesEnd = true
static HighlightingColor MergeColor(HighlightingColor baseColor, HighlightingColor newColor)
{
if (baseColor == null)
return newColor;
if (newColor == null)
return baseColor;
return new HighlightingColor {
Foreground = newColor.Foreground ?? baseColor.Foreground,
FontWeight = newColor.FontWeight ?? baseColor.FontWeight,
FontStyle = newColor.FontStyle ?? baseColor.FontStyle,
}; };
} }

Loading…
Cancel
Save