git ssb

16+

Dominic / patchbay



Commit cfe9ce7cf96f4027441c0d3ce54ead220a5018b1

add sweet keyboard message open behaviour

mix irving committed on 4/2/2017, 8:11:10 AM
Parent: 7911b511d193bfabd39ac967aecdc0570f2f452e

Files changed

main/html/scroller.jschanged
main/html/search-bar.jschanged
main/sync/catch-keyboard-shortcut.jschanged
message/html/layout/default.jschanged
main/html/scroller.jsView
@@ -54,6 +54,8 @@
5454 selectChild((!curMsgEl || d === 'first') ? container.firstChild
5555 : d < 0 ? curMsgEl.previousElementSibling || container.firstChild
5656 : d > 0 ? curMsgEl.nextElementSibling || container.lastChild
5757 : curMsgEl)
58+
59+ return curMsgEl
5860 }
5961 }
main/html/search-bar.jsView
@@ -9,11 +9,11 @@
99 'channel.async.suggest': 'first'
1010 })
1111
1212 exports.create = function (api) {
13- return nest('main.html.searchBar', search)
13+ return nest('main.html.searchBar', searchBar)
1414
15- function search (go) {
15+ function searchBar (go) {
1616 const getProfileSuggestions = api.about.async.suggest()
1717 const getChannelSuggestions = api.channel.async.suggest()
1818
1919 const input = h('input', {
main/sync/catch-keyboard-shortcut.jsView
@@ -47,11 +47,11 @@
4747 return tabs.get(tabs.selected[0]).firstChild.scroll(1)
4848 case 75: // k = newer
4949 return tabs.get(tabs.selected[0]).firstChild.scroll(-1)
5050 case 13: // enter = open
51- return goToMessage(ev)
51+ return goToMessage(ev, tabs)
5252 case 79: // o = open
53- return goToMessage(ev)
53+ return goToMessage(ev, tabs)
5454 case 192: // ` = toggle raw message view
5555 return toggleRawMessage(ev)
5656
5757 // Tabs
@@ -84,17 +84,36 @@
8484 return
8585 }
8686 }
8787
88-function goToMessage (ev) {
88+function goToMessage (ev, tabs) {
8989 const msg = ev.target
9090 if (!msg.classList.contains('Message')) return
9191
9292 // this uses a crudely exported nav api
9393 const search = document.querySelector('input[type=search]')
94- search.go(msg.dataset.root)
94+
95+ const { root, key } = msg.dataset
96+ if (!root) return search.go(key)
97+
98+ search.go(root)
99+ scrollDownToMessage(key, tabs)
95100 }
96101
102+function scrollDownToMessage (key, tabs) {
103+ tabs.get(tabs.selected[0]).firstChild.scroll('first')
104+ locateKey()
105+
106+ function locateKey () {
107+ const msg = tabs.get(tabs.selected[0]).firstChild.scroll(1)
108+ if (msg === undefined) return setTimeout(locateKey, 100)
109+
110+ if (msg && msg.dataset && msg.dataset.key === key) return
111+
112+ locateKey ()
113+ }
114+}
115+
97116 function toggleRawMessage (ev) {
98117 const msg = ev.target
99118 if (!msg.classList.contains('Message')) return
100119
message/html/layout/default.jsView
@@ -21,16 +21,16 @@
2121 if (!(opts.layout === undefined || opts.layout === 'default')) return
2222
2323 var rawMessage = Value(null)
2424
25- return h('Message', {
26- attributes: {
27- tabindex: '0', // needed to be able to navigate and show focus()
28- 'data-key': msg.key,
29- 'data-root': msg.value.content.root,
30- 'data-text': msg.value.content.text
31- }
32- }, [
25+ const attributes = {
26+ tabindex: '0', // needed to be able to navigate and show focus()
27+ 'data-key': msg.key,
28+ 'data-text': msg.value.content.text
29+ }
30+ if (msg.value.content.root) attributes['data-root'] = msg.value.content.root
31+
32+ return h('Message', { attributes }, [
3333 h('section.avatar', {}, api.about.html.image(msg.value.author)),
3434 h('section.timestamp', {}, api.message.html.timestamp(msg)),
3535 h('header.author', {}, api.message.html.author(msg)),
3636 h('section.meta', {}, api.message.html.meta(msg, { rawMessage })),

Built with git-ssb-web