From: Kohei Yoshino Date: Fri, 11 Jan 2019 02:17:01 +0000 (-0500) Subject: Bug 1518328 - The edit comment feature should have a preview mode as well X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7c89e954e6211426bc1b161f89288bf82342fa9d;p=thirdparty%2Fbugzilla.git Bug 1518328 - The edit comment feature should have a preview mode as well --- diff --git a/extensions/EditComments/template/en/default/hook/global/header-start.html.tmpl b/extensions/EditComments/template/en/default/hook/global/header-start.html.tmpl index 814d3408f..9b8acb246 100644 --- a/extensions/EditComments/template/en/default/hook/global/header-start.html.tmpl +++ b/extensions/EditComments/template/en/default/hook/global/header-start.html.tmpl @@ -16,10 +16,13 @@ js_BUGZILLA.string.InlineCommentEditor = { cancel => 'Cancel', cancel_tooltip => 'Discard the changes', + edit => 'Edit', edited => 'Edited', fetch_error => 'Raw comment could not be loaded. Please try again later.', hide_revision => 'Hide This Revision', loading => 'Loading…', + preview => 'Preview', + preview_error = 'Preview could not be loaded. Please try again later.', revision_count => [ '%d revision', '%d revisions' ], save => 'Update Comment', save_error => 'Updated comment could not be saved. Please try again later.', diff --git a/extensions/EditComments/web/js/inline-editor.js b/extensions/EditComments/web/js/inline-editor.js index 605ab8ff8..217770e88 100644 --- a/extensions/EditComments/web/js/inline-editor.js +++ b/extensions/EditComments/web/js/inline-editor.js @@ -47,6 +47,9 @@ Bugzilla.InlineCommentEditor = class InlineCommentEditor { this.$body = $change_set.querySelector('.comment-text'); this.$edit_button.addEventListener('click', event => this.edit_button_onclick(event)); + + // Check if the comment is written in Markdown + this.is_markdown = this.$body.matches('[data-ismarkdown="true"]'); } /** @@ -71,7 +74,7 @@ Bugzilla.InlineCommentEditor = class InlineCommentEditor { } /** - * Called whenever the Edit button is clicked. + * Called whenever the Edit button is clicked. Hide the current comment and insert the inline comment editor instead. * @param {MouseEvent} event Click event. */ edit_button_onclick(event) { @@ -80,38 +83,61 @@ Bugzilla.InlineCommentEditor = class InlineCommentEditor { this.toggle_toolbar_buttons(true); this.$body.hidden = true; + // Determine the preview area's HTML tag name: `
` for Markdown comments or `
` for plaintext
+    const preview_tag = this.is_markdown ? 'div' : 'pre';
+
     // Replace the comment body with a disabled ``);
-    this.$textarea = this.$body.nextElementSibling;
-    this.$textarea.style.height = `${this.$textarea.scrollHeight}px`;
-
-    // Insert a toolbar that provides the Save and Cancel buttons as well as the Hide This Revision checkbox for admin
-    this.$textarea.insertAdjacentHTML('afterend',
       `
-