Make Ctrl+Enter work for issue/comment edit (#30720)

Fix #30710
This commit is contained in:
wxiaoguang 2024-04-27 22:32:00 +08:00 committed by GitHub
parent 6d2a307ad8
commit 8de2992ffb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 8 deletions

View File

@ -235,7 +235,7 @@
{{if and (not $.Repository.IsArchived) (not .DiffNotAvailable)}} {{if and (not $.Repository.IsArchived) (not .DiffNotAvailable)}}
<template id="issue-comment-editor-template"> <template id="issue-comment-editor-template">
<div class="ui comment form"> <div class="ui form comment">
{{template "shared/combomarkdowneditor" (dict {{template "shared/combomarkdowneditor" (dict
"MarkdownPreviewUrl" (print $.Repository.Link "/markup") "MarkdownPreviewUrl" (print $.Repository.Link "/markup")
"MarkdownPreviewContext" $.RepoLink "MarkdownPreviewContext" $.RepoLink
@ -249,7 +249,7 @@
{{end}} {{end}}
<div class="text right edit buttons"> <div class="text right edit buttons">
<button class="ui cancel button">{{ctx.Locale.Tr "repo.issues.cancel"}}</button> <button class="ui cancel button">{{ctx.Locale.Tr "repo.issues.cancel"}}</button>
<button class="ui primary save button">{{ctx.Locale.Tr "repo.issues.save"}}</button> <button class="ui primary button">{{ctx.Locale.Tr "repo.issues.save"}}</button>
</div> </div>
</div> </div>
</template> </template>

View File

@ -146,7 +146,7 @@
</div> </div>
<template id="issue-comment-editor-template"> <template id="issue-comment-editor-template">
<div class="ui comment form"> <div class="ui form comment">
<div class="field"> <div class="field">
{{template "shared/combomarkdowneditor" (dict {{template "shared/combomarkdowneditor" (dict
"MarkdownPreviewUrl" (print .Repository.Link "/markup") "MarkdownPreviewUrl" (print .Repository.Link "/markup")
@ -164,8 +164,8 @@
<div class="field"> <div class="field">
<div class="text right edit"> <div class="text right edit">
<button class="ui basic cancel button">{{ctx.Locale.Tr "repo.issues.cancel"}}</button> <button class="ui cancel button">{{ctx.Locale.Tr "repo.issues.cancel"}}</button>
<button class="ui primary save button">{{ctx.Locale.Tr "repo.issues.save"}}</button> <button class="ui primary button">{{ctx.Locale.Tr "repo.issues.save"}}</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,5 +1,5 @@
export function handleGlobalEnterQuickSubmit(target) { export function handleGlobalEnterQuickSubmit(target) {
const form = target.closest('form'); let form = target.closest('form');
if (form) { if (form) {
if (!form.checkValidity()) { if (!form.checkValidity()) {
form.reportValidity(); form.reportValidity();
@ -9,5 +9,10 @@ export function handleGlobalEnterQuickSubmit(target) {
// here use the event to trigger the submit event (instead of calling `submit()` method directly) // here use the event to trigger the submit event (instead of calling `submit()` method directly)
// otherwise the `areYouSure` handler won't be executed, then there will be an annoying "confirm to leave" dialog // otherwise the `areYouSure` handler won't be executed, then there will be an annoying "confirm to leave" dialog
form.dispatchEvent(new SubmitEvent('submit', {bubbles: true, cancelable: true})); form.dispatchEvent(new SubmitEvent('submit', {bubbles: true, cancelable: true}));
return;
}
form = target.closest('.ui.form');
if (form) {
form.querySelector('.ui.primary.button')?.click();
} }
} }

View File

@ -162,8 +162,8 @@ async function onEditContent(event) {
editContentZone.innerHTML = document.getElementById('issue-comment-editor-template').innerHTML; editContentZone.innerHTML = document.getElementById('issue-comment-editor-template').innerHTML;
comboMarkdownEditor = await initComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor')); comboMarkdownEditor = await initComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'));
comboMarkdownEditor.attachedDropzoneInst = await setupDropzone(editContentZone.querySelector('.dropzone')); comboMarkdownEditor.attachedDropzoneInst = await setupDropzone(editContentZone.querySelector('.dropzone'));
editContentZone.querySelector('.cancel.button').addEventListener('click', cancelAndReset); editContentZone.querySelector('.ui.cancel.button').addEventListener('click', cancelAndReset);
editContentZone.querySelector('.save.button').addEventListener('click', saveAndRefresh); editContentZone.querySelector('.ui.primary.button').addEventListener('click', saveAndRefresh);
} }
// Show write/preview tab and copy raw content as needed // Show write/preview tab and copy raw content as needed