Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit c0010e0

Browse files
committed
Build fix
1 parent f9cd2ef commit c0010e0

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

UI/Components/EditorElementHighlighter.cs

+39-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.Linq;
@@ -14,18 +14,14 @@ namespace Spedit.UI.Components
1414
{
1515
public class AeonEditorHighlighting : IHighlightingDefinition
1616
{
17-
public AeonEditorHighlighting(IEnumerable<HighlightingColor> namedHighlightingColors)
18-
{
19-
NamedHighlightingColors = namedHighlightingColors;
20-
}
21-
2217
public string Name => "SM";
2318

2419
public HighlightingRuleSet MainRuleSet
2520
{
2621
get
2722
{
28-
var commentMarkerSet = new HighlightingRuleSet {Name = "CommentMarkerSet"};
23+
var commentMarkerSet = new HighlightingRuleSet();
24+
commentMarkerSet.Name = "CommentMarkerSet";
2925
commentMarkerSet.Rules.Add(new HighlightingRule
3026
{
3127
Regex = RegexKeywordsHelper.GetRegexFromKeywords(new[]
@@ -209,17 +205,17 @@ public HighlightingRuleSet MainRuleSet
209205
if (def.StructFieldStrings.Length > 0)
210206
rs.Rules.Add(new HighlightingRule //Methods
211207
{
212-
Regex = RegexKeywordsHelper.GetRegexFromKeywords2(
213-
def.StructFieldStrings.Select(e => e).ToArray()),
208+
Regex = RegexKeywordsHelper.GetRegexFromKeywords(
209+
def.StructFieldStrings.Select(e => e).ToArray(), true),
214210
Color = new HighlightingColor
215211
{Foreground = new SimpleHighlightingBrush(Program.OptionsObject.SH_Methods)}
216212
});
217213

218214
if (def.StructMethodStrings.Length > 0)
219215
rs.Rules.Add(new HighlightingRule //Methods
220216
{
221-
Regex = RegexKeywordsHelper.GetRegexFromKeywords2(
222-
def.StructMethodStrings.Select(e => e).ToArray()),
217+
Regex = RegexKeywordsHelper.GetRegexFromKeywords(
218+
def.StructMethodStrings.Select(e => e).ToArray(), true),
223219
Color = new HighlightingColor
224220
{Foreground = new SimpleHighlightingBrush(Program.OptionsObject.SH_Methods)}
225221
});
@@ -247,13 +243,14 @@ public HighlightingColor GetNamedColor(string name)
247243
return null;
248244
}
249245

250-
public IEnumerable<HighlightingColor> NamedHighlightingColors { get; }
246+
public IEnumerable<HighlightingColor> NamedHighlightingColors { get; set; }
251247

252248
public IDictionary<string, string> Properties
253249
{
254250
get
255251
{
256-
var propertiesDictionary = new Dictionary<string, string> {{"DocCommentMarker", "///"}};
252+
var propertiesDictionary = new Dictionary<string, string>();
253+
propertiesDictionary.Add("DocCommentMarker", "///");
257254
return propertiesDictionary;
258255
}
259256
}
@@ -276,7 +273,6 @@ public SimpleHighlightingBrush(Color color) : this(new SolidColorBrush(color))
276273

277274
private SimpleHighlightingBrush(SerializationInfo info, StreamingContext context)
278275
{
279-
// ReSharper disable once PossibleNullReferenceException
280276
brush = new SolidColorBrush((Color) ColorConverter.ConvertFromString(info.GetString("color")));
281277
brush.Freeze();
282278
}
@@ -298,7 +294,8 @@ public override string ToString()
298294

299295
public override bool Equals(object obj)
300296
{
301-
if (!(obj is SimpleHighlightingBrush other))
297+
var other = obj as SimpleHighlightingBrush;
298+
if (other == null)
302299
return false;
303300
return brush.Color.Equals(other.brush.Color);
304301
}
@@ -317,10 +314,20 @@ public static Regex GetRegexFromKeywords(string[] keywords, bool ForceAtomicRege
317314

318315
if (keywords.Length == 0) return new Regex("SPEdit_Error"); //hehe
319316

320-
var UseAtomicRegex = keywords.All(t => char.IsLetterOrDigit(t[0]) && char.IsLetterOrDigit(t[t.Length - 1]));
317+
var UseAtomicRegex = true;
318+
for (var j = 0; j < keywords.Length; ++j)
319+
if (!char.IsLetterOrDigit(keywords[j][0]) ||
320+
!char.IsLetterOrDigit(keywords[j][keywords[j].Length - 1]))
321+
{
322+
UseAtomicRegex = false;
323+
break;
324+
}
321325

322326
var regexBuilder = new StringBuilder();
323-
regexBuilder.Append(UseAtomicRegex ? @"\b(?>" : @"(");
327+
if (UseAtomicRegex)
328+
regexBuilder.Append(@"\b(?>");
329+
else
330+
regexBuilder.Append(@"(");
324331

325332
var orderedKeyWords = new List<string>(keywords);
326333
var i = 0;
@@ -341,22 +348,29 @@ public static Regex GetRegexFromKeywords(string[] keywords, bool ForceAtomicRege
341348
}
342349
}
343350

344-
regexBuilder.Append(UseAtomicRegex ? @")\b" : @")");
351+
if (UseAtomicRegex)
352+
regexBuilder.Append(@")\b");
353+
else
354+
regexBuilder.Append(@")");
345355

346356
return new Regex(regexBuilder.ToString(), RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture);
347357
}
348358

349-
private static string[] ConvertToAtomicRegexAbleStringArray(IReadOnlyList<string> keywords)
359+
public static string[] ConvertToAtomicRegexAbleStringArray(string[] keywords)
350360
{
351-
return keywords.Where(t => t.Length > 0)
352-
.Where(t => char.IsLetterOrDigit(t[0]) && char.IsLetterOrDigit(t[t.Length - 1]))
353-
.ToArray();
361+
var atomicRegexAbleList = new List<string>();
362+
for (var j = 0; j < keywords.Length; ++j)
363+
if (keywords[j].Length > 0)
364+
if (char.IsLetterOrDigit(keywords[j][0]) &&
365+
char.IsLetterOrDigit(keywords[j][keywords[j].Length - 1]))
366+
atomicRegexAbleList.Add(keywords[j]);
367+
368+
return atomicRegexAbleList.ToArray();
354369
}
355370

356-
/// Use this for class like matches (methodmaps and enumstructs atm)
357-
public static Regex GetRegexFromKeywords2(IEnumerable<string> keywords)
371+
public static Regex GetRegexFromKeywords2(string[] keywords)
358372
{
359-
var regexBuilder = new StringBuilder(@"(?<=\b[^\s]+\.)(");
373+
var regexBuilder = new StringBuilder(@"\b[^\s]+\.(");
360374
var i = 0;
361375
foreach (var keyword in keywords)
362376
{

0 commit comments

Comments
 (0)