git ssb

16+

Dominic / patchbay



Tree: 5efc9453c068026844ade88a23f94fb58be520df

Files: 5efc9453c068026844ade88a23f94fb58be520df / modules_core / search-box.js

1068 bytesRaw
1'use strict'
2var h = require('hyperscript')
3
4exports.needs = {
5 suggest_search: 'map', //REWRITE
6 build_suggest_box: 'first'
7}
8
9exports.gives = 'search_box'
10
11exports.create = function (api) {
12
13 return function (go) {
14
15 var search = h('input.searchprompt', {
16 type: 'search',
17 placeholder: 'Commands',
18 onkeydown: ev => {
19 switch (ev.keyCode) {
20 case 13: // enter
21 ev.stopPropagation()
22 suggestBox.complete()
23
24 if (go(search.value.trim(), !ev.ctrlKey))
25 search.blur()
26 return
27 case 27: // escape
28 ev.preventDefault()
29 search.blur()
30 return
31 }
32 }
33 })
34
35 search.activate = (sigil, ev) => {
36 search.focus()
37 ev.preventDefault()
38 if (search.value[0] === sigil) {
39 search.selectionStart = 1
40 search.selectionEnd = search.value.length
41 } else {
42 search.value = sigil
43 }
44 }
45
46 var suggestBox = api.build_suggest_box(search, api.suggest_search)
47
48 return search
49 }
50
51}
52
53

Built with git-ssb-web