News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Ctrl+Enter for Quick/Full reply form

Started by Bugo, December 09, 2010, 04:57:38 PM

Previous topic - Next topic

Bugo

SMF 2.0 RC4, open GenericControls.template.php, find:
<textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" rows="', $editor_context['rows'], '" cols=" ', $context['browser']['is_ie8'] ? '600' : $editor_context['columns'], '" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="', $context['tabindex']++, '" style="width: ', $editor_context['width'], '; height: ', $editor_context['height'], '; ', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? 'border: 1px solid red;' : '', '">', $editor_context['value'], '</textarea>
replace with:
<textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" rows="', $editor_context['rows'], '" cols=" ', $context['browser']['is_ie8'] ? '600' : $editor_context['columns'], '" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="', $context['tabindex']++, '" style="width: ', $editor_context['width'], '; height: ', $editor_context['height'], '; ', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? 'border: 1px solid red;' : '', '" onkeypress="if(event.keyCode==10 || (event.ctrlKey && event.keyCode==13)) {submit();}">', $editor_context['value'], '</textarea>

Then open Display.template.php, find:
<textarea cols="75" rows="7" style="', $context['browser']['is_ie8'] ? 'max-width: 100%; min-width: 100%' : 'width: 100%', '; height: 100px;" name="message" tabindex="', $context['tabindex']++, '"></textarea>
replace with:
<textarea cols="75" rows="7" style="', $context['browser']['is_ie8'] ? 'max-width: 100%; min-width: 100%' : 'width: 100%', '; height: 100px;" name="message" tabindex="', $context['tabindex']++, '" onkeypress="if(event.keyCode==10 || (event.ctrlKey && event.keyCode==13)) {submit();}"></textarea>

Open Modifications.english.php and paste to end:

// Ctrl+Enter for Quick/Full reply form
$txt['shortcuts'] =  'shortcuts: hit ctrl+enter to submit/post or alt+p to preview';
$txt['shortcuts_firefox'] = 'shortcuts: hit ctrl+enter to submit/post or shift+alt+p to preview';


Open Post.english.php and paste to end too:

// Ctrl+Enter for Quick/Full reply form
$txt['shortcuts'] =  'shortcuts: hit ctrl+enter to submit/post or alt+p to preview';
$txt['shortcuts_firefox'] = 'shortcuts: hit ctrl+enter to submit/post or shift+alt+p to preview';


Arantor


Antechinus

Someone else bumped it. That post has apparently been removed.

Arantor


Antechinus

They probably can't get real ham in Russia. All those embargoes.

rez_spb

I have seen the warning about 120 days, but the issue is too related to start a new topic.

This workaround does not work for SMF 2.1 Beta 3, and I really want it to work. Hitting 'alt' is a generally bad idea.

I was unable to find the correct way to implement it: now the proper textarea is in a nested div, and I cannot find in editable code where to add <Ctrl+Enter> JS.
That means that while the workaround is in place, the browser does not react because cursor is actually in another textarea, probably generated by that large... minified... Jquery or something like that.

Maybe it's time for devs to make <Ctrl+Enter> a setting? Or better allow us to assign our own shortcuts?

Arantor

My fix was in https://github.com/StoryBB/StoryBB/commit/555bc946d860d9f15762d3e77ce3158620b1f179 of which this would go in GenericControls.template.php with minimal changes (namely about putting the editor name into the code)

I'm not convinced this should necessarily be core though. I made core in my case because strong lobby from other devs but not sure about SMF. Maybe better as a mod.

rez_spb

I am pretty much for any way that gives new editor ability to override on per-admin base, be it core, optional or external mod.
Too bad I'm not that savvy in... let's call it 'modern JS' to even understand where to copy your commit, so I cannot compose anything sane and share with everyone. I am sorry.

rez_spb

#9
OK I cannot edit the post above, I am sorry for that.

The good news is that after some stupid looking at API and documentation for SCEditor, googling for similar questions, and of course adopting Arantor's code (thank you so much!) I was able to add '<Ctrl+Enter>' for SMF 2.1 Beta 3 (and unable to remove default shortcuts because did not find them at all).

Instructions for future generations.
Replace following code block in Themes/default/GenericControls.template.php (around line 111):

                                });

                                $("#', $editor_id, '").data("sceditor").createPermanentDropDown();', $editor_context['rich_active'] ? '' : '

...with that one:

                                });

                                // Adding <Ctrl+Enter> shortcut
                                $("#' . $editor_id . '").data("sceditor").addShortcut("ctrl+enter", function () {
                                        $("#' . $editor_id . '").closest("form").submit();
                                });

                                $("#', $editor_id, '").data("sceditor").createPermanentDropDown();', $editor_context['rich_active'] ? '' : '


I am not sure that getting closest form will not break in the future and I don't quite understand how to address it properly, but this adaptation restored <Ctrl+Enter> for both Quick Reply and Reply forms.

Limitation: does not send for 'quick modify', instead cancels modification. If someone had the solution, that'd be nice!

Arantor

Closest form makes perfect sense - it means to start from the editor widget itself and go up the tree of elements until it hits the nearest form element that contains the editor widget.

Does quick modify use the rich editor these days? It's been a long time since I looked.

Illori


Kindred

Although it is of limited use, since beta3 is old and should not actually be used......
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

rez_spb

Quote from: Kindred on December 11, 2018, 08:39:41 PM
Although it is of limited use, since beta3 is old and should not actually be used......
Yes, it's older than 1 year, but is the latest available frozen package on the downloads page.
It was that or CI/bleeding edge from GitHub, so obviously I took frozen package to be able to refer to a state in time/code.
Maybe it's time for a public beta 4?

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

The plan is to have RC1 "soon" rather than beta 4, but a year plus between betas is only going to be more problematic as time goes on.

live627

Quote from: rez_spb on December 11, 2018, 04:14:40 PM
OK I cannot edit the post above, I am sorry for that.

The good news is that after some stupid looking at API and documentation for SCEditor, googling for similar questions, and of course adopting Arantor's code (thank you so much!) I was able to add '<Ctrl+Enter>' for SMF 2.1 Beta 3 (and unable to remove default shortcuts because did not find them at all).

Instructions for future generations.
Replace following code block in Themes/default/GenericControls.template.php (around line 111):

                                });

                                $("#', $editor_id, '").data("sceditor").createPermanentDropDown();', $editor_context['rich_active'] ? '' : '

...with that one:

                                });

                                // Adding <Ctrl+Enter> shortcut
                                $("#' . $editor_id . '").data("sceditor").addShortcut("ctrl+enter", function () {
                                        $("#' . $editor_id . '").closest("form").submit();
                                });

                                $("#', $editor_id, '").data("sceditor").createPermanentDropDown();', $editor_context['rich_active'] ? '' : '


I am not sure that getting closest form will not break in the future and I don't quite understand how to address it properly, but this adaptation restored <Ctrl+Enter> for both Quick Reply and Reply forms.

Limitation: does not send for 'quick modify', instead cancels modification. If someone had the solution, that'd be nice!

I've adapted your code for beta 4 (likely would remain this way through the final release):

Find in the same file at or around line 41

sceditor.create(textarea, ', $smcFunc['json_encode']($editor_context['sce_options'], JSON_PRETTY_PRINT), ');';

Replace with

sceditor.create(textarea, ', $smcFunc['json_encode']($editor_context['sce_options'], JSON_PRETTY_PRINT), ');
sceditor.instance(textarea).addShortcut("ctrl+enter", function () {
$(".sceditor-container").closest("form").submit();
});';

rez_spb

Thank you, live627!
Will test is as soon as I switch to GitHub release which looks like the thing I should do to continue the feedback.
Feeling relieved that 'closest' made its way into the code.

Advertisement: