Mysterious deselection and colour loss

I have a textArea and a rectangle that I use along with a custom colour picker window to choose a colour for the selected text in the text area. When I click anywhere inside the textArea, however, the selected text loses its colour and the cursor vanishes. Any idea of what could be going on? I have a similar problem when I use the standard Apple colour picker. When I click anywhere inside the colour picker window the text in a textArea in a different window gets de-selected and the cursor advances to the end of the text in the textArea. This latter problem seems almost magical, as I can’t figure out what’s causing the colour picker window to affect a totally different window!

I have resolved my issue now. It took me a long time to discover a curious bug in my code. Sorry to spam the Forum with my stupidity!