gabalafou
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    January 19, 2023 # Tab roadblocks and other keyboard enemies in the notebook widget For the last few weeks, I have been trying to fix the [keyboard trap](https://www.w3.org/TR/WCAG21/#no-keyboard-trap) (what I've been calling a tab roadblock) in JupyterLab notebook cells. You might be wondering: but I can get out of a code cell editor by pressing the escape key, so why is it a tab trap? The way the notebook extension works, when you press the escape key, it focuses the notebook widget's node, which essentially moves you backwards on the page. That's why I call them tab roadblocks rather than tab traps. It's not exactly a trap because you can get out of it using only the keyboard, but you can't move past it, so it's like a roadblock.[^first] I can't seem to come up with a solution for the notebook cell tab roadblock that doesn't have some serious drawback or another. Perhaps I should start with how I would like keyboard-only interaction with the notebook to behave. 1. A user moves to different cells in the notebook with the up and down arrow keys or with 'J' and 'K', not with tab or shift+tab. - Current behavior: Same, but user can get into code cells by pressing the tab key. 2. Whenever any interactive element inside of the notebook has received focus, whether it is a cell, the expand/collapse button, a button on a cell toolbar, a link, a diagram, or an ipywidget, all notebook keyboard shortcuts (such as 'J' and 'K') should still work, **unless the key is handled by that focussed element**. For example, when the user is typing within a code cell, we do not want 'J' or 'K' to move the user to a different cell , but if the user has focussed on a link in the notebook, then I think it makes sense that a 'J' or 'K' should move them to the cell below or above. - Current behavior: most of the keyboard shortcuts only work when the notebook widget node has focus, [selector = ".jp-Notebook:focus"](https://github.com/jupyterlab/jupyterlab/blob/master/packages/notebook-extension/schema/tracker.json#L372). So for example, if you tab-focus onto a button in a cell's hover toolbar and then press 'J' or 'K', nothing happens. 3. Whenever the user moves the active cell cursor, the document focus should also move. This is to help blind and other non-sighted users who cannot rely on the visual indicator (which is currently a blue vertical bar, sometimes orange) to know which cell is active. - Current behavior: document/browser focus does not move with the active cell cursor. Typically, focus alternates between the cell editor (edit mode) and the whole notebook node (command mode). 4. Exactly one cell wrapper in the notebook should always be tab-focusable. Note that I wrote cell wrapper to distinguish from the cell editor. I do not want the editor inside of the cell to be tab-focusable because that would (re)introduce a tab roadblock. In order to move inside of a cell editor, the user should press the enter key. To exit, they press the escape key. This allows the user to leave the notebook via the tab key and then return to the same cell via the tab key. This helps to put non-sighted users on a par with sighted users for being able to return to where they left off in the notebook. - Current behavior: the only elements in the notebook that are tab-focusable are interactive elements that are tab-focusable by default: buttons, content-editable divs, input elements, and the like. So what has been keeping me so far from building this experience? The main issue that I've run into is trying to solve for #2. The notebook keyboard shortcuts are currently specified in [packages/notebook-extension/schema/tracker.json](https://github.com/jupyterlab/jupyterlab/blob/master/packages/notebook-extension/schema/tracker.json). These keyboard shortcuts [get processed on the capture phase](https://github.com/jupyterlab/lumino/blob/main/packages/application/src/index.ts#L580) of the keydown event, as opposed to the bubbling phase. This makes it hard for me to write code within the JupyterLab app that, for example, prevents the keyboard shortcut from executing if the event happens within some kind of text input element—because by the time the runtime gets to my code (if it gets to my code, either in the bubbling phase, or later in the capture phase of the event), the keyboard shortcut has already been handled. Now, you might be thinking, well the notebook already has two modes (command and edit) which are [reflected in the DOM as classes](https://github.com/jupyterlab/jupyterlab/blob/master/packages/notebook/src/widget.ts#L63) (`jp-mod-commandMode` and `jp-mod-editMode`), so I should be able to simply hook into those in the shortcuts definition file, like so: ``` { "command": "notebook:move-cursor-down", "keys": ["J"], "selector": ".jp-Notebook.jp-mod-commandMode" } ``` The problem is that a notebook cell's output area can contain almost anything. For example, if you put ``` import pdb; pdb.set_trace() ``` in a cell and run it, you will get dropped into a text input ([wrapped by the Stdin class](https://github.com/jupyterlab/jupyterlab/blob/master/packages/outputarea/src/widget.ts#L909)), but the notebook does not switch from command to edit mode. So the selector will apply, and pressing 'J' will move you to the next cell rather than put the letter 'j' into the text input. We could consider moving these shortcuts out of the JSON file and into the Notebook class for more fine-grained control, but I think that would make it difficult to override the shortcuts via settings, am I correct? If you're familiar with Lumino, you might be thinking about adding the [data-lm-suppress-shortcuts](https://github.com/jupyterlab/lumino/blob/main/packages/commands/src/index.ts#L1599) attribute to the output area. That would solve most of the issues. But it would also mean that while the user is focussed on any element inside the output area, none of the notebook keyboard shortcuts will work. For example, if the output area contains a link and the user tabs to that link and then presses the down arrow key, nothing will happen. Which means that the UX will diverge between links in rendered markdown versus links in code cell output. This discrepancy could create confusion for the user. They might think it's a bug: why would keyboard shortcuts like 'J' and 'K' work when focussed on one link in the notebook but not when focussed on another? I have a sneaking sense that there may be some obvious solution staring me in the face, but I can't see it because I'm looking in the wrong place. I dunno. I'm curious to get other people's thoughts and insights. [^first]: You might be thinking: but I can move out of the code cell by pressing the down arrow key, so is it _really_ a keyboard trap? I would argue yes, because even though you can get all the way down to the last code cell in the notebook, you can't actually get past the end of the notebook to the next focusable part of the JupyterLab UI. There is only one way that I've found, using only the keyboard, to get to focusable elements that come after a notebook. And that is to shift-tab backwards until you reach the beginning of the UI and then wrap back around to the end and work your way backwards until you get back to the end of the notebook. But that is such a convoluted workaround, I don't think it would be fair to use it as a way to argue that code cells are not a keyboard trap.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully