diff --git a/richtextfx/src/test/java/org/fxmisc/richtext/ParagraphTest.java b/richtextfx/src/test/java/org/fxmisc/richtext/ParagraphTest.java new file mode 100644 index 000000000..85cd6fe81 --- /dev/null +++ b/richtextfx/src/test/java/org/fxmisc/richtext/ParagraphTest.java @@ -0,0 +1,22 @@ +package org.fxmisc.richtext; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ParagraphTest { + + // Tests that when concatenating two paragraphs, + // the style of the first one is used for the result. + // This relates to merging text changes and issue #216. + @Test + public void concatEmptyParagraphsTest() { + Paragraph p1 = new Paragraph<>(null, "", true); + Paragraph p2 = new Paragraph<>(null, "", false); + + Paragraph p = p1.concat(p2); + + assertEquals(Boolean.TRUE, p.getStyleAtPosition(0)); + } + +} diff --git a/richtextfx/src/test/java/org/fxmisc/richtext/StyledTextAreaModelTest.java b/richtextfx/src/test/java/org/fxmisc/richtext/StyledTextAreaModelTest.java index 15ae1a127..867f9e2a8 100644 --- a/richtextfx/src/test/java/org/fxmisc/richtext/StyledTextAreaModelTest.java +++ b/richtextfx/src/test/java/org/fxmisc/richtext/StyledTextAreaModelTest.java @@ -1,13 +1,12 @@ package org.fxmisc.richtext; import static org.junit.Assert.*; -import javafx.embed.swing.JFXPanel; - -import org.junit.Test; import java.util.Collection; import java.util.Collections; +import org.junit.Test; + public class StyledTextAreaModelTest { @Test @@ -28,4 +27,25 @@ public void testUndoWithWinNewlines() { assertEquals("abc\ndef", model.getText()); } + @Test + public void testForBug216() { + // set up area with some styled text content + boolean initialStyle = false; + StyledTextAreaModel model = new StyledTextAreaModel<>( + initialStyle, "", new EditableStyledDocument<>(initialStyle, ""), true); + model.replaceText("testtest"); + model.setStyle(0, 8, true); + + // add a space styled by initialStyle + model.setUseInitialStyleForInsertion(true); + model.insertText(4, " "); + + // add another space + model.insertText(5, " "); + + // testing that undo/redo don't throw an exception + model.undo(); + model.redo(); + } + }