From c4d089053af16931c66ab0f392f887a44004dd8c Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Wed, 21 Feb 2024 20:56:31 -0500 Subject: [PATCH] Fixes for viewer paginator --- src/common/Paginator.svelte | 27 ++++++++-------------- src/pages/viewer/controls/Paginator.svelte | 2 +- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/common/Paginator.svelte b/src/common/Paginator.svelte index 85c8ba859..a191dc619 100644 --- a/src/common/Paginator.svelte +++ b/src/common/Paginator.svelte @@ -17,12 +17,8 @@ const dispatch = createEventDispatcher(); let input: HTMLInputElement; - let inputValue: number = page; - $: inputWidth = String(inputValue ?? 0).length; - $: invalidValue = inputValue > totalPages || !inputValue; - $: { - inputValue = page; - } + $: inputWidth = String(page ?? 0).length; + $: invalidValue = page > totalPages || !page; export function previous() { dispatch("previous"); @@ -36,13 +32,11 @@ dispatch("goTo", page); } - function handleChange() { - if (invalidValue || inputValue === page) { - inputValue = page; - return; - } - console.log(inputValue); - goTo(inputValue); + function handleChange(event: Event) { + if (invalidValue) return; + console.debug("Paginator: Page changed to ", page); + const { value } = event.target as HTMLInputElement; + goTo(parseInt(value)); } function handleKeyup({ key }: KeyboardEvent) { @@ -53,10 +47,7 @@ input.blur(); break; // case "Enter": - // if (invalidValue) { - // inputValue = page; - // } else if (inputValue !== page) { - // goTo(inputValue); + // goTo(page); // } // input.blur(); // break; @@ -104,7 +95,7 @@ min="1" max={totalPages} bind:this={input} - bind:value={inputValue} + bind:value={page} on:change={handleChange} on:keyup={handleKeyup} style={`width: ${inputWidth}ch`} diff --git a/src/pages/viewer/controls/Paginator.svelte b/src/pages/viewer/controls/Paginator.svelte index b02837482..5238a437f 100644 --- a/src/pages/viewer/controls/Paginator.svelte +++ b/src/pages/viewer/controls/Paginator.svelte @@ -19,7 +19,7 @@ {#if $viewer.loaded && $doc.mode !== "search" && $doc.mode !== "notes" && $doc.mode !== "thumbnail"}