@@ -23,9 +23,18 @@ public final class SuggestionStyledTextViewer {
2323 private final String originalContent ;
2424 private final StyledText styledText ;
2525 private final String newContent ;
26+ private final Color addedColor ;
27+ private final Color removedColor ;
2628
2729 public SuggestionStyledTextViewer (Composite parent , ITextViewer parentTextViewer , String newContent ) {
2830 this .parentStyledText = parentTextViewer .getTextWidget ();
31+ if (isDarkColor (parentTextViewer .getTextWidget ().getForeground ())) {
32+ this .addedColor = new Color (200 , 255 , 200 );
33+ this .removedColor = new Color (255 , 200 , 200 );
34+ } else {
35+ this .addedColor = new Color (50 , 100 , 50 );
36+ this .removedColor = new Color (100 , 50 , 50 );
37+ }
2938 this .originalContent = EclipseUtils .getSelectionText (parentTextViewer );
3039 this .styledText = new StyledText (parent , SWT .BORDER );
3140 this .styledText .setEditable (false );
@@ -57,13 +66,13 @@ public void setupLineDiff() {
5766 final StyleRange styleRange = new StyleRange ();
5867 styleRange .start = this .styledText .getCharCount () - line .length ();
5968 styleRange .length = line .length ();
60- styleRange .background = new Color ( 200 , 255 , 200 ) ;
69+ styleRange .background = this . addedColor ;
6170 this .styledText .setStyleRange (styleRange );
6271 } else if (diffLine .startsWith ("-" )) {
6372 final StyleRange styleRange = new StyleRange ();
6473 styleRange .start = this .styledText .getCharCount () - line .length ();
6574 styleRange .length = line .length ();
66- styleRange .background = new Color ( 255 , 200 , 200 ) ;
75+ styleRange .background = this . removedColor ;
6776 this .styledText .setStyleRange (styleRange );
6877 originalOffset += line .length () + 1 ;
6978 } else {
@@ -106,7 +115,7 @@ public void setupCharDiff() {
106115 continue ;
107116 }
108117 final StyleRange suggestionStyleRange = createCopy (originalStyleRange );
109- suggestionStyleRange .background = new Color ( 255 , 200 , 200 ) ;
118+ suggestionStyleRange .background = this . removedColor ;
110119 suggestionStyleRange .start = suggestionOffset + i ;
111120 suggestionStyleRange .length = Math .min (suggestionOffset + diff .text .length () - suggestionStyleRange .start , originalStyleRange .length );
112121 this .styledText .setStyleRange (suggestionStyleRange );
@@ -116,7 +125,7 @@ public void setupCharDiff() {
116125 suggestionOffset += diff .text .length ();
117126 } else if (diff .operation == Operation .INSERT ) {
118127 final StyleRange suggestionStyleRange = new StyleRange ();
119- suggestionStyleRange .background = new Color ( 200 , 255 , 200 ) ;
128+ suggestionStyleRange .background = this . addedColor ;
120129 suggestionStyleRange .start = suggestionOffset ;
121130 suggestionStyleRange .length = diff .text .length ();
122131 this .styledText .setStyleRange (suggestionStyleRange );
@@ -224,4 +233,8 @@ private static String diff(List<String> oldList, List<String> newList) {
224233
225234 return stringBuilder .toString ();
226235 }
236+
237+ private static boolean isDarkColor (final Color color ) {
238+ return color .getRed () + color .getGreen () + color .getBlue () < 382 ;
239+ }
227240}
0 commit comments