Browse Source

Ctrl + Enter to submit forms (#2540)

* Hotfix for "Add time manually" (https://github.com/go-gitea/gitea/pull/2211#issuecomment-328780125)

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Submit forms if Ctrl+Enter is pressed inside a textarea

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Adding separate class for Ctrl+Enter-Submit
Checking if alt key is pressed too

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Changing .ctrlenter to .js-quick-submit

Signed-off-by: Jonas Franz <info@jonasfranz.software>
Jonas Franz 2 years ago
parent
commit
b4b0280e33
2 changed files with 10 additions and 1 deletions
  1. 9 0
      public/js/index.js
  2. 1 1
      templates/repo/issue/comment_tab.tmpl

+ 9 - 0
public/js/index.js

@@ -1579,6 +1579,7 @@ $(document).ready(function () {
1579 1579
     initCodeView();
1580 1580
     initVueApp();
1581 1581
     initTeamSettings();
1582
+    initCtrlEnterSubmit();
1582 1583
 
1583 1584
     // Repo clone url.
1584 1585
     if ($('#repo-clone-url').length > 0) {
@@ -1786,6 +1787,14 @@ function initVueComponents(){
1786 1787
     })
1787 1788
 }
1788 1789
 
1790
+function initCtrlEnterSubmit() {
1791
+    $(".js-quick-submit").keydown(function(e) {
1792
+        if (((e.ctrlKey && !e.altKey) || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
1793
+            $(this).closest("form").submit();
1794
+        }
1795
+    });
1796
+}
1797
+
1789 1798
 function initVueApp() {
1790 1799
     var el = document.getElementById('app');
1791 1800
     if (!el) {

+ 1 - 1
templates/repo/issue/comment_tab.tmpl

@@ -4,7 +4,7 @@
4 4
 		<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}">{{.i18n.Tr "repo.release.preview"}}</a>
5 5
 	</div>
6 6
 	<div class="ui bottom attached active tab segment" data-tab="write">
7
-		<textarea id="content" class="edit_area" name="content" tabindex="4" data-id="issue-{{.RepoName}}" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.Repo.RepoLink}}">
7
+		<textarea id="content" class="edit_area js-quick-submit" name="content" tabindex="4" data-id="issue-{{.RepoName}}" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.Repo.RepoLink}}">
8 8
 {{if .IssueTemplate}}{{.IssueTemplate}}{{else if .PullRequestTemplate}}{{.PullRequestTemplate}}{{else}}{{.content}}{{end}}</textarea>
9 9
 	</div>
10 10
 	<div class="ui bottom attached tab segment markdown" data-tab="preview">