fonol / anki-search-inside-add-card

An add-on providing full-text-search and PDF reading functionality to Anki's Add card dialog
https://ankiweb.net/shared/info/1781298089
GNU Affero General Public License v3.0
178 stars 24 forks source link

Feature request: Scroll to next/previous page (code provided) #326

Open kvn1351 opened 2 years ago

kvn1351 commented 2 years ago

I was thinking that instead of dealing with a render implementation to show a continuous stream of pages. Most of us would be perfectly happy with vertical scrolling I suppose. At least I would. This way you wouldn't have to rewrite so much code.

I've quickly hacked together this working prototype.

const debounce = function (fn, d) {
    let timer;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(() => {
            fn.apply(context, args);
        }, d);
    }
};

const pdfView = document.getElementById('siac-pdf-overflow');

const onWheelLogic = function () {

    if (myDiv.offsetHeight + pdfView.scrollTop >= pdfView.scrollHeight) {
        pdfPageRight();
    }
    if (!pdfView.scrollTop) {
        pdfPageLeft();
        // This is terrible ofc. Should be integrated into pdfPageLeft instead of using a timeout.
        setTimeout(() => {
            pdfView.scrollTop = pdfView.scrollHeight;
        }, 100);
    }
};

pdfView.addEventListener('wheel', debounce(onWheelLogic, 200));
Benjamin-Watson0 commented 1 year ago

Indeed, this proposal is crucial, and I need it, too.