Skip to content

Navigate word lookup in sc-bottom-sheet.js using arrow keys#3345

Open
transducer wants to merge 1 commit into
suttacentral:mainfrom
transducer:main
Open

Navigate word lookup in sc-bottom-sheet.js using arrow keys#3345
transducer wants to merge 1 commit into
suttacentral:mainfrom
transducer:main

Conversation

@transducer
Copy link
Copy Markdown

@transducer transducer commented Dec 28, 2024

For me the approach mentioned under help for navigating the bottom sheet using HTML access keys doesn't work. This PR should maintain the original functionality using HTML access keys and also provide functionality to navigate respectively left or right one word on the pressing of ← and →. I think this is more discoverable.

suttacentralarrows
Goes right one word on pressing right and left one word on pressing left.

updated help display
Updated help display.

Please let me know if this is a desired implementation or not and if I should add a unit test. And if desired maybe a good idea to also add a keydown handler for p (for previous word) and n (for next word)?

Also need to update the translations files found here.

Summary by Sourcery

New Features:

  • Navigate between words in the bottom sheet using left () and right () arrow keys.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Dec 28, 2024

Reviewer's Guide by Sourcery

This PR implements keyboard navigation for word lookup in the bottom sheet using the left and right arrow keys. It also updates the help text to reflect this change. The original access key functionality is preserved.

Sequence diagram for bottom sheet keyboard navigation

sequenceDiagram
    actor User
    participant BS as Bottom Sheet
    participant KH as Keyboard Handler
    participant Nav as Navigation Logic

    User->>BS: Press Arrow Key
    BS->>KH: _handleKeydown(event)
    alt Arrow Left
        KH->>Nav: _handleArrowLeftKeydown()
        Nav->>Nav: _previous()
    else Arrow Right
        KH->>Nav: _handleArrowRightKeydown()
        Nav->>Nav: _next()
    end
    Nav-->>BS: Update current word
    BS-->>User: Display new word
Loading

Class diagram for SCBottomSheet changes

classDiagram
    class SCBottomSheet {
        -Object _keydownHandlers
        +connectedCallback()
        +disconnectedCallback()
        -_handleKeydown(event)
        -_handleArrowLeftKeydown()
        -_handleArrowRightKeydown()
        -_previous()
        -_next()
    }
    note for SCBottomSheet "Added keyboard navigation
handlers for arrow keys"
Loading

File-Level Changes

Change Details Files
Added keyboard navigation using arrow keys.
  • Added _keydownHandlers to handle left and right arrow key presses.
  • Added event listeners for keydown on connectedCallback and removed them on disconnectedCallback.
  • Implemented _handleKeydown to process keydown events.
  • Implemented _handleArrowLeftKeydown and _handleArrowRightKeydown to call existing _previous and _next methods respectively.
  • Imported ignorableKeydownEvent from sc-keyboard-shortcuts to filter out unwanted keydown events.
client/elements/addons/sc-bottom-sheet.js
Updated help text to include arrow keys.
  • Added arrow key labels to the help text for previous and next word navigation.
  • Updated the help text to reflect the addition of arrow keys.
client/elements/addons/sc-bottom-sheet.js
client/localization/elements/interface_en.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

- Keydown handling similarly implemented as sc-top-sheet-view.js
- Update Help text and add to local English translation
@thesunshade
Copy link
Copy Markdown
Collaborator

Interesting. Without your PR, alt n does nothing for me on FF and alt b triggers the browser's bookmark interface. So for sure that needs to be fixed.

Generally we seem to avoid having two ways of doing things, so I doubt Bhante @sujato will want to do arrow keys and alt b/n.

There has also been talk of using the arrow keys for navigating to the previous and next suttas. In fact the browser extension does just that.

Thank you for working on this! Bhante @sujato is traveling atm so it may take a little bit for him to respond.

@transducer
Copy link
Copy Markdown
Author

transducer commented Dec 28, 2024 via email

@thesunshade
Copy link
Copy Markdown
Collaborator

Just as an FYI, here are all the existing hotkeys:
image

@transducer
Copy link
Copy Markdown
Author

transducer commented Dec 29, 2024

Thanks for the hot key reference, these are indeed the same as defined in sc-top-sheet-view.js.

I notice now that actually the backward access key (Alt+b) does work in Firefox, only the forward (Alt+n) does not. The Ctrl+n (in my case the modifier is Ctrl+⌥ Opt) I think conflicts in Firefox with other behaviour. In Chrome it actually does work for me.

Since I don't see access keys used anywhere else in the SuttaCentral applications, they are quite hard to discover and can conflict with other browser behaviour, maybe best to not use access keys and introduce new regular hot keys for navigating the word lookup? But what keys to use if the arrow keys and n (toggle notes view) are already taken? Perhaps just like in vi the h and l keys for going left and right one word, though this is not so discoverable. Or maybe overload the arrows keys that when the sc-bottom-sheet-view.js is open they are used for navigating the word lookup instead of the suttas? (Though I don't think the latter is technically feasible if the capturing of arrow keys comes from an extension, but if the hotkeys are all defined in the main application it should be possible to arrange it like that.)

@jhanarato
Copy link
Copy Markdown
Collaborator

Hey @thesunshade, you commented on this. Do you think it is still relevant or can I close it?

@thesunshade
Copy link
Copy Markdown
Collaborator

No idea! Would be good if it could get resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants