Skip to content

Commit

Permalink
fix: prevent executing insert command when loading empty books (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
wiskiw authored Jan 26, 2025
1 parent 670dc90 commit ce2a8ee
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/main/java/me/chrr/scribble/mixin/BookEditScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,20 +456,15 @@ private void saveTo(Path path) {
private void loadFrom(Path path) {
try {
BookFile bookFile = BookFile.read(path);
Collection<RichText> loadedPages = bookFile.pages().isEmpty()
? List.of(RichText.empty()) // if loaded book has no pages, then create an empty page
: bookFile.pages();

this.richPages.clear();
this.pages.clear();
richPages.clear();
pages.clear();
commandManager.clear();

// Loading an empty book file would set the total amount of pages to 0.
// We work around this by just inserting a new empty page.
if (bookFile.pages().isEmpty()) {
this.currentPage = 0;
this.insertPage();
return;
}

for (RichText page : bookFile.pages()) {
for (RichText page : loadedPages) {
this.richPages.add(page);
this.pages.add(page.getAsFormattedString());
}
Expand Down

0 comments on commit ce2a8ee

Please sign in to comment.