Advertisement:

Author Topic: Ctrl+Enter for Quick/Full reply form  (Read 4273 times)

Offline Bugo

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,533
  • Gender: Male
    • dragomano on GitHub
    • @dragomano on Twitter
    • Russian translations for SMF mods
Ctrl+Enter for Quick/Full reply form
« on: December 09, 2010, 04:57:38 PM »
SMF 2.0 RC4, open GenericControls.template.php, find:
Code: [Select]
<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:
Code: [Select]
<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:
Code: [Select]
<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:
Code: [Select]
<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:
Code: [Select]
// 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:
Code: [Select]
// 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';

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,321
  • Master of BBC Abuse
Re: Ctrl+Enter for Quick/Full reply form
« Reply #1 on: January 05, 2015, 02:39:34 PM »
Nice tip.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,252
    • StoryBB/StoryBB on GitHub
Re: Ctrl+Enter for Quick/Full reply form
« Reply #2 on: January 05, 2015, 02:42:13 PM »
(Necro bump is necrotic.)
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,321
  • Master of BBC Abuse
Re: Ctrl+Enter for Quick/Full reply form
« Reply #3 on: January 05, 2015, 02:43:28 PM »
Someone else bumped it. That post has apparently been removed.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,252
    • StoryBB/StoryBB on GitHub
Re: Ctrl+Enter for Quick/Full reply form
« Reply #4 on: January 05, 2015, 02:44:47 PM »
Yes because it was spam in Russian...
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,321
  • Master of BBC Abuse
Re: Ctrl+Enter for Quick/Full reply form
« Reply #5 on: January 05, 2015, 02:46:45 PM »
They probably can't get real ham in Russia. All those embargoes.

Offline rez_spb

  • Newbie
  • *
  • Posts: 8
Re: Ctrl+Enter for Quick/Full reply form
« Reply #6 on: December 11, 2018, 01:46:23 PM »
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?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,252
    • StoryBB/StoryBB on GitHub
Re: Ctrl+Enter for Quick/Full reply form
« Reply #7 on: December 11, 2018, 01:57:04 PM »
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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline rez_spb

  • Newbie
  • *
  • Posts: 8
Re: Ctrl+Enter for Quick/Full reply form
« Reply #8 on: December 11, 2018, 02:23:11 PM »
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.

Offline rez_spb

  • Newbie
  • *
  • Posts: 8
Re: Ctrl+Enter for Quick/Full reply form
« Reply #9 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):
Code: [Select]
                                });

                                $("#', $editor_id, '").data("sceditor").createPermanentDropDown();', $editor_context['rich_active'] ? '' : '
...with that one:
Code: [Select]
                                });

                                // 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!
« Last Edit: December 11, 2018, 04:37:43 PM by rez_spb »

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,252
    • StoryBB/StoryBB on GitHub
Re: Ctrl+Enter for Quick/Full reply form
« Reply #10 on: December 11, 2018, 04:59:03 PM »
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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Illori

  • Project Manager
  • SMF Legend
  • *
  • Posts: 51,046
Re: Ctrl+Enter for Quick/Full reply form
« Reply #11 on: December 11, 2018, 05:22:00 PM »
yes.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,339
  • Gender: Male
    • Kindred-999 on GitHub
Re: Ctrl+Enter for Quick/Full reply form
« Reply #12 on: December 11, 2018, 08:39:41 PM »
Although it is of limited use, since beta3 is old and should not actually be used......
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline rez_spb

  • Newbie
  • *
  • Posts: 8
Re: Ctrl+Enter for Quick/Full reply form
« Reply #13 on: December 12, 2018, 04:19:44 AM »
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?

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,339
  • Gender: Male
    • Kindred-999 on GitHub
Re: Ctrl+Enter for Quick/Full reply form
« Reply #14 on: December 12, 2018, 08:14:50 AM »
no. it's not....  :P
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,252
    • StoryBB/StoryBB on GitHub
Re: Ctrl+Enter for Quick/Full reply form
« Reply #15 on: December 12, 2018, 08:22:52 AM »
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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline live627

  • Development Contributor
  • SMF Hero
  • *
  • Posts: 5,620
  • Gender: Male
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: Ctrl+Enter for Quick/Full reply form
« Reply #16 on: December 12, 2018, 04:50:02 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):
Code: [Select]
                                });

                                $("#', $editor_id, '").data("sceditor").createPermanentDropDown();', $editor_context['rich_active'] ? '' : '
...with that one:
Code: [Select]
                                });

                                // 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

Code: [Select]
sceditor.create(textarea, ', $smcFunc['json_encode']($editor_context['sce_options'], JSON_PRETTY_PRINT), ');';
Replace with

Code: [Select]
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();
});';
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline rez_spb

  • Newbie
  • *
  • Posts: 8
Re: Ctrl+Enter for Quick/Full reply form
« Reply #17 on: December 15, 2018, 06:11:20 AM »
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.