Make alt+up/down change rooms

This commit is contained in:
David Baker 2015-06-25 17:41:55 +01:00
parent fae629ea65
commit dd0d6159ce

View File

@ -37,10 +37,12 @@ module.exports = {
this.startMatrixClient(); this.startMatrixClient();
} }
this.focusComposer = false; this.focusComposer = false;
document.addEventListener("keydown", this.onKeyDown);
}, },
componentWillUnmount: function() { componentWillUnmount: function() {
dis.unregister(this.dispatcherRef); dis.unregister(this.dispatcherRef);
document.removeEventListener("keydown", this.onKeyDown);
}, },
componentDidUpdate: function() { componentDidUpdate: function() {
@ -51,6 +53,8 @@ module.exports = {
}, },
onAction: function(payload) { onAction: function(payload) {
var roomIndexDelta = 1;
switch (payload.action) { switch (payload.action) {
case 'logout': case 'logout':
this.setState({ this.setState({
@ -66,6 +70,22 @@ module.exports = {
}); });
this.focusComposer = true; this.focusComposer = true;
break; break;
case 'view_prev_room':
roomIndexDelta = -1;
case 'view_next_room':
var allRooms = mxCliPeg.get().getRooms();
var roomIndex = -1;
for (var i = 0; i < allRooms.length; ++i) {
if (allRooms[i].roomId == this.state.currentRoom) {
roomIndex = i;
break;
}
}
roomIndex = (roomIndex + roomIndexDelta) % allRooms.length;
this.setState({
currentRoom: allRooms[roomIndex].roomId
});
break;
} }
}, },
@ -87,5 +107,20 @@ module.exports = {
}); });
cli.startClient(); cli.startClient();
}, },
onKeyDown: function(ev) {
if (ev.altKey) {
switch (ev.keyCode) {
case 38:
dis.dispatch({action: 'view_prev_room'});
ev.stopPropagation();
break;
case 40:
dis.dispatch({action: 'view_next_room'});
ev.stopPropagation();
break;
}
}
}
}; };