diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a829567..e6add69 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,8 +4,12 @@
-
-
+
+
+
+
+
+
@@ -52,7 +56,30 @@
"nodejs_package_manager_path": "npm"
}
}
-
+
+
+
+
+
+
+
+
+
+
+
+ false
+ true
+ false
+
+
@@ -76,6 +103,15 @@
false
+
+
+
+
+
+
+
+
+
@@ -87,6 +123,7 @@
1660688177518
+
1660688283740
@@ -109,7 +146,14 @@
1660735113793
-
+
+ 1660746908828
+
+
+
+ 1660746908828
+
+
@@ -131,6 +175,7 @@
-
+
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 41ed08a..0f57e4f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ plugins {
}
group 'net.william278'
-version '1.0.1'
+version '1.0.2'
repositories {
mavenCentral()
diff --git a/src/main/java/net/william278/paginedown/ListOptions.java b/src/main/java/net/william278/paginedown/ListOptions.java
index 59ca57c..5cbb5b2 100644
--- a/src/main/java/net/william278/paginedown/ListOptions.java
+++ b/src/main/java/net/william278/paginedown/ListOptions.java
@@ -24,7 +24,7 @@ public class ListOptions {
@NotNull
protected String pageJumperGroupSeparator = "…";
@NotNull
- protected String pageJumperCurrentPageFormat = "[%page%](%color%)";
+ protected String pageJumperCurrentPageFormat = "[%current_page%](%color%)";
@NotNull
protected String pageJumperPageFormat = "[%target_page_index%](show_text=&7Jump to page %target_page_index% run_command=/%command% %target_page_index%)";
@NotNull
diff --git a/src/main/java/net/william278/paginedown/PaginatedList.java b/src/main/java/net/william278/paginedown/PaginatedList.java
index 95c4e6a..4e8a336 100644
--- a/src/main/java/net/william278/paginedown/PaginatedList.java
+++ b/src/main/java/net/william278/paginedown/PaginatedList.java
@@ -222,26 +222,7 @@ public class PaginatedList {
}
break;
case "page_jump_buttons": {
- final StringJoiner pageGroups = new StringJoiner(options.pageJumperGroupSeparator);
- StringJoiner pages = new StringJoiner(options.pageJumperPageSeparator);
-
- for (int i = 1; i <= getTotalPages(); i++) {
- int startCutOff = (page <= 3 ? page - 1 : 3);
- int endCutOff = (page > getTotalPages() - 3 ? page + 1 : getTotalPages() - 3);
- if (i == startCutOff + 1 || i == endCutOff) {
- pageGroups.add(pages.toString());
- pages = new StringJoiner(options.pageJumperPageSeparator);
- }
- if ((i <= startCutOff) || (i > endCutOff)) {
- pages.add(formatPageString(formatPageJumper(i), i));
- } else if (i == page) {
- pages.add(formatPageString(options.pageJumperCurrentPageFormat, i));
- }
- }
- if (!pages.toString().isBlank()) {
- pageGroups.add(pages.toString());
- }
- convertedFormat.append(pageGroups);
+ convertedFormat.append(getPageJumperButtons(page));
break;
}
}
@@ -272,4 +253,29 @@ public class PaginatedList {
Integer.toString(page)), page);
}
+ @NotNull
+ protected String getPageJumperButtons(final int page) {
+ final StringJoiner pageGroups = new StringJoiner(options.pageJumperGroupSeparator);
+ StringJoiner pages = new StringJoiner(options.pageJumperPageSeparator);
+ int lastPage = 1;
+ for (int i = 1; i <= getTotalPages(); i++) {
+ if (i < 3 || i > getTotalPages() - 2 || page == i) {
+ if (i - lastPage > 1) {
+ pageGroups.add(pages.toString());
+ pages = new StringJoiner(options.pageJumperPageSeparator);
+ }
+ if (page == i) {
+ pages.add(formatPageString(options.pageJumperCurrentPageFormat, i));
+ } else {
+ pages.add(formatPageString(formatPageJumper(i), i));
+ }
+ lastPage = i;
+ }
+ }
+ if (!pages.toString().isBlank()) {
+ pageGroups.add(pages.toString());
+ }
+ return pageGroups.toString();
+ }
+
}
diff --git a/src/test/java/net/william278/paginedown/PaginatedListTests.java b/src/test/java/net/william278/paginedown/PaginatedListTests.java
index 11f89e2..8ef2aca 100644
--- a/src/test/java/net/william278/paginedown/PaginatedListTests.java
+++ b/src/test/java/net/william278/paginedown/PaginatedListTests.java
@@ -32,4 +32,42 @@ public class PaginatedListTests {
).getTotalPages();
Assertions.assertEquals(4, pageCount);
}
+
+ @Test
+ public void testPageJumperButtonsOnLongList() {
+ final PaginatedList longList = PaginatedList.of(generateListData(200, "Item #"),
+ new ListOptions.Builder()
+ .setItemsPerPage(10)
+ .setPageJumperPageFormat("%target_page_index%")
+ .setPageJumperCurrentPageFormat("%current_page%")
+ .build());
+ Assertions.assertEquals("1|2…19|20", longList.getPageJumperButtons(2));
+ Assertions.assertEquals("1|2…6…19|20", longList.getPageJumperButtons(6));
+ Assertions.assertEquals("1|2…19|20", longList.getPageJumperButtons(20));
+ Assertions.assertEquals("1|2…19|20", longList.getPageJumperButtons(1));
+ }
+
+ @Test
+ public void testPageJumperButtonsOnMediumList() {
+ final PaginatedList mediumList = PaginatedList.of(generateListData(45, "Item #"),
+ new ListOptions.Builder()
+ .setItemsPerPage(10)
+ .setPageJumperPageFormat("%target_page_index%")
+ .setPageJumperCurrentPageFormat("%current_page%")
+ .build());
+ Assertions.assertEquals("1|2…4|5", mediumList.getPageJumperButtons(1));
+ Assertions.assertEquals("1|2|3|4|5", mediumList.getPageJumperButtons(3));
+ Assertions.assertEquals("1|2…4|5", mediumList.getPageJumperButtons(5));
+ }
+
+ @Test
+ public void testPageJumperButtonsOnShortList() {
+ final PaginatedList shortList = PaginatedList.of(generateListData(20, "Item #"),
+ new ListOptions.Builder()
+ .setItemsPerPage(10)
+ .setPageJumperPageFormat("%target_page_index%")
+ .setPageJumperCurrentPageFormat("%current_page%")
+ .build());
+ Assertions.assertEquals("1|2", shortList.getPageJumperButtons(2));
+ }
}