Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

keyboard shortcuts to move a tab left or right #11313

Merged
merged 1 commit into from
Oct 31, 2017

Conversation

petemill
Copy link
Member

@petemill petemill commented Oct 6, 2017

Fixes #11310

I created this PR as a precursor to some tab enhancements I'm working on with regard to sorting animation and realtime sorting operations during dragging. Following from this PR, which adds the command to change the sort order, I'll be able to submit the PR to add animation to the operation. These same shortcuts are present in other browsers by default (Firefox on all platforms, and Chrome on linux).

Keyboard shortcuts are:

  • ctrl-shift-pageup : moves the current tab right, and the next tab left (swaps)
  • ctrl-shift-pagedown: moves the current tab left, and the previous tab right (swaps)

Note that if you're on a mac keyboard with no pageup or pagedown keys, those are accessed via fn-up or fn-down. So the shortcuts become ctrl-shift-fn-up and ctrl-shift-fn-down

Auditors:
@bsclifton
@cezaraugusto

Would be great to hear from you guys if the way this is architected is best practice. Thoughts I've had:

  • I'm not often a fan of mixing reducers with side-effect causing action dispatching, but I don't see an alternative architecture present at the moment
  • I'm not 100% clear yet on the signature an action needs in order to be passed to and reduced by the correct window, dispatch-able from both the browser process (from the keyboard shortcut) and the renderer process (from the web driven tests) - but after a bit or trial and error the way it is here works.

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.

Test Plan:

auto

  • Run the automated tests for this feature with npm run test -- --bail --grep="tab order index change"

manual

With one tab, one window

  • Open a single window with a single tab
  • Observe that ctrl-shift-pageup and ctrl-shift-pagedown do nothing

With multiple tabs, one window

  • Open many more tabs
  • Observe that when a tab is active, ctrl-shift-pagedown moves the tab forward, as long as it is not the last tab
  • Observe that when a tab is active, ctrl-shift-pageup moves the tab backwards, as long as it is not the first tab

With multiple tabs, two windows

  • Open two windows
  • Open multiple tabs in each window
  • Activate a tab in one window
  • Observe that moving the tab using ctrl-shift-pagedown or ctrl-shift-pageup does not affect any tabs in the second window

With pinned tabs

  • Open multiple tabs
  • Pin some of those tabs
  • Observe that moving the unpinned tabs does not move the tabs to the pinned area
  • Observe that moving the pinned tabs does not move the tabs to the unpinned area

With multiple tab pages

  • Open enough tabs to split in to multiple tab pages
  • Activate a tab on the first page
  • Observe that pressing ctrl-shift-pagedown enough times will move the tab to the second page

Reviewer Checklist:

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

@codecov-io
Copy link

codecov-io commented Oct 6, 2017

Codecov Report

Merging #11313 into master will decrease coverage by 0.06%.
The diff coverage is 10.71%.

@@            Coverage Diff             @@
##           master   #11313      +/-   ##
==========================================
- Coverage    52.6%   52.54%   -0.07%     
==========================================
  Files         268      268              
  Lines       25237    25273      +36     
  Branches     4024     4031       +7     
==========================================
+ Hits        13277    13280       +3     
- Misses      11960    11993      +33
Flag Coverage Δ
#unittest 52.54% <10.71%> (-0.07%) ⬇️
Impacted Files Coverage Δ
js/constants/windowConstants.js 100% <ø> (ø) ⬆️
js/actions/windowActions.js 4.85% <0%> (-0.05%) ⬇️
app/localShortcuts.js 20.68% <11.11%> (-3.76%) ⬇️
js/stores/windowStore.js 27.01% <11.76%> (-0.57%) ⬇️

@luixxiul
Copy link
Contributor

luixxiul commented Oct 6, 2017

Thanks for providing the nice test plan (also automated tests code)!

If automated tests should cover every possible scenarios, would you please add QA/no-qa-needed to #11310? Thanks!

@luixxiul luixxiul added the needs-info Another team member needs information from the PR/issue opener. label Oct 6, 2017
electronLocalshortcut.register(win, 'Ctrl+Shift+PageDown', () => {
const win = BrowserWindow.getFocusedWindow()
if (win) {
windowActions.tabMoveIncrementalRequested(win.id, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if moveNext defaults to true I think we can skip the second argument

const sourceFrame = frameStateUtil.getActiveFrame(windowState)
const isPinned = sourceFrame.get('pinnedLocation')
const framesCanMoveWithin = isPinned ? frameStateUtil.getPinnedFrames(windowState) : frameStateUtil.getNonPinnedFrames(windowState)
const frameGroupIdx = framesCanMoveWithin.indexOf(sourceFrame)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd prefer the verbose name w/ frameGroupIndex instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for other similar named constants

@@ -7,7 +7,9 @@ module.exports = {
activeTab: '[data-test-active-tab]',
activeTabTitle: '[data-test-active-tab] [data-test-id="tabTitle"]',
activeTabFavicon: '[data-test-active-tab] [data-test-favicon]',
pinnedTabs: '.pinnedTabs',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make use of data attr instead? something like data-pinned-tab. We're trying to avoid tests w/ CSS selectors so Aphrodite changes could less likely break tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure - I had just copied what was there originally but makes sense to make the positive changes now

pinnedTabsTabs: '.pinnedTabs [data-test-id="tab"]',
tabs: '.tabs',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

@cezaraugusto cezaraugusto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unable to test on macOS, left some comments

@cezaraugusto
Copy link
Contributor

@petemill is this supposed to work on mac? if not please put OS specific labels. I guess not, given ctrl+pageUp conflicts w/ another system shortcut but please specify which should.

@petemill
Copy link
Member Author

@cezaraugusto definitely for macOS. Works for me with ctrl+shift+pageup (did you miss the shift?)

@petemill
Copy link
Member Author

@cezaraugusto addressed your feedback, rebased on master, and pushed replacement commit

@cezaraugusto cezaraugusto added PR/pending-review and removed needs-info Another team member needs information from the PR/issue opener. labels Oct 14, 2017
…order up or down one position.

Fix brave#11310

Keyboard shortcut is ctrl-shift-pageup and ctrl-shift-pagedown

Auditors:
@bsclifton
@cezaraugusto
@luixxiul luixxiul added this to the Backlog milestone Oct 26, 2017
@petemill petemill changed the title keyboard shortcuts to change a tab's display order up or down keyboard shortcuts to move a tab left or right Oct 28, 2017
Copy link
Contributor

@cezaraugusto cezaraugusto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Please just prefer using appConstants instead of windowConstants and move the windowAction to the appAction as well as we're moving in that direction. Please update tests too to reflect that.

I'm going to approve, once you make the changes please merge. great job!

@petemill
Copy link
Member Author

@cezaraugusto changes you ask for cause the tests to fail as the window reducer never receives the action. I assume the problem is that the appStore won't forward the action to the window, since the action came from a window in the first place, and is targetted to one specific window? My assumption is because it works fine in the app, where the action is dispatched from the browser process, but in the tests, the action is dispatched from the window process using devTools('appActions'). Perhaps we can wait for the fuller refactor that has the appStore access to window state before trying to hack this in to work? Otherwise I can look at it again with clearer eyes.

@alexwykoff alexwykoff modified the milestones: Backlog, 0.21.x (Developer Channel) Oct 31, 2017
@cezaraugusto cezaraugusto merged commit ec3074a into brave:master Oct 31, 2017
cezaraugusto added a commit that referenced this pull request Oct 31, 2017
keyboard shortcuts to move a tab left or right
@cezaraugusto
Copy link
Contributor

master ec3074a
0.21.x bfd9145

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants