From 23ef8ab3ca90174ff1b2dcddc3ac55ec4d9bf52e Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 24 Sep 2021 11:36:23 +0200 Subject: [PATCH] IDE: EditorOptions, Color, fix "reset all". Issue #39388 (cherry picked from commit ff2da4d6be28d9939231ea6c41a97679e4e98598) --- ide/editoroptions.pp | 24 +++++++++++++++++++----- ide/frames/editor_color_options.pas | 4 +++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ide/editoroptions.pp b/ide/editoroptions.pp index d9882701d7..299c476955 100644 --- a/ide/editoroptions.pp +++ b/ide/editoroptions.pp @@ -6431,22 +6431,36 @@ end; procedure TColorSchemeLanguage.Assign(Src: TColorSchemeLanguage); var - i: Integer; + i, j: Integer; Attr, SrcAttr: TColorSchemeAttribute; + NewList: TQuickStringlist; begin - Clear; - FAttributes.Sorted := false; + // Do not clear old list => external references to Attributes may exist FLanguage := Src.FLanguage; FLanguageName := Src.FLanguageName; + //FDefaultAttribute.Assign(Src.FDefaultAttribute); FDefaultAttribute := nil; + NewList := TQuickStringlist.Create; for i := 0 to Src.AttributeCount - 1 do begin SrcAttr := Src.AttributeAtPos[i]; - Attr := TColorSchemeAttribute.Create(Self, SrcAttr.Caption, SrcAttr.StoredName); + // Reuse existing Attribute if possible. + j := FAttributes.IndexOf(UpperCase(SrcAttr.StoredName)); + if j >= 0 then begin + Attr := TColorSchemeAttribute(FAttributes.Objects[j]); + DebugLn([' Use existing attr ', Attr.StoredName]); + FAttributes.Delete(j); + end + else begin + Attr := TColorSchemeAttribute.Create(Self, SrcAttr.Caption, SrcAttr.StoredName); + end; Attr.Assign(SrcAttr); - FAttributes.AddObject(Attr.StoredName, Attr); + NewList.AddObject(UpperCase(Attr.StoredName), Attr); if SrcAttr = Src.DefaultAttribute then FDefaultAttribute := Attr; end; + Clear; + FreeAndNil(FAttributes); + FAttributes := NewList; FAttributes.Sorted := true; end; diff --git a/ide/frames/editor_color_options.pas b/ide/frames/editor_color_options.pas index f141c30f2e..2f6871ff92 100644 --- a/ide/frames/editor_color_options.pas +++ b/ide/frames/editor_color_options.pas @@ -1213,7 +1213,9 @@ begin DefaultSchemeGrp := ColorSchemeFactory.ColorSchemeGroup[ColorSchemeButton.Caption]; if DefaultSchemeGrp = nil then exit; - if FIsEditingDefaults or FCurHighlightElement.IsUsingSchemeGlobals then + if FIsEditingDefaults or + (OnlySelected and FCurHighlightElement.IsUsingSchemeGlobals) + then DefaultColorScheme := DefaultSchemeGrp.DefaultColors else DefaultColorScheme := DefaultSchemeGrp.ColorScheme[FCurrentColorScheme.Language];