From dd0d6159ce706140882a5520be8b6d746c469548 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 25 Jun 2015 17:41:55 +0100 Subject: [PATCH] Make alt+up/down change rooms --- src/controllers/pages/MatrixChat.js | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/controllers/pages/MatrixChat.js b/src/controllers/pages/MatrixChat.js index 34c916b3af..d14451dc51 100644 --- a/src/controllers/pages/MatrixChat.js +++ b/src/controllers/pages/MatrixChat.js @@ -37,10 +37,12 @@ module.exports = { this.startMatrixClient(); } this.focusComposer = false; + document.addEventListener("keydown", this.onKeyDown); }, componentWillUnmount: function() { dis.unregister(this.dispatcherRef); + document.removeEventListener("keydown", this.onKeyDown); }, componentDidUpdate: function() { @@ -51,6 +53,8 @@ module.exports = { }, onAction: function(payload) { + var roomIndexDelta = 1; + switch (payload.action) { case 'logout': this.setState({ @@ -66,6 +70,22 @@ module.exports = { }); this.focusComposer = true; 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(); }, + + 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; + } + } + } };