src/main/java/de/unixwork/uwproj/Feature.java

changeset 98
4bf47ea3fc64
parent 97
1af1bfacd25a
child 113
24f32dbd88cd
--- a/src/main/java/de/unixwork/uwproj/Feature.java	Fri Jan 19 20:48:26 2024 +0100
+++ b/src/main/java/de/unixwork/uwproj/Feature.java	Fri Jan 19 21:03:34 2024 +0100
@@ -144,7 +144,6 @@
         // Prepare the description by replacing some unwanted spaces
         final var hdesc = desc.trim()
                 .replaceAll("\\r", "")
-                .replaceAll("\\n", " ")
                 .replaceAll("\\t", "  ");
 
         // Declare our frame where the description shall be placed
@@ -165,6 +164,9 @@
             // get the next word and see where we would end
             int s = hdesc.indexOf(' ', i);
             if (s < 0) s = hdesc.length();
+            int n = hdesc.indexOf('\n', i);
+            if (n < 0) n = hdesc.length();
+            s = Math.min(s, n);
             int l = s-i;
             if (x + l > endx) {
                 // does not fit, break into next line
@@ -177,11 +179,27 @@
             x += l;
             i += l;
             // append the next spaces
-            while (i < hdesc.length() && hdesc.charAt(i) == ' ') {
-                i++;
-                x++;
-                // as long as we don't need to break, add the spaces
-                if (x < endx) builder.append(' ');
+            while (i < hdesc.length()) {
+                int c = hdesc.charAt(i);
+                if (c == ' ') {
+                    // as long as we don't need to break, add the spaces
+                    i++;
+                    x++;
+                    if (x < endx) builder.append(' ');
+                } else if (c == '\n') {
+                    // if user wants us to break, comply
+                    i++;
+                    // if we have still space, just move to the end of the line
+                    if (x < endx) {
+                        x = endx;
+                    } else {
+                        // otherwise, we need to add an extra blank line
+                        builder.append('\n');
+                    }
+                } else {
+                    // we have found the next word, so continue with the outer loop
+                    break;
+                }
             }
             // break to new line, when spaces moved us outside the frame
             if (x > endx) {

mercurial