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

Already on GitHub? Sign in to your account

Fix SC.TextFieldView to insert a new line when the enter key is press on a text area #836

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet
4 participants
Member

nicolasbadia commented Sep 17, 2012

A fix were already there for the SC.InlineTextFieldView class so I copy it into the TextFieldView class. I've updated the SC.InlineTextFieldView class so that it now call the super class in the case where it is a text area.

I've also removed some useless code in the SC.InlineTextFieldView class:

  • A fix in the insertNewline method which is not needed anymore
  • The method fieldValueDidChange which only call the super class

Nicolas BADIA added some commits Sep 17, 2012

Fix SC.TextFieldView to insert a new line when the enter key is press…
… on a text area

A fix were already there for the SC.InlineTextFieldView class so I copy
it into the TextFieldView class. I've updated the
SC.InlineTextFieldView class so that it now call the super class in the
case where it is a text area.

I've also removed some useless code in the InlineTextFieldView class:
- A fix in the insertNewline method which is not needed anymore
- The method fieldValueDidChange which only call the super class
Member

nicolasbadia commented Oct 16, 2012

I know there is no test for this but after 2 hours trying to write some, I give up.
If someone know how to test this, I'd love to hear it.

Owner

mauritslamers commented Oct 17, 2012

?? In 1.4.5 it still worked afaik...

Could it have to do with a default action of some sort?

Op 17 okt 2012, om 00:38 heeft Nicolas BADIA het volgende geschreven:

I know there is no test for this but after 2 hours trying to write some, I give up.
If someone know how to test this, I'd love to hear it.


Reply to this email directly or view it on GitHub.

Owner

mauritslamers commented Oct 17, 2012

fake an event, then read out the contents?

Op 17 okt 2012, om 00:38 heeft Nicolas BADIA het volgende geschreven:

I know there is no test for this but after 2 hours trying to write some, I give up.
If someone know how to test this, I'd love to hear it.


Reply to this email directly or view it on GitHub.

Member

nicolasbadia commented Oct 17, 2012

I believe it doesn't work anymore in 1.9.
Faking an event is what I've tried. Here is a simple sample of code where I try to add a "a" to the field:

SC.RunLoop.begin();
var layer = view.get('layer');
evt = SC.Event.simulateEvent(layer, 'keydown', { which: 97, keyCode: 97 });
view.keyDown(evt);
evt = SC.Event.simulateEvent(layer, 'keyup', { which: 97, keyCode: 97 });
view.keyUp(evt);
SC.RunLoop.end();

But the value of the textFieldView never change. I've try a few other things with no success.

Maybe what I'm trying to do is not possible. In this case, how I'm suppose to test that when a user type SC.Event.KEY_RETURN, a new line is insert.

Owner

dcporter commented Oct 17, 2012

Faking events is annoying as hell, very fragile, and 100% possible. Every time I've written one of these tests I've had to step through the code to see where it was expecting some property that I hadn't specified on my fake-event object. It's always been possible though.

On Oct 17, 2012, at 5:12 AM, Nicolas BADIA notifications@github.com wrote:

I believe it doesn't work anymore in 1.9.
Faking an event is what I've tried. Here is a simple sample of code where I try to add a "a" to the field:

SC.RunLoop.begin();
var layer = view.get('layer');
evt = SC.Event.simulateEvent(layer, 'keydown', { which: 97, keyCode: 97 });
view.keyDown(evt);
evt = SC.Event.simulateEvent(layer, 'keyup', { which: 97, keyCode: 97 });
view.keyUp(evt);
SC.RunLoop.end();
But the value of the textFieldView never change. I've try a few other things with no success.

Maybe what I'm trying to do is not possible. In this case, how I'm suppose to test that when a user type SC.Event.KEY_RETURN, a new line has to be inserted.


Reply to this email directly or view it on GitHub.

Member

nicolasbadia commented Oct 17, 2012

I've think about it, and in my case, I have to simulate an event that, at the end, will call the method allowDefault to allow a native browser handling (which will add the caracter at the end of the field).

I'm not 100% sure of what I'm saying, but are you sure it's possible to do this, because I can't find any test which do that. In the case of input, it looks like the value is always change using the val method.

Some actions need to be always handle by a TextFieldView when it has …
…the focus

If a parentView of a TextFieldView handle deleteForward deleteBackward,
moveLeft, moveRight, selectAll, moveUp or moveDown, the event will not
be mapped to the TextFieldView.
Member

nicolasbadia commented Nov 6, 2012

In my opinion, the actions: deleteForward, deleteBackward, moveLeft, moveRight, selectAll, moveUp and moveDown should always be handle by the TextFieldView when it is firstResponder.

I'm not sure all of this can be test more that it is by the test call: "interpretKeyEvents should allow key command methods to be implemented.". If someone know a way to test it, let me know.

Owner

publickeating commented Apr 1, 2013

pushed to 1-9-stable. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment