No method to use to jump back & forth between search results

Which product are you using?
pdfjs-express

PDF.js Express Version
8.4.0

Detailed description of issue
We are trying to create an event listener on the search panel, on keydown we will be binding [↑], [↓] to navigate search results, but there is no where documented how to navigate to the previous and next search result.

Expected behaviour
Expected to have methods that navigate to the previous and next search result, just like the arrows in the search panel.
Screenshot 2023-02-27 at 10.48.00

Does your issue happen with every document, or just one?
all

Link to document

Code snippet

Hi there,

Thanks for reaching out to pdf.js express forums,

You would be calling the ‘searchText’ method again to get to the next result:

Additionally, these are the hotkeys we have available:
https://pdfjs.express/api/UI.Hotkeys.html

Best regards,
Kevin Kim

Thank you Kim for your response, but it is a bit not clear, could you provide a piece of code that I could use/inject in mine?

Much appreciated,
Ons.

Hey there,

You could remove the ‘arrow down’ event key via ‘off’ method:

instance.UI.hotkeys.off(instance.UI.hotkeys.Keys.DOWN);

Then add a new event for that hotkey with ‘on’:

instance.UI.hotkeys.on('DOWN', e => {
    const searchValue = 'your_search_text'

    instance.UI.searchText(searchValue, {
        // ...options // see the API reference for options
    })
});

Best regards,
Kevin Kim

This is only for the arrow down I assume, what about arrow up? (going to the previous search result)

Hi there,

It looks like we do not have a specific method to go back to previous search result.

We do however have the API textSearchInit:
https://pdfjs.express/api/Core.DocumentViewer.html#textSearchInit
From there, you can add an option for the searchMode:
https://pdfjs.express/api/Core.Search.html

The other method that could work is to create an event to click the UI button:

var element = document.querySelector('[aria-label="Previous result"]');
element.click()

Best regards,
Kevin Kim