Suppose I want to type the following comment:
The character for sun is 日, while the character for moon is 月.
To do this, I would type the following sequence of characters:
The character for sun is Alt+`hiSpaceEnterAlt+`, while the character for moon is Alt+`tukiSpaceEnterAlt+`.
But before I get to the end of my comment, the overzealous comment-submitting Enter key takes over the first time I press it, leaving me with a comment that looks like this:
The character for sun is 日
This problem has been brought up before:
- Here on MSO, but only as an answer as near as I can tell.
- On meta.Japanese.SE. The resolution of this problem for Japanese.SE (where basically everybody uses an IME (input method editor) that requires the Enter key to be pressed often as part of normal typing) was apparently to disable comment submission via the Enter key altogether, as near as I can tell.
This is a bug that should be fixed, whether by turning off Enter-submits-comments (which I guess the Powers That Be are opposed to) or by some other method.
(This might be a regression - I don't remember this happening to me before, but that might be because this is the first time I've tried using my IME in a comment outside of Japanese.SE. If it matters, I'm on Chrome 32.0.1700.76 on Windows 7, and I get this behavior using both Google Japanese Input and the Microsoft IME)
Update (21 Jan 2015): I cannot reproduce this behavior in Chrome 41.0.2272.12 dev-m on Windows 8. Maybe this was a bug in earlier versions of Chrome? In any case, if this issue is fixed in stable Chrome (I don't have it on any of my machines because of this), this should probably be marked status-norepro.
3 Answers 3
I've encountered such issues before (in other web apps). This issue happens on all sites when the user uses the keyboard to select a spell check suggestion (arrows + Enter).
The solution to this problem is to not use the keyup event, but the keydown event.
When I check the source code of http://dev.meta.stackoverflow.com/content/Js/full.en.js, I can see that the submit-on-Enter feature is implemented using:
var bind_submitOnEnterPress = function(jForm)
{
jForm.find('textarea').keyup(function(event)
{
if (event.which == 13 && !event.shiftKey && !$(this).prev("#tabcomplete:visible").length)
jForm.submit()
}).keypress(function(event)
{
if (event.which == 13 && !event.shiftKey)
return false
})
};
Replacing keyup with keydown (and removing keypress) ought to solve the problem.
As I mentioned in the comments above, I've come up with what I hope is a client-side JavaScript fix for both this bug as well as this non-IME-related one:
StackExchange.options.desc = true;
$('body').on( 'keydown keypress', 'form[id*="-comment-"] textarea',
function (e) {
if ( e.which != 13 || e.shiftKey ) return;
e.preventDefault();
if ( e.type == 'keydown' &&
$(this).prev('#tabcomplete:visible').length == 0 )
$(this).closest('form').submit();
}
);
This code does pretty much exactly what Rob W suggests in his answer:
The first line simply sets a config option that tells the Stack Exchange JS code not to attach its normal submit-on-enter event handler. This option is currently enabled by default e.g. on Japanese Language Stack Exchange, where this bug has apparently caused enough problems to convince the developers to disable comment submission using the enter key.
The rest of the code sets up a custom keyboard event handler that does pretty much the same thing as the SE event handler we just disabled, except that it's attached to the
keydownevent rather than tokeyup. It appears that this simple change is enough to fix the bug.(I'm also using the same handler to suppress the default behavior of the
keypressevent, which would insert a line break in the text; the SE code uses a separate event handler for that.)
I have included this fix in version 1.4 of the Stack Overflow Unofficial Patch, a collection of client-side user interface fixes for Stack Exchange sites. If you're using an IME and a browser with user script support, such as Firefox (with GreaseMonkey), Chrome (with Tampermonkey), Opera (native support) or possibly Safari (with NinjaKit), please give it a try!
Note: If you try SOUP and find that it does not fix this bug for you, or that it has any undesirable side effects, please let me know! Apparently, this bug is only triggered by some combinations of browser, OS, IME and possibly keyboard / locale, and I can't rule out the possibility that this fix might not work for all of them. (In fact, since I don't normally use an IME myself, my ability to test this fix has been quite limited. I'm fairly confident that it at least shouldn't make things any worse, but that's about it.)
-
1Another app of interest: Disable enter for submitting comments. . . . . @Ilmari, do you have a link to some documentation about the object
StackOverflow?brasofilo– brasofilo2014年10月02日 19:04:04 +00:00Commented Oct 2, 2014 at 19:04
If they want to keep it by design, probably it still should be an user preference, so everyone that's happy with current behaviour will stay happy, and the ones that use IME can disable the enter to submit without affecting others.
You must log in to answer this question.
Explore related questions
See similar questions with these tags.
Shift-ENTERwork?Shift-ENTERdoesn't work for you and posts the comment immediately?