How to disable trimming tailing spaces on NSTextField?

I have a multitine Text Field with Fixed-Width font and align text Middle.

I am working on a retro computer emulator and as such I have a multiline text with fixed amount of characters in each lines.

What I expect is that each lines are nicely aligned one above each others, and because this is a fixed width character each lines has exactly the same length. That works nicely when aligned to the left. Or there is no tailing space (aka I put a fake non-space right before the line end).


However, it seems to me that Text Field auto-trims off tailing spaces whenever there is an EOL ('\n') character.


How do I prevent this to happen? I could not find any settings in Interface Builder, nor in the NSTextFieldCell properties. Any directions would be much appreciated.

Replies

I tested on an OSX App.I created a textField with its IBOutlet.

Set line break to clip. Align text middle.


Added the text to the textField:

        var someText = "Try with blanks       " + "\n"
        someText = someText + "and a second line       " + "\n"
        someText = someText + "Stop here."
        multilinesTextField.stringValue = someText


And it works OK, text is not trimmed.

But effectively, alignment ignores the trailing blanks.

I tried to add an option-space, but it is ignored as well.

You could try to find an invisible char to add at the end ?

Or have a look here, to draw the invisible (setting the

showsInvisibleCharacters
property of
NSLayoutManager
to
true)

https://stackoverflow.com/questions/36666502/uitextview-draw-invisible-whitespace-characters

or

https://stackoverflow.com/questions/300086/display-hidden-characters-in-nstextview


If this was an IOS App, no multiline on textField, need to use TextView.


Thanks to report if that works.

Thank you! That sounds reasonable. I will check it out soon and will report back.