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];