From b99bef09b0f6ed65030c0e7ce86f8ea6dba82d66 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 28 Feb 2023 07:13:52 +0800 Subject: [PATCH 1/2] Change button text for commenting and closing an issue at the same time (#23135) Close #10468 Without SimpleMDE/EasyMDE, using Simple Textarea, the button text could be changed when content changes. After introducing SimpleMDE/EasyMDE, there is no code for updating the button text. --- web_src/js/features/comp/EasyMDE.js | 3 +++ web_src/js/features/repo-legacy.js | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/web_src/js/features/comp/EasyMDE.js b/web_src/js/features/comp/EasyMDE.js index 1f7fe45153cce..d6f0c529e71bc 100644 --- a/web_src/js/features/comp/EasyMDE.js +++ b/web_src/js/features/comp/EasyMDE.js @@ -77,6 +77,9 @@ export async function createCommentEasyMDE(textarea, easyMDEOptions = {}) { const inputField = easyMDE.codemirror.getInputField(); + easyMDE.codemirror.on('change', (...args) => { + easyMDEOptions?.onChange(...args); + }); easyMDE.codemirror.setOption('extraKeys', { 'Cmd-Enter': codeMirrorQuickSubmit, 'Ctrl-Enter': codeMirrorQuickSubmit, diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 2c93ca03424b0..cfb4f16131f1b 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -68,12 +68,18 @@ export function initRepoCommentForm() { } (async () => { + const $statusButton = $('#status-button'); for (const textarea of $commentForm.find('textarea:not(.review-textarea, .no-easymde)')) { // Don't initialize EasyMDE for the dormant #edit-content-form if (textarea.closest('#edit-content-form')) { continue; } - const easyMDE = await createCommentEasyMDE(textarea); + const easyMDE = await createCommentEasyMDE(textarea, { + 'onChange': () => { + const value = easyMDE?.value().trim(); + $statusButton.text($statusButton.attr(value.length === 0 ? 'data-status' : 'data-status-and-comment')); + }, + }); initEasyMDEImagePaste(easyMDE, $commentForm.find('.dropzone')); } })(); From 25808f2d7df0e5f494d3b86c4d8e57b7a5b253fd Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Tue, 28 Feb 2023 13:41:04 +0200 Subject: [PATCH 2/2] Update web_src/js/features/comp/EasyMDE.js Co-authored-by: wxiaoguang --- web_src/js/features/comp/EasyMDE.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/comp/EasyMDE.js b/web_src/js/features/comp/EasyMDE.js index d6f0c529e71bc..6793bd84d57ef 100644 --- a/web_src/js/features/comp/EasyMDE.js +++ b/web_src/js/features/comp/EasyMDE.js @@ -78,7 +78,7 @@ export async function createCommentEasyMDE(textarea, easyMDEOptions = {}) { const inputField = easyMDE.codemirror.getInputField(); easyMDE.codemirror.on('change', (...args) => { - easyMDEOptions?.onChange(...args); + easyMDEOptions?.onChange?.(...args); }); easyMDE.codemirror.setOption('extraKeys', { 'Cmd-Enter': codeMirrorQuickSubmit,