From 859a537badd6df4355de1c482a594ebe5eaed2b9 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 2 Jun 2016 23:48:45 +0000 Subject: [PATCH] Add some keybindings to switch chat rooms. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3236 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/client.js | 1 + packages/cory/chat/chat.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/core/client.js b/core/client.js index d6e4a102..83bb2ef4 100644 --- a/core/client.js +++ b/core/client.js @@ -184,6 +184,7 @@ function keyEvent(event) { keyCode: event.keyCode, charCode: event.charCode, character: String.fromCharCode(event.keyCode || event.which), + altKey: event.altKey, }); } diff --git a/packages/cory/chat/chat.js b/packages/cory/chat/chat.js index 77c9f1be..259c3747 100644 --- a/packages/cory/chat/chat.js +++ b/packages/cory/chat/chat.js @@ -42,6 +42,27 @@ function setWindow(accountId, conversation) { updateWindows(); } +function cycleConversation(delta) { + let allConversations = []; + let index = -1; + for (let i in gSessions) { + for (let j in gSessions[i].conversations) { + if (gCurrentConversation == gSessions[i].conversations[j]) { + index = allConversations.length; + } + allConversations.push([i, j]); + } + } + index += delta; + while (index < 0) { + index += allConversations.length; + } + while (index >= allConversations.length) { + index -= allConversations.length; + } + setWindow(allConversations[index][0], allConversations[index][1]); +} + function addAccount() { return database.get(kAccountsKey).then(function(data) { let accounts = data ? JSON.parse(data) : []; @@ -425,6 +446,19 @@ core.register("blur", function() { gFocus = false; }); +core.register("key", function(event) { + if (event.type == "keydown") { + if (event.altKey) { + if (event.character == "I") { + cycleConversation(-1); + } else if (event.character == "K") { + cycleConversation(1); + } + } + } +}); +terminal.setSendKeyEvents(true); + // Connect all accounts on start. Promise.all([database.get(kAccountsKey), database.get(kStateKey)]).then(function(results) { let accounts = results[0] ? JSON.parse(results[0]) : [];