All I wanted was a Rich Text editor which offers a proper Dark Mode. It proved an impossible request.
In Mojave, TextEdit follows Apple’s standard protocol of fixing its text display in Light Mode. When you switch to Dark Mode, the window and its controls go dark, but the view in which the document’s text is displayed remains obstinately black on white. That may be fine when you’re working on plain Rich Text, if that’s not a contradiction. But several of my tools here, like Consolation 3 and Nalaprop, now generate multicoloured Rich Text, which looks drop-dead gorgeous in Dark Mode.
The view background in TextEdit also glares too brightly if the rest of the display is all dark. It stands out like a sore thumb, dazzles, and detracts from the overall effect.
Besides, there aren’t any other really good plain Rich Text editors around. The moment that you step up from text to RTF, vendors assume that you want a word (or document) processor, not something lean and functional. Markdown editors are two a-penny; Rich Text not at any price.
So, off to Xcode, where writing a Cocoa Rich Text editor involves no more than a couple of dozen lines of code. The trickiest work is in its Interface Builder, getting its settings right. An hour or so later, I was happy with the result, except that it too was stuck in Light Mode, just like TextEdit.
I then turned to Apple’s documentation of how to set an app and individual windows in a specific appearance mode, in Mojave. Another hour later, I had working menu commands which switch the whole app, and separately its frontmost window, to one of three options:
- follow the prevailing mode, as set in the General pane,
- fixed Dark Mode,
- fixed Light Mode.
Here, the whole app, now named DelightEd, is set to follow the prevailing mode, which is Dark, and two of the four windows are fixed in Light Mode.
Success: after just a couple of hours of coding and tweaking, my new Rich Text editor was ready to go, and worked a treat with RTF saved from Consolation 3 and Nalaprop. So I wrote its ReadMe file in Sierra, moved that back to Mojave, and tried setting up that screenshot. Now it didn’t work at all: the Light Mode windows looked fine, but Dark Mode was the dreaded black on black.
The problem is with Rich Text Format itself, which in Mojave is being coded to work in the two modes, but isn’t in Sierra. For Mojave’s Dark Mode, Apple seems to have changed the way that macOS codes up Attributed Text into RTF.
In RTF, colours needed in a document are normally defined in a prefatory colour table, which might look like this:
That defines a colour table with three colours:
entry 0 is a default null colour which is imagined as a zero-length string between
\colortbl and the semi-colon
entry 1 is red = 255, green = 255, blue = 255, i.e. white
entry 2 is red = 0, green = 0, blue = 0, i.e. black.
Then in the content of the file, the code
\cfN selects colour table entry number N as the foreground colour, and
\cbN selects N as the background colour.
But there’s also an expanded colour table, which is generated by Mojave, and looks like
That apparently defines three colours, of which one (entry 2) is named
textColor. That will in Light Mode be displayed as black, but in Dark Mode as white.
Then the RTF code sets the main body of text in
textColor using the markup
\cf2. Where necessary,
\cb1 sets the background to the standard, i.e. white in Light Mode, but black in Dark Mode.
Sure enough, when I create RTF documents in DelightEd running in Mojave, by default they use expanded colour tables which switch the contents properly according to the view’s appearance. But create them in Sierra, and they use fixed foreground colours, and misbehave when opened in Mojave.
Having got to the bottom of this baffling problem, I feel more confident in offering DelightEd for your entertainment and practical use. But please, don’t tell Apple, as I’m sure that it will horrify all those engineers and designers who have worked so hard to make Dark Mode what it is.
DelightEd 1.0b2 runs on Sierra, High Sierra, and most of all Mojave, and is notarized for your added protection. It’s available from here: DelightEd10b2
and from Downloads above.
I’m sure that it will drive you crazy, but it does just what I want it to at last.