Skip to content

Commit

Permalink
0.4.7
Browse files Browse the repository at this point in the history
Closes #55, #56
- Changed previous tab command behavior: When the search input is active, going to the previous tab selects the last tab instead
- Improved key-handling for common system shortcuts:
  + <kbd>Shift</kbd>-<kbd>Tab</kbd> now goes to the previous item in the tab list
  + <kbd>Home</kbd> and <kbd>End</kbd> jump to the beginning or the ending of the tab list
  + <kbd>PgUp</kbd> and <kbd>PgDown</kbd> go to the previous or next tab in the tab list
  • Loading branch information
reblws committed Mar 30, 2018
2 parents 06a0782 + 42dcdfc commit a2074d2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
- Dark theme
- Vertically centered overlay

## 0.4.7 (2018-03-30)

- Changed previous tab command behavior: When the search input is active, going to the previous tab selects the last tab instead
- Improved key-handling for common system shortcuts:
+ <kbd>Shift</kbd>-<kbd>Tab</kbd> now goes to the previous item in the tab list
+ <kbd>Home</kbd> and <kbd>End</kbd> jump to the beginning or the ending of the tab list
+ <kbd>PgUp</kbd> and <kbd>PgDown</kbd> go to the previous or next tab in the tab list

## 0.4.6 (2018-02-27)

- Added ability to bind a second shortcut
Expand Down
32 changes: 26 additions & 6 deletions src/core/pages/popup/event-callbacks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Main DOM event-handlers */
import keyboard, { TAB_NEXT } from 'core/keyboard';
import keyboard, { TAB_NEXT, TAB_PREV } from 'core/keyboard';
import {
injectTabsInList,
addHeadTabListNodeSelectedStyle,
Expand Down Expand Up @@ -97,6 +97,7 @@ function isModifierSingle(event) {
}

export function keydownHandler(store) {
const navigate = cmdKey => navigateResults(cmdKey, store.getState);
const { keyboard: keyboardControls } = store.getState();
// The keyboard object is an object with the mapping { [ACTION]: kbdcommand }
// Mirror the keys and values so we have a Map:
Expand All @@ -109,8 +110,7 @@ export function keydownHandler(store) {
if (isModifierSingle(event)) {
event.preventDefault();
}
// Handle preventing default
// Delete, Backspace, Tab, ArrowUp, Arrowdown, Enter
// Handle preventing default key actions
switch (event.key) {
case 'Tab':
// // Change it so tab no longer focuses the entire popup window
Expand All @@ -121,17 +121,37 @@ export function keydownHandler(store) {
case 'ArrowUp':
case 'ArrowDown':
case 'Enter':
case 'Home':
case 'End':
case 'PageDown':
case 'PageUp':
event.preventDefault();
break;
default: break;
}
if (keyboard.isValid(event)) {
const cmd = keyboard.command(event);
const key = [...kbdControlMap.keys()].find(x => keyboard.isEqual(x, cmd));
return navigateResults(kbdControlMap.get(key), store.getState);
return navigate(kbdControlMap.get(key));
}
if (event.key === 'Tab') {
return navigateResults(TAB_NEXT, store.getState);
// Keys that require special behavior
// In the case of 'End' or 'Home' this breaks the behavior of skipping to
// the beginning of the end of the line in the searchInput.
// Maybe we should only focus if the searchInput isn't active?
switch (event.key) {
case 'End':
tabList.lastChild.focus();
break;
case 'Home':
tabList.firstChild.focus();
break;
case 'PageDown':
return navigate(TAB_NEXT);
case 'PageUp':
return navigate(TAB_PREV);
case 'Tab':
return navigate(event.shiftKey ? TAB_PREV : TAB_NEXT);
default: break;
}
const shouldJustFocusSearchBar = (event.key === 'Backspace' && !isModifierSingle(event))
|| (/^([A-Za-z]|\d)$/.test(event.key) && !isModifierSingle(event));
Expand Down
4 changes: 3 additions & 1 deletion src/core/pages/popup/utils/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ export function navigateResults(cmdKey, getState) {
const prevSibling = selectedTab.previousElementSibling;
if (prevSibling) {
prevSibling.focus();
} else {
} else if (document.activeElement !== searchInput) {
searchInput.focus();
} else { // We're at the top but searchInput is focused
tabList.lastChild.focus();
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/manifest/base.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "TabSearch",
"version": "0.4.6",
"version": "0.4.7",
"description": "Easy tab search & switching",
"permissions": [
"tabs",
Expand Down

0 comments on commit a2074d2

Please sign in to comment.