Skip to content

Commit

Permalink
Fix a bug when appending bytes in Book
Browse files Browse the repository at this point in the history
  • Loading branch information
codedread committed Jun 30, 2024
1 parent 4161f7a commit c15d683
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 55 deletions.
4 changes: 2 additions & 2 deletions code/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ export class Book extends EventTarget {
* @param {ArrayBuffer} appendBuffer
*/
appendBytes(appendBuffer) {
let newBuffer = new Uint8Array(this.#arrayBuffer.length + appendBuffer.length);
let newBuffer = new Uint8Array(this.#arrayBuffer.byteLength + appendBuffer.byteLength);
newBuffer.set(this.#arrayBuffer, 0);
newBuffer.set(appendBuffer, this.#arrayBuffer.length);
newBuffer.set(appendBuffer, this.#arrayBuffer.byteLength);
this.#arrayBuffer = newBuffer;
}

Expand Down
114 changes: 61 additions & 53 deletions code/kthoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,68 +186,76 @@ export class KthoomApp {
this.viewMenu_.addEventListener(MenuEventType.ITEM_SELECTED, evt => {
const id = evt.item.id;
switch (id) {
case 'menu-view-rotate-left':
this.bookViewer_.rotateCounterClockwise();
this.saveSettings_();
closeMainMenu();
case 'menu-view-rotate-left': {
this.bookViewer_.rotateCounterClockwise();
this.saveSettings_();
closeMainMenu();
}
break;
case 'menu-view-rotate-right':
this.bookViewer_.rotateClockwise();
this.saveSettings_();
closeMainMenu();
case 'menu-view-rotate-right': {
this.bookViewer_.rotateClockwise();
this.saveSettings_();
closeMainMenu();
}
break;
case 'menu-view-one-page':
this.bookViewer_.setNumPagesInViewer(1);
this.viewMenu_.setMenuItemSelected('menu-view-one-page', true);
this.viewMenu_.setMenuItemSelected('menu-view-two-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false);
this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false);
this.saveSettings_();
closeMainMenu();
case 'menu-view-one-page': {
this.bookViewer_.setNumPagesInViewer(1);
this.viewMenu_.setMenuItemSelected('menu-view-one-page', true);
this.viewMenu_.setMenuItemSelected('menu-view-two-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false);
this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false);
this.saveSettings_();
closeMainMenu();
}
break;
case 'menu-view-two-page':
this.bookViewer_.setNumPagesInViewer(2);
this.viewMenu_.setMenuItemSelected('menu-view-one-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-two-page', true);
this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false);
this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false);
this.saveSettings_();
closeMainMenu();
case 'menu-view-two-page': {
this.bookViewer_.setNumPagesInViewer(2);
this.viewMenu_.setMenuItemSelected('menu-view-one-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-two-page', true);
this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false);
this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false);
this.saveSettings_();
closeMainMenu();
}
break;
case 'menu-view-long-strip':
this.bookViewer_.setNumPagesInViewer(3);
this.viewMenu_.setMenuItemSelected('menu-view-one-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-two-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-long-strip', true);
this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false);
this.saveSettings_();
closeMainMenu();
case 'menu-view-long-strip': {
this.bookViewer_.setNumPagesInViewer(3);
this.viewMenu_.setMenuItemSelected('menu-view-one-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-two-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-long-strip', true);
this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false);
this.saveSettings_();
closeMainMenu();
}
break;
case 'menu-view-wide-strip':
this.bookViewer_.setNumPagesInViewer(4);
this.viewMenu_.setMenuItemSelected('menu-view-one-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-two-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false);
this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', true);
this.saveSettings_();
closeMainMenu();
case 'menu-view-wide-strip': {
this.bookViewer_.setNumPagesInViewer(4);
this.viewMenu_.setMenuItemSelected('menu-view-one-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-two-page', false);
this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false);
this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', true);
this.saveSettings_();
closeMainMenu();
}
break;
case HIDE_PANEL_BUTTONS_MENU_ITEM:
this.#togglePanelButtons();
closeMainMenu();
case HIDE_PANEL_BUTTONS_MENU_ITEM: {
this.#togglePanelButtons();
closeMainMenu();
}
break;
case 'menu-view-fit-best':
case 'menu-view-fit-height':
case 'menu-view-fit-width':
const fitMode = (id === 'menu-view-fit-best' ? FitMode.Best :
id === 'menu-view-fit-height' ? FitMode.Height :
id === 'menu-view-fit-width' ? FitMode.Width : undefined);
this.bookViewer_.setFitMode(fitMode);
this.viewMenu_.setMenuItemSelected('menu-view-fit-best', fitMode === FitMode.Best);
this.viewMenu_.setMenuItemSelected('menu-view-fit-height', fitMode === FitMode.Height);
this.viewMenu_.setMenuItemSelected('menu-view-fit-width', fitMode === FitMode.Width);
this.saveSettings_();
closeMainMenu();
case 'menu-view-fit-width': {
const fitMode = (id === 'menu-view-fit-best' ? FitMode.Best :
id === 'menu-view-fit-height' ? FitMode.Height :
id === 'menu-view-fit-width' ? FitMode.Width : undefined);
this.bookViewer_.setFitMode(fitMode);
this.viewMenu_.setMenuItemSelected('menu-view-fit-best', fitMode === FitMode.Best);
this.viewMenu_.setMenuItemSelected('menu-view-fit-height', fitMode === FitMode.Height);
this.viewMenu_.setMenuItemSelected('menu-view-fit-width', fitMode === FitMode.Width);
this.saveSettings_();
closeMainMenu();
}
break;
}
});
Expand Down

0 comments on commit c15d683

Please sign in to comment.