Refactor the workaround for QPlainTextEdit's mangling of nbsp into a separate class