Skip to content

Commit

Permalink
- Fix C/C++ styles can get reverted to default
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Jan 16, 2024
1 parent 75b33fc commit 58f118d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Codist/Helpers/TextEditorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,38 +288,41 @@ public static void Remove(this IEditorFormatMap map, string formatName, string k
map.GetProperties(formatName).Remove(key);
}
public static TextFormattingRunProperties AsFormatProperties(this ResourceDictionary resource) {
var r = TextFormattingRunProperties.CreateTextFormattingRunProperties();
return MergeFormatProperties(resource, TextFormattingRunProperties.CreateTextFormattingRunProperties());
}

public static TextFormattingRunProperties MergeFormatProperties(this ResourceDictionary resource, TextFormattingRunProperties properties) {
foreach (System.Collections.DictionaryEntry item in resource) {
switch (item.Key.ToString()) {
case EditorFormatDefinition.ForegroundBrushId:
r = r.SetForegroundBrush(item.Value as WpfBrush); break;
properties = properties.SetForegroundBrush(item.Value as WpfBrush); break;
case EditorFormatDefinition.ForegroundColorId:
r = r.SetForeground((WpfColor)item.Value); break;
properties = properties.SetForeground((WpfColor)item.Value); break;
case ClassificationFormatDefinition.ForegroundOpacityId:
r = r.SetForegroundOpacity((double)item.Value); break;
properties = properties.SetForegroundOpacity((double)item.Value); break;
case EditorFormatDefinition.BackgroundBrushId:
r = r.SetBackgroundBrush(item.Value as WpfBrush); break;
properties = properties.SetBackgroundBrush(item.Value as WpfBrush); break;
case EditorFormatDefinition.BackgroundColorId:
r = r.SetBackground((WpfColor)item.Value); break;
properties = properties.SetBackground((WpfColor)item.Value); break;
case ClassificationFormatDefinition.BackgroundOpacityId:
r = r.SetBackgroundOpacity((double)item.Value); break;
properties = properties.SetBackgroundOpacity((double)item.Value); break;
case ClassificationFormatDefinition.IsBoldId:
r = r.SetBold((bool)item.Value); break;
properties = properties.SetBold((bool)item.Value); break;
case ClassificationFormatDefinition.IsItalicId:
r = r.SetItalic((bool)item.Value); break;
properties = properties.SetItalic((bool)item.Value); break;
case ClassificationFormatDefinition.TextDecorationsId:
r = r.SetTextDecorations(item.Value as TextDecorationCollection); break;
properties = properties.SetTextDecorations(item.Value as TextDecorationCollection); break;
case ClassificationFormatDefinition.TypefaceId:
r = r.SetTypeface(item.Value as Typeface); break;
properties = properties.SetTypeface(item.Value as Typeface); break;
case ClassificationFormatDefinition.FontHintingSizeId:
r = r.SetFontHintingEmSize((double)item.Value); break;
properties = properties.SetFontHintingEmSize((double)item.Value); break;
case ClassificationFormatDefinition.FontRenderingSizeId:
r = r.SetFontRenderingEmSize((double)item.Value); break;
properties = properties.SetFontRenderingEmSize((double)item.Value); break;
case ClassificationFormatDefinition.TextEffectsId:
r = r.SetTextEffects(item.Value as TextEffectCollection); break;
properties = properties.SetTextEffects(item.Value as TextEffectCollection); break;
}
}
return r;
return properties;
}
#endregion
#endregion
Expand Down
4 changes: 4 additions & 0 deletions Codist/SyntaxHighlight/FormatStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ public void Refresh() {
foreach (var item in formats) {
if (item.IsFormattableClassificationType()) {
var p = _ClassificationFormatMap.GetTextProperties(item);
// C/C++ styles can somehow get reverted, here we forcefully reinforce our highlights
if (Highlight(item, out var newStyle) != FormatChanges.None) {
p = newStyle.Value.MergeFormatProperties(p);
}
$"[{_Category}] refresh classification {item.Classification} ({p.Print()})".Log();
_ClassificationFormatMap.SetTextProperties(item, p);
_PropertiesCache[item] = p;
Expand Down

0 comments on commit 58f118d

Please sign in to comment.