From 4b0e8f227da63d0a50fafafc618c5e66059379eb Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Sun, 31 Mar 2024 09:19:40 +0500 Subject: [PATCH 1/3] Make display of EasyMDE in UI optional to template This commit adds EasyMDE field to combomarkdowneditor, as well as to all its calls. (cherry picked from commit f5c7ccaeffa7cd5d2f4a7a6b18b8e2c55d5e315e) --- templates/repo/diff/box.tmpl | 1 + templates/repo/diff/comment_form.tmpl | 1 + templates/repo/diff/new_review.tmpl | 1 + templates/repo/issue/comment_tab.tmpl | 1 + templates/repo/issue/fields/textarea.tmpl | 1 + templates/repo/issue/view_content.tmpl | 1 + templates/repo/release/new.tmpl | 1 + templates/repo/wiki/new.tmpl | 1 + templates/shared/combomarkdowneditor.tmpl | 5 ++++- 9 files changed, 12 insertions(+), 1 deletion(-) diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 6b343e4ee0..71ad0f5377 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -241,6 +241,7 @@ "MarkdownPreviewContext" $.RepoLink "TextareaName" "content" "DropzoneParentContainer" ".ui.form" + "EasyMDE" true )}} {{if .IsAttachmentEnabled}}
diff --git a/templates/repo/diff/comment_form.tmpl b/templates/repo/diff/comment_form.tmpl index 856b3da01a..08ef8a4c87 100644 --- a/templates/repo/diff/comment_form.tmpl +++ b/templates/repo/diff/comment_form.tmpl @@ -17,6 +17,7 @@ "TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.comment.placeholder") "DropzoneParentContainer" "form" "DisableAutosize" "true" + "EasyMDE" true )}} {{if $.root.IsAttachmentEnabled}} diff --git a/templates/repo/diff/new_review.tmpl b/templates/repo/diff/new_review.tmpl index a2eae007a5..39e5ebe222 100644 --- a/templates/repo/diff/new_review.tmpl +++ b/templates/repo/diff/new_review.tmpl @@ -21,6 +21,7 @@ "TextareaName" "content" "TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.review.placeholder") "DropzoneParentContainer" "form" + "EasyMDE" true )}}
{{if .IsAttachmentEnabled}} diff --git a/templates/repo/issue/comment_tab.tmpl b/templates/repo/issue/comment_tab.tmpl index 4197ea4f65..29d69a3de1 100644 --- a/templates/repo/issue/comment_tab.tmpl +++ b/templates/repo/issue/comment_tab.tmpl @@ -11,6 +11,7 @@ "TextareaContent" $textareaContent "TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.comment.placeholder") "DropzoneParentContainer" "form, .ui.form" + "EasyMDE" true )}} diff --git a/templates/repo/issue/fields/textarea.tmpl b/templates/repo/issue/fields/textarea.tmpl index 3ad69e1220..b98ac39cfc 100644 --- a/templates/repo/issue/fields/textarea.tmpl +++ b/templates/repo/issue/fields/textarea.tmpl @@ -13,6 +13,7 @@ "TextareaContent" .item.Attributes.value "TextareaPlaceholder" .item.Attributes.placeholder "DropzoneParentContainer" ".combo-editor-dropzone" + "EasyMDE" true )}} {{if .root.IsAttachmentEnabled}} diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index bb8863a170..2c3e72b812 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -151,6 +151,7 @@ "MarkdownPreviewContext" .RepoLink "TextareaName" "content" "DropzoneParentContainer" ".ui.form" + "EasyMDE" true )}} diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl index 425cc2c87a..81104a70d2 100644 --- a/templates/repo/release/new.tmpl +++ b/templates/repo/release/new.tmpl @@ -57,6 +57,7 @@ "TextareaPlaceholder" (ctx.Locale.Tr "repo.release.message") "TextareaAriaLabel" (ctx.Locale.Tr "repo.release.message") "DropzoneParentContainer" "form" + "EasyMDE" true )}} {{range .attachments}} diff --git a/templates/repo/wiki/new.tmpl b/templates/repo/wiki/new.tmpl index 2f51a5fe2e..81433db003 100644 --- a/templates/repo/wiki/new.tmpl +++ b/templates/repo/wiki/new.tmpl @@ -29,6 +29,7 @@ "TextareaPlaceholder" (ctx.Locale.Tr "repo.wiki.page_content") "TextareaAriaLabel" (ctx.Locale.Tr "repo.wiki.page_content") "TextareaContent" $content + "EasyMDE" true )}}
diff --git a/templates/shared/combomarkdowneditor.tmpl b/templates/shared/combomarkdowneditor.tmpl index f4d51f510b..fb11a75bec 100644 --- a/templates/shared/combomarkdowneditor.tmpl +++ b/templates/shared/combomarkdowneditor.tmpl @@ -10,6 +10,7 @@ Template Attributes: * TextareaAriaLabel: aria-label attribute for the textarea * DropzoneParentContainer: container for file upload (leave it empty if no upload) * DisableAutosize: whether to disable automatic height resizing +* EasyMDE: whether to display button for switching to legacy editor */}}
{{if .MarkdownPreviewUrl}} @@ -41,7 +42,9 @@ Template Attributes:
- + {{if .EasyMDE}} + + {{end}}
From 99effab1ebfeccc04972d0226007a5027328de0e Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Sun, 31 Mar 2024 09:31:57 +0500 Subject: [PATCH 2/3] Remove EasyMDE from various areas Ref https://codeberg.org/forgejo/forgejo/issues/2831 Removed from: - form for creating comment - form for updating comment - popup reviewing form - line reviewing form - I did not check the use of textarea.tmpl but I belive its used for issue templates, so also removed - I did not check the use of box.tmpl, could not get any comments on compare EasyMDE is left for these pages: - release notes editor - wiki editor (cherry picked from commit 703aee4cadc4f2179eeadf2ae7965af416eef5fe) --- templates/repo/diff/box.tmpl | 1 - templates/repo/diff/comment_form.tmpl | 1 - templates/repo/diff/new_review.tmpl | 1 - templates/repo/issue/comment_tab.tmpl | 1 - templates/repo/issue/fields/textarea.tmpl | 1 - templates/repo/issue/view_content.tmpl | 1 - 6 files changed, 6 deletions(-) diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 71ad0f5377..6b343e4ee0 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -241,7 +241,6 @@ "MarkdownPreviewContext" $.RepoLink "TextareaName" "content" "DropzoneParentContainer" ".ui.form" - "EasyMDE" true )}} {{if .IsAttachmentEnabled}}
diff --git a/templates/repo/diff/comment_form.tmpl b/templates/repo/diff/comment_form.tmpl index 08ef8a4c87..856b3da01a 100644 --- a/templates/repo/diff/comment_form.tmpl +++ b/templates/repo/diff/comment_form.tmpl @@ -17,7 +17,6 @@ "TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.comment.placeholder") "DropzoneParentContainer" "form" "DisableAutosize" "true" - "EasyMDE" true )}} {{if $.root.IsAttachmentEnabled}} diff --git a/templates/repo/diff/new_review.tmpl b/templates/repo/diff/new_review.tmpl index 39e5ebe222..a2eae007a5 100644 --- a/templates/repo/diff/new_review.tmpl +++ b/templates/repo/diff/new_review.tmpl @@ -21,7 +21,6 @@ "TextareaName" "content" "TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.review.placeholder") "DropzoneParentContainer" "form" - "EasyMDE" true )}}
{{if .IsAttachmentEnabled}} diff --git a/templates/repo/issue/comment_tab.tmpl b/templates/repo/issue/comment_tab.tmpl index 29d69a3de1..4197ea4f65 100644 --- a/templates/repo/issue/comment_tab.tmpl +++ b/templates/repo/issue/comment_tab.tmpl @@ -11,7 +11,6 @@ "TextareaContent" $textareaContent "TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.comment.placeholder") "DropzoneParentContainer" "form, .ui.form" - "EasyMDE" true )}}
diff --git a/templates/repo/issue/fields/textarea.tmpl b/templates/repo/issue/fields/textarea.tmpl index b98ac39cfc..3ad69e1220 100644 --- a/templates/repo/issue/fields/textarea.tmpl +++ b/templates/repo/issue/fields/textarea.tmpl @@ -13,7 +13,6 @@ "TextareaContent" .item.Attributes.value "TextareaPlaceholder" .item.Attributes.placeholder "DropzoneParentContainer" ".combo-editor-dropzone" - "EasyMDE" true )}} {{if .root.IsAttachmentEnabled}} diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 2c3e72b812..bb8863a170 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -151,7 +151,6 @@ "MarkdownPreviewContext" .RepoLink "TextareaName" "content" "DropzoneParentContainer" ".ui.form" - "EasyMDE" true )}} From ae128c617bcb3f29e49d6e4dc7851ca3bde97173 Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Mon, 15 Apr 2024 22:59:26 +0500 Subject: [PATCH 3/3] Add integration test for EasyMDE button (cherry picked from commit 089e37026fdabf03f7a5d52fc869ad775a40d4ac) --- tests/integration/easymde_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/integration/easymde_test.go diff --git a/tests/integration/easymde_test.go b/tests/integration/easymde_test.go new file mode 100644 index 0000000000..c8203d36be --- /dev/null +++ b/tests/integration/easymde_test.go @@ -0,0 +1,25 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package integration + +import ( + "net/http" + "testing" +) + +func TestEasyMDESwitch(t *testing.T) { + session := loginUser(t, "user2") + testEasyMDESwitch(t, session, "user2/glob/issues/1", false) + testEasyMDESwitch(t, session, "user2/glob/issues/new", false) + testEasyMDESwitch(t, session, "user2/glob/wiki?action=_new", true) + testEasyMDESwitch(t, session, "user2/glob/releases/new", true) +} + +func testEasyMDESwitch(t *testing.T, session *TestSession, url string, expected bool) { + t.Helper() + req := NewRequest(t, "GET", url) + resp := session.MakeRequest(t, req, http.StatusOK) + doc := NewHTMLParser(t, resp.Body) + doc.AssertElement(t, ".combo-markdown-editor button.markdown-switch-easymde", expected) +}