Search Issue Tracker

Fixed in 5.3.0

Votes

14

Found in

4.6.0f2

Issue ID

648688

Regression

No

When copying text in a multiline Input Field and then pasting it, new lines are ignored

UI

-

To reproduce this issue:

1. Open the attached project
2. Open 'test' scene
3. It has input field with line type: 'Multi Line Newline'
4. Play the scene
5. Enter some text into multiple lines
6. Highlight text
7. Copy it(Control/CMD + C)
8. Paste it again
9. New lines are ignored and text is pasted into one line

Captured repro: http://screencast.com/t/QllgkKyxcCao

Comments (9)

  1. JayDeveloper

    Aug 26, 2015 03:22

    A dirty solution to make newline pastable again:

    // Use InputFieldM instead of InputField
    public class InputFieldM : InputField
    {
    protected override void Append (string input)
    {
    if (HoldKeyManager.HoldCommandOnly && Input.GetKeyDown (KeyCode.V)) {
    TextEditor te = new TextEditor ();
    te.multiline = multiLine;
    te.Paste ();
    input = te.content.text;
    }

    if (TouchScreenKeyboard.isSupported)
    return;

    for (int i = 0, imax = input.Length; i < imax; ++i) {
    char c = input [i];

    Append (c);
    }
    }
    }

  2. JayDeveloper

    Aug 26, 2015 02:55

    If Unity team couldn't/wouldn't have time to get the InputField right, just make every function and member of the InputField object overridable(declaring functions virtual and members protected or public instead of private) so people who needs customized behaviour can write their own functionality by inheriting InputField.
    Also, please liberate the use of GUIUtility.copySystemBuffer to developers. A better cross-platform copy and paste solution would be much better.
    General advice: UI components are usually very customized. Instead of taking a closed approach of assuming many feature or behavior for developers, try opening up more API and settings of components. E.g. copy/paste keypress can be an event that allow developer to customize response; replace '\n' with space? why space?

    Details on why newlines are replaced with space lies in code below:

    // ----- InputField.cs ------
    static string clipboard
    {
    get
    {
    TextEditor te = new TextEditor();
    te.Paste();
    return te.content.text;
    }
    set
    {
    TextEditor te = new TextEditor();
    te.content = new GUIContent(value);
    te.OnFocus();
    te.Copy();
    }
    }

    // ----- public class TextEditor ------
    public bool Paste ()
    {
    string text = GUIUtility.systemCopyBuffer;
    if (text != string.Empty)
    {
    if (!this.multiline)
    {
    text = TextEditor.ReplaceNewlinesWithSpaces (text);
    }
    this.ReplaceSelection (text);
    return true;
    }
    return false;
    }
    // ----- End of code reference -----

    *I suspect InputField.cs is written by an intern.

  3. riwalk

    Aug 22, 2015 21:32

    This is really quite easy to reproduce and is extremely annoying. What good is a text field if it doesn't work?

  4. JayDeveloper

    Aug 22, 2015 03:43

    Sorry, it's my own problem that '/' is ignored. '/' should be fine.

  5. JayDeveloper

    Aug 22, 2015 03:28

    '/' is also ignored

  6. GroenBoer

    Aug 05, 2015 23:43

    Copy & pasting text from outside of Unity (such as notepad or a website) into an inputfield at runtime then any newline characters are removed by unity!

  7. Anjin_nz

    Jul 13, 2015 23:52

    Something similar seems to be happening in Unity 5.1.0f3

  8. Anjin_nz

    Jul 13, 2015 23:49

    Something similar seems to be happening in Unity 5.1.0f3

  9. Morgan

    May 20, 2015 03:24

    Tabs are also ignored

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.