From 0773cfbdf539fcc7c1fa7d79c3e036fea6d5d531 Mon Sep 17 00:00:00 2001 From: Sibo Van Gool Date: Fri, 28 Jan 2022 22:52:35 +0100 Subject: [PATCH] Use special HTML newline With the
HTML newline, when a user would want to copy-paste the bug report, it would just be one long string of text, because the
tag would just be replaced by a space instead of a newline. --- .../sf/openrocket/gui/dialogs/BugReportDialog.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java index c3ce4d470..6b1817990 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java @@ -71,7 +71,7 @@ public class BugReportDialog extends JDialog { "gapleft para, split 2, gapright rel"); panel.add(new URLLabel(REPORT_EMAIL_URL, REPORT_EMAIL), "growx, wrap para"); - final JEditorPane editorPane = new JEditorPane("text/html", message.replace("\n", "
")); + final JEditorPane editorPane = new JEditorPane("text/html", formatNewlineHTML(message)); editorPane.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, true); editorPane.setPreferredSize(new Dimension(600, 400)); editorPane.setEditable(true); @@ -241,5 +241,16 @@ public class BugReportDialog extends JDialog { sb.append(l.toString()).append('\n'); } } + + /** + * Replace newline character \n to an HTML newline. Instead of just using a
tag, we replace newlines with a + * paragraph tag with zero margin. This is so that when you copy the HTML text and paste it somewhere, that the + * HTML newlines are also interpreted as newlines in the new text. A
tag would just be replaced by a space. + * @param text text to be formatted + * @return text with HTML newlines + */ + private static String formatNewlineHTML(String text) { + return text.replaceAll("\n(.*?)(?=(\n|$))", "

$1

"); + } }