Skip to content

Commit 9dcd7e3

Browse files
committed
Tab switch by number
1 parent 82262d3 commit 9dcd7e3

File tree

11 files changed

+95
-41
lines changed

11 files changed

+95
-41
lines changed

app/accelerators.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const applicationMenu = { // app/menu.js
4848
rightPane: 'Alt+Right',
4949
topPane: 'Alt+Up',
5050
bottomPane: 'Alt+Down',
51-
nextTab: 'Shift+[',
52-
previousTab: 'Shift+]'
51+
nextTab: 'Shift+]',
52+
prevTab: 'Shift+['
5353
};
5454

5555
const mousetrap = { // lib/containers/hyper.js

app/menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ module.exports = ({createWindow, updatePlugins}) => {
284284
submenu: [
285285
{
286286
label: 'Previous Tab',
287-
accelerator: accelerators.previousTab,
287+
accelerator: accelerators.prevTab,
288288
click(item, focusedWindow) {
289289
if (focusedWindow) {
290290
focusedWindow.rpc.emit('mv', {type: 'Tab', arrow: 'Left'});

lib/UI/hyper.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ import Component from './component';
44
import Header from './head/header';
55

66
class Hyper extends Component {
7+
constructor(props) {
8+
super(props);
9+
this.handleKeyDown = this.handleKeyDown.bind(this);
10+
this.tabChange = props.tabChange;
11+
}
12+
13+
handleKeyDown(ev) {
14+
const num = parseInt(ev.key, 10);
15+
if (ev.metaKey && Number.isInteger(num)) {
16+
if (num > 0) {
17+
this.tabChange(num);
18+
}
19+
}
20+
}
21+
22+
componentWillMount() {
23+
window.addEventListener('keydown', this.handleKeyDown);
24+
}
25+
726
componentWillReceiveProps(next) {
827
if (this.props.backgroundColor !== next.backgroundColor) {
928
// this can be removed when `setBackgroundColor` in electron

lib/UI/main/term.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ class Term extends Component {
1717
this.xt.onArrow = props.onArrow;
1818
// this.xt.focus = props.onSelect.bind(null, props.uid);
1919
}
20-
2120

2221
onKey(key, ev) {
23-
if(isAccelerator(ev)) {
22+
if (isAccelerator(ev)) {
2423
return false;
2524
}
2625
rpc.emit('data', {uid: this.uid, data: key});
@@ -43,13 +42,12 @@ class Term extends Component {
4342
this.xt.writeln('Welcome to xterm.js');
4443
this.xt.writeln('Just type some keys in the prompt below.');
4544
this.xt.writeln('');
46-
this.xt.attachCustomKeydownHandler(this.onKey);
4745
this.xt.on('key', this.onKey);
48-
this.xt.attachCustomKeydownHandler(function(e){
49-
if(isAccelerator(e)) {
46+
this.xt.attachCustomKeydownHandler(e => {
47+
if (isAccelerator(e)) {
5048
return false;
5149
}
52-
})
50+
});
5351
}
5452

5553
componentDidMount() {
@@ -59,21 +57,21 @@ class Term extends Component {
5957
window.addEventListener('resize', this._SizeListener);
6058
}
6159

62-
componentWillReceiveProps(next) {
63-
// if (next.activeTerm) {
64-
// this.focus();
65-
// this.xt.textarea.focus();
66-
// }
67-
// this._SizeListener();
68-
}
60+
// componentWillReceiveProps(next) {
61+
// // if (next.activeTerm) {
62+
// // this.focus();
63+
// // this.xt.textarea.focus();
64+
// // }
65+
// // this._SizeListener();
66+
// }
6967

7068
template(css) {
7169
const {activeTerm} = this.props;
7270
return (<div
73-
ref={c => {
74-
this.terminal = c;
75-
}
71+
ref={t => {
72+
this.terminal = t;
7673
}
74+
}
7775
className={css('terminal', activeTerm && 'activeTerm')}
7876
/>);
7977
}

lib/communication/actions/tab.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ export function directionalSwitch(arrow) {
2929
});
3030
};
3131
}
32+
33+
export function tabChange(num) {
34+
return dispatch => {
35+
dispatch({
36+
type: 'TAB_SWITCH',
37+
num
38+
});
39+
};
40+
}

lib/connector/hyper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {connect} from '../utils/plugins';
22
import Hyper from '../UI/hyper';
3+
import {tabChange} from '../communication/actions/tab';
34

45
const isMac = /Mac/.test(navigator.userAgent);
56

@@ -14,7 +15,11 @@ const HyperConnector = connect(
1415
};
1516
},
1617
dispatch => {
17-
return {};
18+
return {
19+
tabChange(num) {
20+
dispatch(tabChange(num));
21+
}
22+
};
1823
},
1924
null,
2025
{withRef: true}

lib/reducers/conditions/pane.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {request, split, select, arrow, close, renum} from '../objects/pane';
1+
import {request, split, select, swith, close, renum} from '../objects/pane';
22

33
const conditions = (state, action) => {
44
switch (action.type) {
@@ -15,7 +15,7 @@ const conditions = (state, action) => {
1515
case 'PANE_CREATED':
1616
return state;
1717
case 'PANE_SWITCH':
18-
return arrow(state, action);
18+
return swith(state, action);
1919
default:
2020
return state;
2121
}

lib/reducers/conditions/tab.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {create, select, arrow} from '../objects/tab';
1+
import {create, select, swith} from '../objects/tab';
22

33
const conditions = (state, action) => {
44
switch (action.type) {
@@ -7,7 +7,7 @@ const conditions = (state, action) => {
77
case 'TAB_SELECT':
88
return select(state, action);
99
case 'TAB_SWITCH':
10-
return arrow(state, action);
10+
return swith(state, action);
1111
default:
1212
return state;
1313
}

lib/reducers/objects/Display.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export function right(state, display) {
5555
const pane = state.active.pane;
5656
const indexOf = display.panes.indexOf(pane);
5757
if (indexOf + 1 <= display.panes.length - 1) {
58-
console.log('hello');
5958
return setActive(state, display.panes[indexOf + 1]);
6059
}
6160
// return state;

lib/reducers/objects/pane.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export function close(state, action) {
172172
}));
173173
}
174174

175-
export function arrow(state, action) {
175+
export function swith(state, action) {
176176
const display = state.displays[state.active.display];
177177
switch (action.arrow) {
178178
case 'Left':

0 commit comments

Comments
 (0)