Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 8ace234

Browse files
committed
Fix bugs in #505
1 parent 293edbf commit 8ace234

5 files changed

Lines changed: 29 additions & 12 deletions

File tree

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public bool Italic {
7070

7171
public bool Underline {
7272
get {
73-
return color.Underline;
73+
return color.Underline == true;
7474
}
7575
set {
7676
throw new NotSupportedException();

src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public FontStyle? FontStyle {
8686
}
8787

8888
/// <summary>
89-
/// Gets/sets the underline flag. Null if the underline status does not change the font style.
90-
/// </summary>
89+
/// Gets/sets the underline flag. Null if the underline status does not change the font style.
90+
/// </summary>
9191
public bool? Underline {
9292
get {
9393
return underline;
@@ -97,7 +97,7 @@ public bool? Underline {
9797
throw new InvalidOperationException();
9898
underline = value;
9999
}
100-
}
100+
}
101101

102102
/// <summary>
103103
/// Gets/sets the foreground color applied by the highlighting.
@@ -146,6 +146,8 @@ protected HighlightingColor(SerializationInfo info, StreamingContext context)
146146
this.FontWeight = System.Windows.FontWeight.FromOpenTypeWeight(info.GetInt32("Weight"));
147147
if (info.GetBoolean("HasStyle"))
148148
this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style"));
149+
if (info.GetBoolean("HasUnderline"))
150+
this.Underline = info.GetBoolean("Underline");
149151
this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(HighlightingBrush));
150152
this.Background = (HighlightingBrush)info.GetValue("Background", typeof(HighlightingBrush));
151153
}
@@ -169,6 +171,9 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte
169171
info.AddValue("HasStyle", this.FontStyle.HasValue);
170172
if (this.FontStyle.HasValue)
171173
info.AddValue("Style", this.FontStyle.Value.ToString());
174+
info.AddValue("HasUnderline", this.Underline.HasValue);
175+
if (this.Underline.HasValue)
176+
info.AddValue("Underline", this.Underline.Value);
172177
info.AddValue("Foreground", this.Foreground);
173178
info.AddValue("Background", this.Background);
174179
}
@@ -196,6 +201,12 @@ public virtual string ToCss()
196201
b.Append(FontStyle.Value.ToString().ToLowerInvariant());
197202
b.Append("; ");
198203
}
204+
if (Underline != null)
205+
{
206+
b.Append("text-decoration: ");
207+
b.Append(Underline.Value ? "underline" : "none");
208+
b.Append("; ");
209+
}
199210
return b.ToString();
200211
}
201212

@@ -247,7 +258,9 @@ public virtual bool Equals(HighlightingColor other)
247258
{
248259
if (other == null)
249260
return false;
250-
return this.name == other.name && this.fontWeight == other.fontWeight && this.fontStyle == other.fontStyle && object.Equals(this.foreground, other.foreground) && object.Equals(this.background, other.background);
261+
return this.name == other.name && this.fontWeight == other.fontWeight
262+
&& this.fontStyle == other.fontStyle && this.underline == other.underline
263+
&& object.Equals(this.foreground, other.foreground) && object.Equals(this.background, other.background);
251264
}
252265

253266
/// <inheritdoc/>
@@ -282,11 +295,14 @@ public void MergeWith(HighlightingColor color)
282295
this.foreground = color.foreground;
283296
if (color.background != null)
284297
this.background = color.background;
298+
if (color.underline != null)
299+
this.underline = color.underline;
285300
}
286301

287302
internal bool IsEmptyForMerge {
288303
get {
289-
return fontWeight == null && fontStyle == null && foreground == null && background == null;
304+
return fontWeight == null && fontStyle == null && underline == null
305+
&& foreground == null && background == null;
290306
}
291307
}
292308
}

src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<xsd:simpleType name="FontStyle">
2525
<xsd:restriction base="xsd:string">
2626
<xsd:enumeration value="italic"/>
27-
<xsd:enumeration value="underlined"/>
2827
<xsd:enumeration value="normal"/>
2928
<xsd:enumeration value="oblique"/>
3029
</xsd:restriction>

src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static XshdColor ParseColorAttributes(XmlReader reader)
297297
color.Background = ParseColor(position, reader.GetAttribute("background"));
298298
color.FontWeight = ParseFontWeight(reader.GetAttribute("fontWeight"));
299299
color.FontStyle = ParseFontStyle(reader.GetAttribute("fontStyle"));
300-
color.Underline = reader.GetAttribute("underline") == "true";
300+
color.Underline = reader.GetBoolAttribute("underline");
301301
return color;
302302
}
303303

src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class XshdColor : XshdElement, ISerializable
5252
/// <summary>
5353
/// Gets/sets the underline flag
5454
/// </summary>
55-
public bool Underline { get; set; }
55+
public bool? Underline { get; set; }
5656

5757
/// <summary>
5858
/// Gets/sets the font style.
@@ -86,7 +86,8 @@ protected XshdColor(SerializationInfo info, StreamingContext context)
8686
if (info.GetBoolean("HasStyle"))
8787
this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style"));
8888
this.ExampleText = info.GetString("ExampleText");
89-
this.Underline = info.GetBoolean("Underline");
89+
if (info.GetBoolean("HasUnderline"))
90+
this.Underline = info.GetBoolean("Underline");
9091
}
9192

9293
/// <summary>
@@ -104,9 +105,10 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte
104105
info.AddValue("Name", this.Name);
105106
info.AddValue("Foreground", this.Foreground);
106107
info.AddValue("Background", this.Background);
108+
info.AddValue("HasUnderline", this.Underline.HasValue);
109+
if (this.Underline.HasValue)
110+
info.AddValue("Underline", this.Underline.Value);
107111
info.AddValue("HasWeight", this.FontWeight.HasValue);
108-
if (this.Underline)
109-
info.AddValue("Underline", this.Underline);
110112
if (this.FontWeight.HasValue)
111113
info.AddValue("Weight", this.FontWeight.Value.ToOpenTypeWeight());
112114
info.AddValue("HasStyle", this.FontStyle.HasValue);

0 commit comments

Comments
 (0)