From 3d58c869638980ce89d48b0b017b80a9f6e2312c Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 22 Sep 2019 23:53:29 -0700 Subject: [PATCH] feat: left/right keys can change columns or focus (#1516) * feat: left/right keys can change columns or focus * fixup * fixup, add tests --- src/routes/_components/NavShortcuts.html | 19 +++ src/routes/_components/ShortcutHelpInfo.html | 18 ++- .../dialog/components/MediaDialog.html | 6 +- src/routes/_pages/settings/hotkeys.html | 30 ++++- .../observers/leftRightFocusObservers.js | 114 ++++++++++++++++++ src/routes/_store/observers/observers.js | 2 + src/routes/_store/store.js | 4 +- src/routes/_utils/runMediumPriorityTask.js | 2 +- src/routes/_utils/shortcuts.js | 3 +- src/routes/_utils/userAgent.js | 3 + tests/spec/024-shortcuts-navigation.js | 70 ++++++++++- tests/utils.js | 6 + 12 files changed, 265 insertions(+), 12 deletions(-) create mode 100644 src/routes/_store/observers/leftRightFocusObservers.js create mode 100644 src/routes/_utils/userAgent.js diff --git a/src/routes/_components/NavShortcuts.html b/src/routes/_components/NavShortcuts.html index 0a4ffead..588d4e40 100644 --- a/src/routes/_components/NavShortcuts.html +++ b/src/routes/_components/NavShortcuts.html @@ -8,6 +8,10 @@ +{#if !$leftRightChangesFocus} + + +{/if} {#each $navPages as navPage, i} {/each} @@ -35,6 +39,21 @@ async showComposeDialog () { const showComposeDialog = await importShowComposeDialog() showComposeDialog() + }, + goLeftOrRight (left) { + let { currentPage, navPages } = this.store.get() + if (currentPage === 'notifications/mentions') { // special case + currentPage = 'notifications' + } + const idx = navPages.findIndex(_ => _.name === currentPage) + if (idx === -1) { + return + } + if (left && idx > 0) { + goto(navPages[idx - 1].href) + } else if (!left && idx < navPages.length - 1) { + goto(navPages[idx + 1].href) + } } } } diff --git a/src/routes/_components/ShortcutHelpInfo.html b/src/routes/_components/ShortcutHelpInfo.html index a18d82b2..5f7c7029 100644 --- a/src/routes/_components/ShortcutHelpInfo.html +++ b/src/routes/_components/ShortcutHelpInfo.html @@ -6,8 +6,19 @@ {@html `

Global

+ ${$leftRightChangesFocus ? + ` +
    +
  • to go to the next focusable element
  • +
  • to go to the previous focusable element
  • +
+ ` : ''}
    -
  • 1 - 6 to switch columns
  • +
  • + 1 - 6 + ${$leftRightChangesFocus ? '' : `or /`} + to switch columns +
  • 7 or c to compose a new toot
  • s to search
  • g + h to go home
  • @@ -40,7 +51,7 @@

    Media

      -
    • - to go to next or previous
    • +
    • / to go to next or previous
    `} @@ -83,7 +94,10 @@ }