Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

better handling of new lines + spec

Bruno Pagno83d30a54c304
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
index 647baee3380..3514b958278 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
@@ -623,7 +623,13 @@ export default class IndexController extends Controller {
const userName = target.dataset.userNameParam as string;
const content = target.dataset.contentParam as string;
- this.openEditorWithInitialData(this.quotedText(content, userName));
+ const quotedText = this.quotedText(content, userName);
+ const formVisible = !this.formRowTarget.classList.contains('d-none');
+ if (formVisible) {
+ this.insertQuoteOnExistingEditor(quotedText);
+ } else {
+ this.openEditorWithInitialData(quotedText);
+ }
}
private quotedText(rawComment:string, userName:string) {
@@ -634,6 +640,18 @@ export default class IndexController extends Controller {
return `${userName}\n${quoted}`;
}
+ insertQuoteOnExistingEditor(quotedText:string) {
+ const ckEditorInstance = this.getCkEditorInstance();
+ if (ckEditorInstance) {
+ const editorData = ckEditorInstance.getData({ trim: false });
+ if (editorData.endsWith('<br>') || editorData.endsWith('\n')) {
+ ckEditorInstance.setData(`${editorData}${quotedText}`);
+ } else {
+ ckEditorInstance.setData(`${editorData}\n\n${quotedText}`);
+ }
+ }
+ }
+
openEditorWithInitialData(quotedText:string) {
this.showForm();
const ckEditorInstance = this.getCkEditorInstance();
diff --git a/spec/features/activities/work_package/activities_spec.rb b/spec/features/activities/work_package/activities_spec.rb
index dc6de51035b..2c0ef771d16 100644
--- a/spec/features/activities/work_package/activities_spec.rb
+++ b/spec/features/activities/work_package/activities_spec.rb
@@ -776,7 +776,27 @@ RSpec.describe "Work package activity", :js, :with_cuprite do
activity_tab.quote_comment(first_comment_by_member)
# expect the quoted comment to be shown
- activity_tab.expect_journal_notes(text: "A Member wrote:\nFirst comment by member")
+ activity_tab.ckeditor.expect_value("A Member wrote:\nFirst comment by member")
+ end
+ end
+
+ context "when writing a comment" do
+ current_user { admin }
+
+ before do
+ wp_page.visit!
+ wp_page.wait_for_activity_tab
+ end
+
+ it "can quote other user's comments", :aggregate_failures do
+ # open the editor and type something
+ activity_tab.type_comment("Partial message:")
+
+ # quote other user's comment
+ activity_tab.quote_comment(first_comment_by_member)
+
+ # expect the original comment and quote are shown
+ activity_tab.ckeditor.expect_value("Partial message:\nA Member wrote:\nFirst comment by member")
end
end
end