forked from cory/tildefriends
		
	ssb: Alt+up/down to cycle through channels.
This commit is contained in:
		| @@ -1,5 +1,5 @@ | ||||
| { | ||||
| 	"type": "tildefriends-app", | ||||
| 	"emoji": "🐌", | ||||
| 	"previous": "&hWgKPOx3M3T7BufeywObcOCHvsdRfVAoZ9LErkPhJPE=.sha256" | ||||
| 	"previous": "&tkrwd7UkPaWUk9189g3D08N44EjT0AJOlDLw6oMfbpY=.sha256" | ||||
| } | ||||
|   | ||||
| @@ -97,6 +97,36 @@ class TfElement extends LitElement { | ||||
| 		this.channels = Object.keys(channel_map).sort(); | ||||
| 	} | ||||
|  | ||||
| 	connectedCallback() { | ||||
| 		super.connectedCallback(); | ||||
| 		this._keydown = this.keydown.bind(this); | ||||
| 		window.addEventListener('keydown', this._keydown); | ||||
| 	} | ||||
|  | ||||
| 	disconnectedCallback() { | ||||
| 		super.disconnectedCallback(); | ||||
| 		window.removeEventListener('keydown', this._keydown); | ||||
| 	} | ||||
|  | ||||
| 	keydown(event) { | ||||
| 		if (event.altKey && event.key == 'ArrowUp') { | ||||
| 			this.next_channel(1); | ||||
| 			event.preventDefault(); | ||||
| 		} else if (event.altKey && event.key == 'ArrowDown') { | ||||
| 			this.next_channel(-1); | ||||
| 			event.preventDefault(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	next_channel(delta) { | ||||
| 		let channel_names = ['', '@'].concat(this.channels); | ||||
| 		let index = channel_names.indexOf(this.hash.substring(1)); | ||||
| 		if (index != -1) { | ||||
| 			index += delta; | ||||
| 			this.set_hash('#' + encodeURIComponent(channel_names[(index + channel_names.length) % channel_names.length])); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	set_hash(hash) { | ||||
| 		this.hash = decodeURIComponent(hash || '#'); | ||||
| 		if (this.hash.startsWith('#q=')) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user