Commit cfe9ce7cf96f4027441c0d3ce54ead220a5018b1
add sweet keyboard message open behaviour
mix irving committed on 4/2/2017, 8:11:10 AMParent: 7911b511d193bfabd39ac967aecdc0570f2f452e
Files changed
main/html/scroller.js | changed |
main/html/search-bar.js | changed |
main/sync/catch-keyboard-shortcut.js | changed |
message/html/layout/default.js | changed |
main/html/scroller.js | ||
---|---|---|
@@ -54,6 +54,8 @@ | ||
54 | 54 | selectChild((!curMsgEl || d === 'first') ? container.firstChild |
55 | 55 | : d < 0 ? curMsgEl.previousElementSibling || container.firstChild |
56 | 56 | : d > 0 ? curMsgEl.nextElementSibling || container.lastChild |
57 | 57 | : curMsgEl) |
58 | + | |
59 | + return curMsgEl | |
58 | 60 | } |
59 | 61 | } |
main/html/search-bar.js | ||
---|---|---|
@@ -9,11 +9,11 @@ | ||
9 | 9 | 'channel.async.suggest': 'first' |
10 | 10 | }) |
11 | 11 | |
12 | 12 | exports.create = function (api) { |
13 | - return nest('main.html.searchBar', search) | |
13 | + return nest('main.html.searchBar', searchBar) | |
14 | 14 | |
15 | - function search (go) { | |
15 | + function searchBar (go) { | |
16 | 16 | const getProfileSuggestions = api.about.async.suggest() |
17 | 17 | const getChannelSuggestions = api.channel.async.suggest() |
18 | 18 | |
19 | 19 | const input = h('input', { |
main/sync/catch-keyboard-shortcut.js | ||
---|---|---|
@@ -47,11 +47,11 @@ | ||
47 | 47 | return tabs.get(tabs.selected[0]).firstChild.scroll(1) |
48 | 48 | case 75: // k = newer |
49 | 49 | return tabs.get(tabs.selected[0]).firstChild.scroll(-1) |
50 | 50 | case 13: // enter = open |
51 | - return goToMessage(ev) | |
51 | + return goToMessage(ev, tabs) | |
52 | 52 | case 79: // o = open |
53 | - return goToMessage(ev) | |
53 | + return goToMessage(ev, tabs) | |
54 | 54 | case 192: // ` = toggle raw message view |
55 | 55 | return toggleRawMessage(ev) |
56 | 56 | |
57 | 57 | // Tabs |
@@ -84,17 +84,36 @@ | ||
84 | 84 | return |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | -function goToMessage (ev) { | |
88 | +function goToMessage (ev, tabs) { | |
89 | 89 | const msg = ev.target |
90 | 90 | if (!msg.classList.contains('Message')) return |
91 | 91 | |
92 | 92 | // this uses a crudely exported nav api |
93 | 93 | 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) | |
95 | 100 | } |
96 | 101 | |
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 | + | |
97 | 116 | function toggleRawMessage (ev) { |
98 | 117 | const msg = ev.target |
99 | 118 | if (!msg.classList.contains('Message')) return |
100 | 119 |
message/html/layout/default.js | ||
---|---|---|
@@ -21,16 +21,16 @@ | ||
21 | 21 | if (!(opts.layout === undefined || opts.layout === 'default')) return |
22 | 22 | |
23 | 23 | var rawMessage = Value(null) |
24 | 24 | |
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 }, [ | |
33 | 33 | h('section.avatar', {}, api.about.html.image(msg.value.author)), |
34 | 34 | h('section.timestamp', {}, api.message.html.timestamp(msg)), |
35 | 35 | h('header.author', {}, api.message.html.author(msg)), |
36 | 36 | h('section.meta', {}, api.message.html.meta(msg, { rawMessage })), |
Built with git-ssb-web