Skip to content

Commit 0654ea9

Browse files
committed
Add configuration
1 parent bc95d48 commit 0654ea9

File tree

4 files changed

+148
-67
lines changed

4 files changed

+148
-67
lines changed

README.md

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# hyper-pane
2-
Extension for Hyper.app to enhance pane navigation.
2+
Extension for Hyper.app to enhance pane navigation. Navigate through panes with arrows or jump directly to a specific pane with digit.
33

44
![hyper-pane](https://cloud.githubusercontent.com/assets/4137761/22717106/844a9c5c-ed99-11e6-8e88-8c71a8cbbd5a.gif)
55

@@ -15,19 +15,54 @@ plugins: [
1515
],
1616
```
1717

18+
## Configuration
19+
20+
Default configuration:
21+
``` js
22+
module.exports = {
23+
config: {
24+
// other configs...
25+
paneNavigation: {
26+
debug: false,
27+
hotkeys: {
28+
navigation: {
29+
up: 'ctrl+alt+up',
30+
down: 'ctrl+alt+down',
31+
left: 'ctrl+alt+left',
32+
right: 'ctrl+alt+right'
33+
},
34+
jump_prefix: 'ctrl+alt', // completed with 1-9 digits
35+
permutation_modifier: 'shift', // Added to jump and navigation hotkeys for pane permutation
36+
},
37+
showIndicators: true, // Show pane number
38+
indicatorPrefix: '^⌥', // Will be completed with pane number
39+
indicatorStyle: { // Added to indicator <div>
40+
position: 'absolute',
41+
top: 0,
42+
left: 0,
43+
fontSize: '10px'
44+
},
45+
}
46+
}
47+
//...
48+
};
49+
```
50+
51+
1852
## Usage
1953
### Navigation with arrows
2054

21-
You can use `Ctrl+Alt+<Up,Down,Left,Right>` to navigate to a neighbor pane.
55+
Use `Ctrl+Alt+<Up,Down,Left,Right>` (or your configured hotkeys) to navigate to a neighbor pane.
2256

23-
### Navigation with digit
57+
### Jump with digit
2458

25-
You can use `Ctrl+Alt+<1-9>` to jump to a numbered pane.
26-
Panes are ordered "first child descendent" but `9` is reserved to the last pane.
59+
Use `Ctrl+Alt+<1-9>` (or your configured hotkeys) to jump directly to a numbered pane.
60+
Panes are ordered "first child descendent" and `9` is reserved to the last pane.
2761

28-
Shortcuts are displayed on top left corner of each pane from 2 panes opened.
62+
Hotkey indicators are displayed on top left corner of each pane from 2 panes opened.
63+
You can change its content, its style or hide them completly.
2964

30-
### Switching/Moving pane
65+
### Pane permutation
3166

32-
Adding `Shift` key to previous shortcuts cause a pane switching.
67+
Adding `Shift` key (or your configured key) to previous hotkeys cause a pane switching.
3368

index.js

Lines changed: 98 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
11
const Mousetrap = require('mousetrap');
2+
const merge = require('lodash.merge');
3+
4+
const defaultConfig = {
5+
debug: false,
6+
hotkeys: {
7+
navigation: {
8+
up: 'ctrl+alt+up',
9+
down: 'ctrl+alt+down',
10+
left: 'ctrl+alt+left',
11+
right: 'ctrl+alt+right'
12+
},
13+
jump_prefix: 'ctrl+alt',
14+
permutation_modifier: 'shift',
15+
},
16+
showIndicators: true,
17+
indicatorPrefix: '^⌥',
18+
indicatorStyle: {
19+
position: 'absolute',
20+
top: 0,
21+
left: 0,
22+
fontSize: '10px'
23+
},
24+
};
225

3-
let debug_enabled_ = false;
26+
let config = defaultConfig;
427

528
const debug = function () {
6-
if (debug_enabled_){
29+
if (config.debug){
730
[].unshift.call(arguments, '|HYPER-PANE|');
831
console.log.apply(this, arguments);
932
}
10-
}
33+
};
1134

1235
/**
1336
* Duplicate Hyper code
@@ -73,15 +96,12 @@ const UI_MOVE_LEFT_PANE = 'UI_MOVE_LEFT_PANE';
7396
const UI_MOVE_RIGHT_PANE = 'UI_MOVE_RIGHT_PANE';
7497
const UI_SWITCH_SESSIONS = 'UI_SWITCH_SESSIONS';
7598

76-
// Keys
77-
const JUMP_KEYS = 'ctrl+alt';
78-
const SWITCH_MODIFIER = 'shift';
79-
const NAV_KEYS = {
80-
UI_MOVE_UP_PANE: 'ctrl+alt+up',
81-
UI_MOVE_DOWN_PANE: 'ctrl+alt+down',
82-
UI_MOVE_LEFT_PANE: 'ctrl+alt+left',
83-
UI_MOVE_RIGHT_PANE: 'ctrl+alt+right'
84-
};
99+
const navigationActionMap = {
100+
up: 'UI_MOVE_UP_PANE',
101+
down: 'UI_MOVE_DOWN_PANE',
102+
left: 'UI_MOVE_LEFT_PANE',
103+
right: 'UI_MOVE_RIGHT_PANE'
104+
}
85105

86106
// Others
87107
const ROOT_FRAME = {
@@ -274,6 +294,18 @@ const updateChildrenFrames = (state, groupUid) => {
274294
* Plugin bindings
275295
*/
276296

297+
exports.middleware = store => next => action => {
298+
switch (action.type) {
299+
case 'CONFIG_LOAD':
300+
case 'CONFIG_RELOAD':
301+
if (action.config.paneNavigation) {
302+
config = merge(JSON.parse(JSON.stringify(defaultConfig)), action.config.paneNavigation);
303+
}
304+
break;
305+
}
306+
return next(action);
307+
}
308+
277309
exports.reduceTermGroups = (state, action) => {
278310

279311
switch (action.type) {
@@ -385,47 +417,58 @@ exports.decorateTerms = (Terms, { React, notify, Notification }) => {
385417
const document = term.getTermDocument();
386418
const keys = new Mousetrap(document);
387419

388-
['1','2','3','4','5','6','7','8','9'].forEach(num => {
389-
let shortcut = JUMP_KEYS + `+${num}`;
390-
//debug('Add shortcut', shortcut);
391-
keys.bind(
392-
shortcut,
393-
(e) => {
394-
this.props.onMoveToPane(num);
395-
e.preventDefault();
396-
this.reattachKeyListner();
397-
}
398-
);
399-
shortcut = `${SWITCH_MODIFIER} + ${shortcut}`;
400-
//debug('Add shortcut', shortcut);
401-
keys.bind(
402-
shortcut,
403-
(e) => {
404-
this.props.onMoveToPane(num, true);
405-
e.preventDefault();
406-
this.reattachKeyListner();
420+
const jump_prefix = config.hotkeys.jump_prefix;
421+
const permutation_modifier = config.hotkeys.permutation_modifier;
422+
if (jump_prefix && jump_prefix.length) {
423+
['1','2','3','4','5','6','7','8','9'].forEach(num => {
424+
let shortcut = jump_prefix+ `+${num}`;
425+
//debug('Add shortcut', shortcut);
426+
keys.bind(
427+
shortcut,
428+
(e) => {
429+
this.props.onMoveToPane(num);
430+
e.preventDefault();
431+
this.reattachKeyListner();
432+
}
433+
);
434+
if (permutation_modifier && permutation_modifier.length) {
435+
shortcut = `${permutation_modifier} + ${shortcut}`;
436+
//debug('Add shortcut', shortcut);
437+
keys.bind(
438+
shortcut,
439+
(e) => {
440+
this.props.onMoveToPane(num, true);
441+
e.preventDefault();
442+
this.reattachKeyListner();
443+
}
444+
);
407445
}
408-
);
409-
});
446+
});
447+
}
410448

411-
Object.keys(NAV_KEYS).forEach(direction => {
412-
keys.bind(
413-
NAV_KEYS[direction],
414-
(e) => {
415-
this.props.onMoveToDirectionPane(direction);
416-
e.preventDefault();
417-
this.reattachKeyListner();
418-
}
419-
);
420-
421-
keys.bind(
422-
`${SWITCH_MODIFIER}+` + NAV_KEYS[direction],
423-
(e) => {
424-
this.props.onMoveToDirectionPane(direction, true);
425-
e.preventDefault();
426-
this.reattachKeyListner();
449+
Object.keys(config.hotkeys.navigation).forEach(direction => {
450+
const key = config.hotkeys.navigation[direction];
451+
const actionType = navigationActionMap[direction];
452+
if (key && key.length && actionType && actionType.length) {
453+
keys.bind(
454+
key,
455+
(e) => {
456+
this.props.onMoveToDirectionPane(actionType);
457+
e.preventDefault();
458+
this.reattachKeyListner();
459+
}
460+
);
461+
if (permutation_modifier && permutation_modifier.length) {
462+
keys.bind(
463+
`${permutation_modifier}+` + key,
464+
(e) => {
465+
this.props.onMoveToDirectionPane(actionType, true);
466+
e.preventDefault();
467+
this.reattachKeyListner();
468+
}
469+
);
427470
}
428-
);
471+
}
429472
});
430473
this.keys = keys;
431474
}
@@ -460,17 +503,15 @@ exports.decorateTerm = (Term, { React, notify }) => {
460503
super(props, context);
461504
}
462505
render () {
506+
if (!config.showIndicators) {
507+
return React.createElement(Term, this.props);
508+
}
463509
const myCustomChildrenBefore = React.createElement(
464510
'div',
465511
{
466-
style: {
467-
position: 'absolute',
468-
top: 0,
469-
left: 0,
470-
fontSize: '10px'
471-
}
512+
style: config.indicatorStyle
472513
},
473-
this.props.termShorcutNum > 0 ? '^⌥' + this.props.termShorcutNum : ''
514+
this.props.termShorcutNum > 0 ? config.indicatorPrefix + this.props.termShorcutNum : ''
474515
);
475516
const customChildrenBefore = this.props.customChildrenBefore
476517
? Array.from(this.props.customChildrenBefore).concat(myCustomChildrenBefore)

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "hyper-pane",
3-
"version": "0.1.2",
4-
"description": "Extension for Hyper.app to enhance pane navigation.",
3+
"version": "1.0.0",
4+
"description": "Extension for Hyper.app to enhance pane navigation. Navigate through panes with arrows or jump directly to a specific pane with digit.",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
@@ -47,6 +47,7 @@
4747
]
4848
},
4949
"dependencies": {
50+
"lodash.merge": "^4.6.0",
5051
"mousetrap": "^1.6.0"
5152
}
5253
}

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# yarn lockfile v1
33

44

5+
lodash.merge@^4.6.0:
6+
version "4.6.0"
7+
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.0.tgz#69884ba144ac33fe699737a6086deffadd0f89c5"
8+
59
mousetrap@^1.6.0:
610
version "1.6.0"
711
resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.0.tgz#0168fcabb11d07669e87490324c981208121ac4d"

0 commit comments

Comments
 (0)