git ssb

16+

Dominic / patchbay



Commit a2793e72faf8165dbb3e94f713d5670e7c557606

refactor message opening into keyboard shortcuts file

mix irving committed on 3/28/2017, 11:01:10 AM
Parent: 0c82b5ef7a36d201a465e8fd4f91ebafc925ab4c

Files changed

main/sync/catch-keyboard-shortcut.jschanged
message/html/layout/default.jschanged
main/sync/catch-keyboard-shortcut.jsView
@@ -9,9 +9,9 @@
99 var gPressed = false
1010
1111 root.addEventListener('keydown', (ev) => {
1212 isTextFieldEvent(ev)
13- ? textFieldShortcuts(ev, opts)
13+ ? textFieldShortcuts(ev)
1414 : genericShortcuts(ev, opts)
1515 })
1616 }
1717 }
@@ -19,9 +19,9 @@
1919 // TODO build better apis for navigation, search, and publishing
2020
2121 function isTextFieldEvent (ev) {
2222 const tag = ev.target.nodeName
23- return (tag === 'INPUT' || tag === 'TEXTAREA')
23+ return (tag === 'INPUT' || tag === 'TEXTAREA')
2424 }
2525
2626 function textFieldShortcuts (ev) {
2727 if (ev.keyCode === 13 && ev.ctrlKey) {
@@ -30,10 +30,10 @@
3030 }
3131
3232 function genericShortcuts (ev, { tabs, search }) {
3333
34- // scroll to top
35- if (ev.keyCode === 71) { // g
34+ // Messages
35+ if (ev.keyCode === 71) { // gg = scroll to top
3636 if (!gPressed) {
3737 gPressed = true
3838 return
3939 }
@@ -42,48 +42,55 @@
4242 gPressed = false
4343
4444 switch (ev.keyCode) {
4545
46- // scroll through messages
47- case 74: // j
46+ // Messages (cont'd)
47+ case 74: // j = older
4848 return tabs.get(tabs.selected[0]).firstChild.scroll(1)
49- case 75: // k
49+ case 75: // k = newer
5050 return tabs.get(tabs.selected[0]).firstChild.scroll(-1)
51+ case 13: // enter = open
52+ return goToMessage(ev)
53+ case 79: // o = open
54+ return goToMessage(ev)
5155
52- // scroll through tabs
53- case 72: // h
56+ // Tabs
57+ case 72: // h = left
5458 return tabs.selectRelative(-1)
55- case 76: // l
59+ case 76: // l = right
5660 return tabs.selectRelative(1)
57-
58- // close current tab
59- case 88: // x
61+ case 88: // x = close
6062 if (tabs.selected) {
6163 var sel = tabs.selected
6264 var i = sel.reduce(function (a, b) { return Math.min(a, b) })
6365 tabs.remove(sel)
6466 tabs.select(Math.max(i - 1, 0))
6567 }
6668 return
6769
68- // activate the search field
69- case 191: // /
70+ // Search
71+ case 191: // / = routes search
7072 if (ev.shiftKey) search.activate('?', ev)
7173 else search.activate('/', ev)
7274 return
73-
74- // navigate to a feed
75- case 50: // 2
75+ case 50: // @ = mention search
7676 if (ev.shiftKey) search.activate('@', ev)
7777 return
78-
79- // navigate to a channel
80- case 51: // 3
78+ case 51: // # = channel search
8179 if (ev.shiftKey) search.activate('#', ev)
8280 return
83-
84- // navigate to a message
85- case 53: // 5
81+ case 53: // % = message search
8682 if (ev.shiftKey) search.activate('%', ev)
8783 return
8884 }
8985 }
86+
87+
88+function goToMessage (ev) {
89+ const msg = ev.target
90+ if (!msg.classList.contains('Message')) return
91+
92+ // this uses a crudely exported nav api
93+ const search = document.querySelector('input[type=search]')
94+ search.go(msg.dataset.root)
95+}
96+
message/html/layout/default.jsView
@@ -22,12 +22,12 @@
2222
2323 var rawMessage = Value(null)
2424
2525 return h('Message', {
26- 'ev-keydown': navigateToMessageOnEnter,
2726 attributes: {
2827 tabindex: '0', // needed to be able to navigate and show focus()
2928 'data-key': msg.key,
29+ 'data-root': msg.value.content.root,
3030 'data-text': msg.value.content.text
3131 }
3232 }, [
3333 h('section.avatar', {}, api.about.html.image(msg.value.author)),
@@ -39,19 +39,7 @@
3939 h('section.raw-content', rawMessage),
4040 h('section.actions', {}, api.message.html.action(msg)),
4141 h('footer.backlinks', {}, api.message.html.backlinks(msg))
4242 ])
43-
44- function navigateToMessageOnEnter (ev) {
45- // on enter (or 'o'), hit first meta.
46- if (!(ev.keyCode === 13 || ev.keyCode === 79)) return
47-
48- // unless in an input
49- if (ev.target.nodeName === 'INPUT' || ev.target.nodeName === 'TEXTAREA') return
50-
51- // this uses a crudely exported nav api
52- const search = document.querySelector('input[type=search]')
53- search.go(msg.value.content.root)
54- }
5543 }
5644 }
5745

Built with git-ssb-web