forked from cory/tildefriends
		
	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:
		| @@ -184,6 +184,7 @@ function keyEvent(event) { | |||||||
| 		keyCode: event.keyCode, | 		keyCode: event.keyCode, | ||||||
| 		charCode: event.charCode, | 		charCode: event.charCode, | ||||||
| 		character: String.fromCharCode(event.keyCode || event.which), | 		character: String.fromCharCode(event.keyCode || event.which), | ||||||
|  | 		altKey: event.altKey, | ||||||
|  |  | ||||||
| 	}); | 	}); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -42,6 +42,27 @@ function setWindow(accountId, conversation) { | |||||||
| 	updateWindows(); | 	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() { | function addAccount() { | ||||||
| 	return database.get(kAccountsKey).then(function(data) { | 	return database.get(kAccountsKey).then(function(data) { | ||||||
| 		let accounts = data ? JSON.parse(data) : []; | 		let accounts = data ? JSON.parse(data) : []; | ||||||
| @@ -425,6 +446,19 @@ core.register("blur", function() { | |||||||
| 	gFocus = false; | 	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. | // Connect all accounts on start. | ||||||
| Promise.all([database.get(kAccountsKey), database.get(kStateKey)]).then(function(results) { | Promise.all([database.get(kAccountsKey), database.get(kStateKey)]).then(function(results) { | ||||||
| 	let accounts = results[0] ? JSON.parse(results[0]) : []; | 	let accounts = results[0] ? JSON.parse(results[0]) : []; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user