From ad65327732fcb4d4a9063a9dfc9fe8052b2a43cc Mon Sep 17 00:00:00 2001
From: Riccardo Mottola <rm@gnu.org>
Date: Sat, 6 Feb 2021 12:31:10 +0100
Subject: [PATCH] Respect background selection preferences and infer text as
 inverse.

---
 ChangeLog                                |  6 ++++++
 Modules/Editors/ProjectCenter/PCEditor.m | 26 ++++++++++++++++++++----
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7a7c734..1bc324a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-02-06 Riccardo Mottola <rm@gnu.org>
+
+	* Modules/Editors/ProjectCenter/PCEditor.m
+	Respect background selection preferences and infer text
+	as inverse.
+
 2021-02-04 Riccardo Mottola <rm@gnu.org>
 
 	* Framework/PCProjectManager.m
diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m
index 973af3a..3f1ef4d 100644
--- a/Modules/Editors/ProjectCenter/PCEditor.m
+++ b/Modules/Editors/ProjectCenter/PCEditor.m
@@ -1,7 +1,7 @@
 /*
    GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html
 
-   Copyright (C) 2002-2015 Free Software Foundation
+   Copyright (C) 2002-2021 Free Software Foundation
 
    Authors: Philippe C.D. Robert
             Serg Stoyan
@@ -112,9 +112,13 @@
 
 - (PCEditorView *)_createEditorViewWithFrame:(NSRect)fr
 {
-  PCEditorView    *ev = nil;
-  NSTextContainer *tc = nil;
-  NSLayoutManager *lm = nil;
+  PCEditorView       *ev = nil;
+  NSTextContainer    *tc = nil;
+  NSLayoutManager    *lm = nil;
+  NSColor            *bSelCol = nil;
+  NSColor            *tSelCol = nil;
+  id <PCPreferences>  prefs;
+  NSDictionary       *selAttributes;
 
   /*
    * setting up the objects needed to manage the view but using the
@@ -152,6 +156,19 @@
 
   [ev setEditable:_isEditable];
 
+  prefs = [[_editorManager projectManager] prefController];
+  bSelCol = [prefs colorForKey:EditorSelectionColor];
+  tSelCol = [NSColor colorWithCalibratedRed: 1.0 - [bSelCol redComponent]
+				      green: 1.0 - [bSelCol greenComponent]
+				       blue: 1.0 - [bSelCol blueComponent]
+				      alpha: [bSelCol alphaComponent]];
+  selAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
+				  bSelCol, NSBackgroundColorAttributeName,
+				tSelCol, NSForegroundColorAttributeName,
+				nil];
+  [ev setSelectedTextAttributes:selAttributes];
+  [ev setSelectedTextAttributes:selAttributes];
+
   // Activate undo
   [ev setAllowsUndo: YES];
 
@@ -296,6 +313,7 @@
 
   text  = [NSString stringWithContentsOfFile:_path];
   attributedString = [attributedString initWithString:text attributes:attributes];
+  [attributes release];
 
   _storage = [[NSTextStorage alloc] init];
   [_storage setAttributedString:attributedString];