Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline TextField + TextEvent.TEXT_INPUT: event.text should be \n instead of \r when user press enter #19482

Open
ylazy opened this issue Feb 10, 2025 · 6 comments · May be fixed by #19517
Open
Labels
bug Something isn't working input Issues relating to user input in Flash content text Issues relating to text rendering/input

Comments

@ylazy
Copy link

ylazy commented Feb 10, 2025

Describe the bug

On TextEvent.TEXT_INPUT event handler, when I get event.text:

Flash: I got event.text = \n
Ruffle: I got event.text = \r

Expected behavior

event.text should return \n

Content Location

There's no need a swf to reproduce the bug.

Affected platform

Desktop app

Operating system

Windows 11

Browser

No response

Additional information

No response

@ylazy ylazy added the bug Something isn't working label Feb 10, 2025
@kjarosh kjarosh added text Issues relating to text rendering/input input Issues relating to user input in Flash content labels Feb 10, 2025
@evilpie
Copy link
Collaborator

evilpie commented Feb 14, 2025

Did we hardcode this wrong?

const INPUT_NEWLINE: char = '\r';

The following test code produces U+A (Line Feed) for me on Linux with Flash:

package {
    import flash.display.Sprite;
    import flash.events.TextEvent;
    import flash.text.TextField;
    import flash.text.TextFieldType;

    public class Test extends Sprite {
        public function Test() {
            var textField = new TextField();
            textField.type = TextFieldType.INPUT;
            textField.border = true;
            textField.multiline = true;
            textField.height = 200;
            textField.addEventListener(TextEvent.TEXT_INPUT, onInput);
            addChild(textField);
        }

        public function onInput(evt: TextEvent) {
            trace("onInput: U+" + evt.text.charCodeAt(0).toString(16).toUpperCase() + " " + evt.text.length);
        }
    }
}

@kjarosh
Copy link
Member

kjarosh commented Feb 14, 2025

I believe Flash is just weird with newlines. We should write some tests related to newlines in every possible place that a newline might allear. I believe Flash uses internally CR for newlines, but sometimes surfaces it as LF to the user.

@evilpie
Copy link
Collaborator

evilpie commented Feb 14, 2025

Ah, I think I know what you mean. Entering [A] [Enter] [B] produces the "textInput" events A, Line Feed (U+A) and B. But the text property of the TextField contains Carriage Return (U+D).

@kjarosh
Copy link
Member

kjarosh commented Feb 14, 2025

I think we should also replace LF with CR when setting the text (e.g. field.text = 'a\nb'). Which would mean Flash is likely to use LF on the user level and CR on the text field level, so pressing enter would generate a LF, but it would be latter replaced with a CR.

@evilpie
Copy link
Collaborator

evilpie commented Feb 14, 2025

At least for the KEY_DOWN event Flash also uses a CR. (#19518)

@ylazy
Copy link
Author

ylazy commented Feb 15, 2025

I remember that years ago I had read somewhere that Flash expect the newline that user input is \n (LF) and what Flash output when you get the .text property is \r (CR).

So in this case the event.text is what user input so it should be \n.

There's no problem if user input \r I think, Flash still will show a new line, but it can break existing apps if a developer do a check if (event.text == "\n")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working input Issues relating to user input in Flash content text Issues relating to text rendering/input
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants