Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #696 #697

Merged
merged 2 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public Paragraph<PS, SEG, S> restyle(int from, int to, S style) {

public Paragraph<PS, SEG, S> restyle(int from, StyleSpans<? extends S> styleSpans) {
int len = styleSpans.length();
if(styleSpans.equals(getStyleSpans(from, from + len))) {
if(styleSpans.equals(getStyleSpans(from, from + len)) || styleSpans.getSpanCount() == 0) {
return this;
}
if(length() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static org.junit.Assert.*;

import java.util.Collection;
import java.util.Collections;

import org.junit.Test;

public class ParagraphTest {
Expand Down Expand Up @@ -37,4 +40,26 @@ public void restylingEmptyParagraphViaStyleSpansWorks() {
assertTrue(restyledP.getStyleSpans().styleStream().allMatch( b -> b ));
}

// Relates to #696 (caused by #685, coming from #449) where an empty
// StyleSpans being applied to an empty paragraph results in an Exception
@Test
public void restylingEmptyParagraphViaEmptyStyleSpansWorks() {

Collection<String> test = Collections.singleton("test");
TextOps<String, Collection<String>> segOps = SegmentOps.styledTextOps();
Paragraph<Void, String, Collection<String>> p = new Paragraph<>(null, segOps, "", test);
assertEquals( 0, p.length() );

StyleSpans<Collection<String>> spans = new StyleSpans<Collection<String>>()
{
@Override public Position position( int major, int minor ) { return null; }
@Override public Position offsetToPosition( int offset, Bias bias ) { return null; }
@Override public StyleSpan<Collection<String>> getStyleSpan( int index ) { return null; }
@Override public int getSpanCount() { return 0; }
@Override public int length() { return 0; }
};

Paragraph<Void, String, Collection<String>> restyledP = p.restyle(0, spans);
assertEquals( test, restyledP.getStyleSpans().getStyleSpan( 0 ).getStyle() );
}
}