mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-05 18:27:17 +01:00
SPIGOT-3568: Fix single letter pagination edge case
By: md_5 <git@md-5.net>
This commit is contained in:
parent
663dce96c5
commit
28dfa926fd
2 changed files with 17 additions and 6 deletions
|
@ -93,7 +93,10 @@ public class ChatPaginator {
|
|||
for (String partialWord : word.toString().split("(?<=\\G.{" + lineLength + "})")) {
|
||||
lines.add(partialWord);
|
||||
}
|
||||
} else if (line.length() + word.length() - lineColorChars == lineLength) { // Line exactly the correct length...newline
|
||||
} else if (line.length() + 1 + word.length() - lineColorChars == lineLength) { // Line exactly the correct length...newline
|
||||
if (line.length() > 0) {
|
||||
line.append(' ');
|
||||
}
|
||||
line.append(word);
|
||||
lines.add(line.toString());
|
||||
line = new StringBuilder();
|
||||
|
|
|
@ -7,14 +7,12 @@ import static org.hamcrest.CoreMatchers.is;
|
|||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ChatPaginatorTest {
|
||||
@Test
|
||||
public void testWordWrap1() {
|
||||
String rawString = ChatColor.RED + "123456789 123456789 123456789";
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is(ChatColor.RED + "123456789 123456789"));
|
||||
assertThat(lines[1], is(ChatColor.RED.toString() + "123456789"));
|
||||
|
@ -128,12 +126,22 @@ public class ChatPaginatorTest {
|
|||
assertThat(lines.length, is(1));
|
||||
assertThat(lines[0], is(ChatColor.RED + "a a a " + ChatColor.BLUE + "a a"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWordWrap12() {
|
||||
String rawString = "123 1 123";
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 5);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123 1"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPaginate1() {
|
||||
String rawString = "1234 123456789 123456789 123456789";
|
||||
ChatPaginator.ChatPage page = ChatPaginator.paginate(rawString, 1, 6, 2);
|
||||
|
||||
|
||||
assertThat(page.getPageNumber(), is(1));
|
||||
assertThat(page.getTotalPages(), is(4));
|
||||
assertThat(page.getLines().length, is(2));
|
||||
|
|
Loading…
Reference in a new issue