InputField copy/paste loses newlines!

Augh — this is causing me some serious grief this week.

It appears that when you paste multi-line text into a multi-line InputField, line breaks are stripped. This can be easily demonstrated as follows:

  • Go to Unity WebGL Player | Miniscript
  • Click on the Program button at the top, then the Example 1 button at the bottom.
  • Select all the code in the big input field. Copy with cmd-C. (I hear a system beep at this point, but it really does put the text on the clipboard, with line breaks, as can be verified by pasting into a text editor or whatever.)
  • Paste with cmd-V. Again the beep, but more importantly, all the line breaks (as well as the whitespace at the start of each line) are stripped out.

This is in the web plugin, but I see exactly the same behavior in the editor on MacOS (which is everywhere I’ve tested so far). I don’t believe I have any code involved in this process; it’s all stock behavior. The input field Content Type is set to Standard, with Line Type set to “Multi Line Newline”.

Is there something else I might have done wrong? Or is this just a nasty bug? And if so, any ideas how to work around it?

I have found a partial work-around; in code, you can do

myField.text = GUIUtility.systemCopyBuffer;

and this appears to work correctly, both in the editor (Mac) and in the web plugin (Mac/Firefox host).

But that doesn’t help somebody who hits cmd-V, because as far as I know, there is no way to intercept that. I’ll have to provide a Paste button in the UI, and train users to use that instead of the standard one. And of course this does a full replace of the text, rather than inserting or replacing the selected text (though that may be possible too with more work).

This is a really long-standing issue. It’s supposedly fixed in 5.3.0: Unity Issue Tracker - When copying text in a multiline Input Field and then pasting it, new lines are ignored

Hey, thanks Tony! I did do a search before reporting it, but Unity has the world’s best game engine and the world’s worst search engine, so I found no results at all.

This is encouraging… and after spending the last 45 minutes trying to hack around it myself, this is a very good incentive to try 5.3!

Please let us know if 5.3 fixes it. I haven’t actually tested it.

Confirmed, it works fine in 5.3. And I’ve now ripped out all the crazy stuff I was doing to try to work around the bug. Whew!

Still broken in 5.3.5f1