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

Ctrl + Enter to submit forms #2540

Merged
merged 11 commits into from
Sep 22, 2017
Merged

Conversation

jonasfranz
Copy link
Member

This adds the functionality of submiting forms when Ctrl + Enter is pressed inside a textarea.

Fixes #2526

@codecov-io
Copy link

codecov-io commented Sep 18, 2017

Codecov Report

Merging #2540 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2540   +/-   ##
=======================================
  Coverage   27.32%   27.32%           
=======================================
  Files          86       86           
  Lines       17135    17135           
=======================================
  Hits         4682     4682           
  Misses      11775    11775           
  Partials      678      678

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1be2b4a...524541e. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 18, 2017
@@ -1786,6 +1787,14 @@ function initVueComponents(){
})
}

function initCtrlEnterSubmit() {
$("textarea").keydown(function(e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this global/general event. What about creating class for that and use it in tmpl where you want to apply this feature?

@@ -1786,6 +1787,14 @@ function initVueComponents(){
})
}

function initCtrlEnterSubmit() {
$("textarea").keydown(function(e) {
if ((e.ctrlKey || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work on windows correctly as e.ctrlKey will fire also on AltGr+Enter. It should be something like:
(e.ctrlKey && !e.altKey) || e.metaKey to check if ctrl/meta key is pressed

Checking if alt key is pressed too

Signed-off-by: Jonas Franz <info@jonasfranz.software>
@lafriks
Copy link
Member

lafriks commented Sep 18, 2017

LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Sep 18, 2017
@@ -1786,6 +1787,14 @@ function initVueComponents(){
})
}

function initCtrlEnterSubmit() {
$(".ctrlenter").keydown(function(e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was searching for better solution than using class. We can use custom attribute. e.g. "submit" (or "keysubmit", "autosubmit", 'submit="ctrl+enter"', ...) and do simple jq select like $("textarea[autosubmit]") or $("[autosubmit]") or $["[submit='ctrl+enter']"].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lafriks What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not (pure/jq) js expert, but is not purpose of data- attributes for storing data? We need only element selector. Using data- would work too, but it has other meaning and purpose for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g. boostrap uses data- attributes for their javascript handlers intensively

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Morlinest @daviian So can we agree on solution so that either @JonasFranzDEV can fix this or we can merge it as is

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lafriks For me it is ok as it is. The class could be a little more descriptive, at first glance nobody would know that it is for form submission. Something like can-ctrlenter-submit

But I don't want to enforce my opinion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just take inspiration from github and use "js-quick-submit" class name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonasFranzDEV please change class name to @Morlinest suggested

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lafriks Done

@ethantkoenig
Copy link
Member

ethantkoenig commented Sep 19, 2017

We should add Ctrl+Enter functionality to the description field of the new issue page as well.

Also, the commit form in the web editor would also be nice.

@lunny lunny added this to the 1.x.x milestone Sep 19, 2017
@jonasfranz
Copy link
Member Author

@ethantkoenig It is usable at the new issue page as well since it uses comment_tab as textarea.

@bkcsoft
Copy link
Member

bkcsoft commented Sep 19, 2017

@JonasFranzDEV We should just make the comment editor a Vue Component :trollface:

@sapk
Copy link
Member

sapk commented Sep 20, 2017

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Sep 20, 2017
@lunny lunny added the type/enhancement An improvement of existing functionality label Sep 20, 2017
@lunny lunny modified the milestones: 1.x.x, 1.3.0 Sep 20, 2017
@lunny lunny merged commit b4b0280 into go-gitea:master Sep 22, 2017
@jonasfranz jonasfranz deleted the ctrl-enter-to-submit branch September 22, 2017 16:20
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ctrl+Enter to post issue or comment