From fe073f3bd7513542fcb3b2637f000bd6eee163a3 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Sat, 23 Nov 2013 07:52:55 +0100 Subject: [PATCH] Ensure line breaks are kept when replying to a multi line comment Add a leading space to each quoted line to ensure that line breaks are kept. If the existing line breaks are kept it can happen that some lines get very long (e.g. if a whole paragraph was typed without an explicit line break). To avoid this long lines are automatically wrapped. Change-Id: I397e10f68908d85049abeb0e64cc923736f060bf Signed-off-by: Edwin Kempin --- .../google/gerrit/client/change/ReplyBox.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ReplyBox.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ReplyBox.java index c870dbf02e..cba285548a 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ReplyBox.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ReplyBox.java @@ -193,7 +193,24 @@ class ReplyBox extends Composite { m = m.substring(i + 1).trim(); } } - return "> " + m.replaceAll("\\n", "\\\n> "); + StringBuilder quotedMsg = new StringBuilder(); + for (String line : m.split("\\n")) { + line = line.trim(); + while (line.length() > 67) { + int i = line.lastIndexOf(' ', 67); + if (i < 50) { + i = line.indexOf(' ', 67); + } + if (i > 0) { + quotedMsg.append(" > ").append(line.substring(0, i)).append("\n"); + line = line.substring(i + 1); + } else { + break; + } + } + quotedMsg.append(" > ").append(line).append("\n"); + } + return quotedMsg.toString().substring(0, quotedMsg.length() - 1); // remove last '\n' } private void hide() {