Skip to content

Commit f95622c

Browse files
authored
Fix issue comment form and quick-submit (#30623)
1. Rewrite initGlobalEnterQuickSubmit (by the way, remove jQuery) 2. Fix issue comment form layout
1 parent e865de1 commit f95622c

File tree

7 files changed

+37
-38
lines changed

7 files changed

+37
-38
lines changed

templates/devtest/fetch-action.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<button name="btn">submit get</button>
2222
</form>
2323
<form method="post" action="fetch-action-test?k=1" class="form-fetch-action">
24-
<div><textarea name="text" rows="3" class="js-quick-submit"></textarea></div>
24+
<div><textarea name="text" rows="3"></textarea></div>
2525
<div><label><input name="check" type="checkbox"> check</label></div>
2626
<div><button name="btn">submit post</button></div>
2727
</form>

templates/repo/issue/view_content.tmpl

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,34 @@
8585
{{ctx.AvatarUtils.Avatar .SignedUser 40}}
8686
</a>
8787
<div class="content">
88-
<form class="ui segment form form-fetch-action" id="comment-form" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/comments" method="post">
89-
{{template "repo/issue/comment_tab" .}}
90-
{{.CsrfTokenHtml}}
91-
<div class="field footer">
92-
<div class="text right">
93-
{{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .DisableStatusChange)}}
94-
{{if .Issue.IsClosed}}
95-
<button id="status-button" class="ui primary basic button" data-status="{{ctx.Locale.Tr "repo.issues.reopen_issue"}}" data-status-and-comment="{{ctx.Locale.Tr "repo.issues.reopen_comment_issue"}}" name="status" value="reopen">
96-
{{ctx.Locale.Tr "repo.issues.reopen_issue"}}
97-
</button>
98-
{{else}}
99-
{{$closeTranslationKey := "repo.issues.close"}}
100-
{{if .Issue.IsPull}}
101-
{{$closeTranslationKey = "repo.pulls.close"}}
88+
<div class="ui segment">
89+
<form class="ui form form-fetch-action" id="comment-form" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/comments" method="post">
90+
{{template "repo/issue/comment_tab" .}}
91+
{{.CsrfTokenHtml}}
92+
<div class="field footer">
93+
<div class="text right">
94+
{{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .DisableStatusChange)}}
95+
{{if .Issue.IsClosed}}
96+
<button id="status-button" class="ui primary basic button" data-status="{{ctx.Locale.Tr "repo.issues.reopen_issue"}}" data-status-and-comment="{{ctx.Locale.Tr "repo.issues.reopen_comment_issue"}}" name="status" value="reopen">
97+
{{ctx.Locale.Tr "repo.issues.reopen_issue"}}
98+
</button>
99+
{{else}}
100+
{{$closeTranslationKey := "repo.issues.close"}}
101+
{{if .Issue.IsPull}}
102+
{{$closeTranslationKey = "repo.pulls.close"}}
103+
{{end}}
104+
<button id="status-button" class="ui red basic button" data-status="{{ctx.Locale.Tr $closeTranslationKey}}" data-status-and-comment="{{ctx.Locale.Tr "repo.issues.close_comment_issue"}}" name="status" value="close">
105+
{{ctx.Locale.Tr $closeTranslationKey}}
106+
</button>
102107
{{end}}
103-
<button id="status-button" class="ui red basic button" data-status="{{ctx.Locale.Tr $closeTranslationKey}}" data-status-and-comment="{{ctx.Locale.Tr "repo.issues.close_comment_issue"}}" name="status" value="close">
104-
{{ctx.Locale.Tr $closeTranslationKey}}
105-
</button>
106108
{{end}}
107-
{{end}}
108-
<button class="ui primary button">
109-
{{ctx.Locale.Tr "repo.issues.create_comment"}}
110-
</button>
109+
<button class="ui primary button">
110+
{{ctx.Locale.Tr "repo.issues.create_comment"}}
111+
</button>
112+
</div>
111113
</div>
112-
</div>
113-
</form>
114+
</form>
115+
</div>
114116
</div>
115117
</div>
116118
{{else if .Repository.IsArchived}}

templates/shared/combomarkdowneditor.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Template Attributes:
4545
</div>
4646
</markdown-toolbar>
4747
<text-expander keys=": @" suffix="">
48-
<textarea class="markdown-text-editor js-quick-submit"{{if .TextareaName}} name="{{.TextareaName}}"{{end}}{{if .TextareaPlaceholder}} placeholder="{{.TextareaPlaceholder}}"{{end}}{{if .TextareaAriaLabel}} aria-label="{{.TextareaAriaLabel}}"{{end}}{{if .DisableAutosize}} data-disable-autosize="{{.DisableAutosize}}"{{end}}>{{.TextareaContent}}</textarea>
48+
<textarea class="markdown-text-editor"{{if .TextareaName}} name="{{.TextareaName}}"{{end}}{{if .TextareaPlaceholder}} placeholder="{{.TextareaPlaceholder}}"{{end}}{{if .TextareaAriaLabel}} aria-label="{{.TextareaAriaLabel}}"{{end}}{{if .DisableAutosize}} data-disable-autosize="{{.DisableAutosize}}"{{end}}>{{.TextareaContent}}</textarea>
4949
</text-expander>
5050
<script>
5151
if (localStorage?.getItem('markdown-editor-monospace') === 'true') {

templates/user/settings/keys_ssh.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</div>
1717
<div class="field {{if .Err_Content}}error{{end}}">
1818
<label for="ssh-key-content">{{ctx.Locale.Tr "settings.key_content"}}</label>
19-
<textarea id="ssh-key-content" name="content" class="js-quick-submit" placeholder="{{ctx.Locale.Tr "settings.key_content_ssh_placeholder"}}" required>{{.content}}</textarea>
19+
<textarea id="ssh-key-content" name="content" placeholder="{{ctx.Locale.Tr "settings.key_content_ssh_placeholder"}}" required>{{.content}}</textarea>
2020
</div>
2121
<input name="type" type="hidden" value="ssh">
2222
<button class="ui primary button">
@@ -84,7 +84,7 @@
8484
</div>
8585
<div class="field">
8686
<label for="signature">{{ctx.Locale.Tr "settings.ssh_token_signature"}}</label>
87-
<textarea id="ssh-key-signature" name="signature" class="js-quick-submit" placeholder="{{ctx.Locale.Tr "settings.key_signature_ssh_placeholder"}}" required>{{$.signature}}</textarea>
87+
<textarea id="ssh-key-signature" name="signature" placeholder="{{ctx.Locale.Tr "settings.key_signature_ssh_placeholder"}}" required>{{$.signature}}</textarea>
8888
</div>
8989
<input name="type" type="hidden" value="verify_ssh">
9090
<button class="ui primary button">

web_src/css/repo.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,8 +1080,8 @@ td .commit-summary {
10801080
clear: none;
10811081
}
10821082

1083-
.repository .comment.form .content .form::before,
1084-
.repository .comment.form .content .form::after {
1083+
.repository .comment.form .content .segment::before,
1084+
.repository .comment.form .content .segment::after {
10851085
right: 100%;
10861086
top: 20px;
10871087
border: solid transparent;
@@ -1092,13 +1092,13 @@ td .commit-summary {
10921092
pointer-events: none;
10931093
}
10941094

1095-
.repository .comment.form .content .form::before {
1095+
.repository .comment.form .content .segment::before {
10961096
border-right-color: var(--color-secondary);
10971097
border-width: 9px;
10981098
margin-top: -9px;
10991099
}
11001100

1101-
.repository .comment.form .content .form::after {
1101+
.repository .comment.form .content .segment::after {
11021102
border-right-color: var(--color-box-body);
11031103
border-width: 8px;
11041104
margin-top: -8px;

web_src/js/features/common-global.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ export function initFootLanguageMenu() {
4646
}
4747

4848
export function initGlobalEnterQuickSubmit() {
49-
$(document).on('keydown', '.js-quick-submit', (e) => {
50-
if (((e.ctrlKey && !e.altKey) || e.metaKey) && (e.key === 'Enter')) {
49+
document.addEventListener('keydown', (e) => {
50+
const isQuickSubmitEnter = ((e.ctrlKey && !e.altKey) || e.metaKey) && (e.key === 'Enter');
51+
if (isQuickSubmitEnter && e.target.matches('textarea')) {
52+
e.preventDefault();
5153
handleGlobalEnterQuickSubmit(e.target);
52-
return false;
5354
}
5455
});
5556
}

web_src/js/features/comp/QuickSubmit.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,5 @@ export function handleGlobalEnterQuickSubmit(target) {
99
// here use the event to trigger the submit event (instead of calling `submit()` method directly)
1010
// otherwise the `areYouSure` handler won't be executed, then there will be an annoying "confirm to leave" dialog
1111
form.dispatchEvent(new SubmitEvent('submit', {bubbles: true, cancelable: true}));
12-
} else {
13-
// if no form, then the editor is for an AJAX request, dispatch an event to the target, let the target's event handler to do the AJAX request.
14-
// the 'ce-' prefix means this is a CustomEvent
15-
target.dispatchEvent(new CustomEvent('ce-quick-submit', {bubbles: true}));
1612
}
1713
}

0 commit comments

Comments
 (0)