diff --git a/rta/pom.xml b/rta/pom.xml
index 56ea257..2c98889 100644
--- a/rta/pom.xml
+++ b/rta/pom.xml
@@ -144,6 +144,12 @@
false
--add-opens javafx.graphics/com.sun.javafx.application=ALL-UNNAMED
+
+
+ java.util.logging.config.file
+ src/test/resources/logging.properties
+
+
diff --git a/rta/src/main/java/com/gluonhq/richtextarea/RichListCell.java b/rta/src/main/java/com/gluonhq/richtextarea/RichListCell.java
index 774a0d9..8751ec9 100644
--- a/rta/src/main/java/com/gluonhq/richtextarea/RichListCell.java
+++ b/rta/src/main/java/com/gluonhq/richtextarea/RichListCell.java
@@ -253,7 +253,7 @@ private Text buildText(String content, TextDecoration decoration) {
return lfText;
}
Objects.requireNonNull(decoration);
- Text text = new Text(Objects.requireNonNull(content));
+ Text text = new Text(Objects.requireNonNull(content).replace("\n", ""));
String foreground = decoration.getForeground();
text.setFill(COLOR_MAP.computeIfAbsent(foreground, s -> parseColorOrDefault(foreground, Color.BLACK)));
text.setStrikethrough(decoration.isStrikethrough());
diff --git a/rta/src/main/java/com/gluonhq/richtextarea/model/UnitBuffer.java b/rta/src/main/java/com/gluonhq/richtextarea/model/UnitBuffer.java
index ab539eb..ad2dc40 100644
--- a/rta/src/main/java/com/gluonhq/richtextarea/model/UnitBuffer.java
+++ b/rta/src/main/java/com/gluonhq/richtextarea/model/UnitBuffer.java
@@ -51,8 +51,14 @@
*/
public class UnitBuffer {
+ /**
+ * The block pattern is defined by
+ * \ufeff, a @ or a # symbol, any text (any combination of letters, numbers, punctuation and spaces), and a final \ufeff
+ * For example:
+ * {@code \ufeff@name foo33!\ufeff} has group 0: {@code @}, and group 1: {@code name foo33!}
+ */
private static final Pattern BLOCK_PATTERN = Pattern.compile(
- TextBuffer.ZERO_WIDTH_NO_BREAK_SPACE_TEXT + "(@|#)([\\p{L}|\\p{N}|\\s]*)" + TextBuffer.ZERO_WIDTH_NO_BREAK_SPACE_TEXT,
+ TextBuffer.ZERO_WIDTH_NO_BREAK_SPACE_TEXT + "([@#])([\\p{L}\\p{N}\\p{P}\\s]*)" + TextBuffer.ZERO_WIDTH_NO_BREAK_SPACE_TEXT,
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
private final List unitList;
diff --git a/rta/src/main/java/com/gluonhq/richtextarea/viewmodel/RichTextAreaViewModel.java b/rta/src/main/java/com/gluonhq/richtextarea/viewmodel/RichTextAreaViewModel.java
index 5c52c95..aa3e911 100644
--- a/rta/src/main/java/com/gluonhq/richtextarea/viewmodel/RichTextAreaViewModel.java
+++ b/rta/src/main/java/com/gluonhq/richtextarea/viewmodel/RichTextAreaViewModel.java
@@ -755,7 +755,8 @@ private void updateProperties() {
private Document getCurrentDocument(Selection selection) {
// text and indices should be based on the exportable text
- int caret = getTextBuffer().getText(0, getCaretPosition()).length();
+ int caretPosition = getCaretPosition() < 0 ? getTextLength() : getCaretPosition();
+ int caret = getTextBuffer().getText(0, caretPosition).length();
int start = selection.isDefined() ? selection.getStart() : 0;
int end = selection.isDefined() ? selection.getEnd() : getTextLength();
return new Document(getTextBuffer().getText(start, end), getTextBuffer().getDecorationModelList(start, end), caret);
diff --git a/rta/src/test/java/com/gluonhq/richtextarea/ui/RTATest.java b/rta/src/test/java/com/gluonhq/richtextarea/ui/RTATest.java
index 483a70b..5ce9dc7 100644
--- a/rta/src/test/java/com/gluonhq/richtextarea/ui/RTATest.java
+++ b/rta/src/test/java/com/gluonhq/richtextarea/ui/RTATest.java
@@ -49,6 +49,7 @@
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
+import javafx.scene.text.TextFlow;
import javafx.stage.Stage;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -88,6 +89,7 @@
import static javafx.scene.text.FontWeight.BOLD;
import static javafx.scene.text.FontWeight.NORMAL;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -827,6 +829,40 @@ public void copyPaste3Test(FxRobot robot) {
assertEquals(NORMAL, ((TextDecoration) dm4.getDecoration()).getFontWeight());
assertEquals("black", ((TextDecoration) dm4.getDecoration()).getForeground());
}
+ @Test
+ public void multiLineDocumentTest(FxRobot robot) {
+ run(() -> {
+ String text = "Hello\nRTA";
+ TextDecoration textDecoration = TextDecoration.builder().presets().fontFamily("Arial").build();
+ ParagraphDecoration paragraphDecoration = ParagraphDecoration.builder().presets().build();
+ Document document = new Document(text,
+ List.of(new DecorationModel(0, 6, textDecoration, paragraphDecoration),
+ new DecorationModel(6, 3, textDecoration, paragraphDecoration)), text.length());
+ richTextArea.getActionFactory().open(document).execute(new ActionEvent());
+ });
+ waitForFxEvents();
+
+ verifyThat(".rich-text-area", node -> node instanceof RichTextArea);
+ verifyThat(".rich-text-area", NodeMatchers.isFocused());
+ RichTextArea rta = robot.lookup(".rich-text-area").query();
+ assertEquals(9, rta.getTextLength());
+ assertEquals(9, rta.getCaretPosition());
+ assertNotNull(rta.getDocument());
+ assertEquals(9, rta.getDocument().getCaretPosition());
+ assertEquals("Hello\nRTA", rta.getDocument().getText());
+ String internalText = "Hello\nRTA";
+ assertEquals(9, internalText.length());
+ assertEquals(internalText, getInternalText(rta.getDocument(), 9));
+ assertEquals(2, robot.lookup(".text-flow").queryAll().size());
+ for (int i = 0; i < 2; i++) {
+ assertInstanceOf(TextFlow.class, robot.lookup(".text-flow").nth(i).query());
+ TextFlow tf = robot.lookup(".text-flow").nth(i).query();
+ assertEquals(1, tf.getChildren().size());
+ assertInstanceOf(Text.class, tf.getChildren().get(0));
+ assertFalse(((Text) tf.getChildren().get(0)).getText().contains("\n"));
+ }
+ sleep(4, TimeUnit.SECONDS);
+ }
@Test
public void findASCIIEmojiTest(FxRobot robot) {
diff --git a/rta/src/test/resources/logging.properties b/rta/src/test/resources/logging.properties
new file mode 100644
index 0000000..51f7e75
--- /dev/null
+++ b/rta/src/test/resources/logging.properties
@@ -0,0 +1,9 @@
+handlers = java.util.logging.ConsoleHandler
+.level = INFO
+
+java.util.logging.ConsoleHandler.level = FINEST
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+com.gluonhq.richtextarea.model.level = INFO
+com.gluonhq.richtextarea.undo.level = INFO
+com.gluonhq.richtextarea.viewmodel.level = INFO
diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/FullFeaturedDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/FullFeaturedDemo.java
index a699815..76ffadd 100644
--- a/samples/src/main/java/com/gluonhq/richtextarea/samples/FullFeaturedDemo.java
+++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/FullFeaturedDemo.java
@@ -166,7 +166,7 @@ public class FullFeaturedDemo extends Application {
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).\n" +
"Where does\u200bit\u200bcome\u200bfrom?\u200b\u200b\n" +
"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.\n" +
- "The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from \"de Finibus Bonorum et Malorum\" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.\n",
+ "The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from \"de Finibus Bonorum et Malorum\" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
decorations, 2314);
private final Label textLengthLabel = new Label();