Add some keybindings to switch chat rooms.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3236 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2016-06-02 23:48:45 +00:00
parent be18e46a17
commit 859a537bad
2 changed files with 35 additions and 0 deletions

View File

@ -184,6 +184,7 @@ function keyEvent(event) {
keyCode: event.keyCode,
charCode: event.charCode,
character: String.fromCharCode(event.keyCode || event.which),
altKey: event.altKey,
});
}

View File

@ -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]) : [];