History

Remove scope by clicking on it or by backspacing into it (#942)

Remove scope by clicking on it or by backspacing into it

Jasper van Merle committed 7 years ago

Commit 22d78b52 parents d477ed1 4d4a8f93 files · +18 −2Browse files

Unified · Split

3 files
  1. assets/javascripts/views/search/search.coffee +8 −0
  2. assets/javascripts/views/search/search_scope.coffee +9 −2
  3. assets/stylesheets/components/_header.scss +1 −0
assets/javascripts/views/search/search.coffee+8−0
@@ -30,6 +30,9 @@ class app.views.Search extends app.View · 29 unmodified lines
30 .on 'results', @onResults30 .on 'results', @onResults
31 .on 'end', @onEnd31 .on 'end', @onEnd
32 32
33 @scope
34 .on 'change', @onScopeChange
35
33 app.on 'ready', @onReady36 app.on 'ready', @onReady
34 $.on window, 'hashchange', @searchUrl37 $.on window, 'hashchange', @searchUrl
35 $.on window, 'focus', @onWindowFocus38 $.on window, 'focus', @onWindowFocus
@@ -138,6 +141,11 @@ class app.views.Search extends app.View · 102 unmodified lines
138 $.stopEvent(event)141 $.stopEvent(event)
139 return142 return
140 143
144 onScopeChange: =>
145 @value = ''
146 @onInput()
147 return
148
141 afterRoute: (name, context) =>149 afterRoute: (name, context) =>
142 return if app.shortcuts.eventInProgress?.name is 'escape'150 return if app.shortcuts.eventInProgress?.name is 'escape'
143 @reset(true) if not context.init and app.router.isIndex()151 @reset(true) if not context.init and app.router.isIndex()
assets/javascripts/views/search/search_scope.coffee+9−2
@@ -6,6 +6,7 @@ class app.views.SearchScope extends app.View · 5 unmodified lines
6 tag: '._search-tag'6 tag: '._search-tag'
7 7
8 @events:8 @events:
9 click: 'onClick'
9 keydown: 'onKeydown'10 keydown: 'onKeydown'
10 11
11 @routes:12 @routes:
@@ -87,11 +88,17 @@ class app.views.SearchScope extends app.View · 75 unmodified lines
87 @trigger 'change', null, previousDoc88 @trigger 'change', null, previousDoc
88 return89 return
89 90
91 onClick: (event) =>
92 if event.target is @tag
93 @reset()
94 $.stopEvent(event)
95 return
96
90 onKeydown: (event) =>97 onKeydown: (event) =>
91 if event.which is 8 # backspace98 if event.which is 8 # backspace
92 if @doc and not @input.value99 if @doc and @input.selectionEnd is 0
93 $.stopEvent(event)
94 @reset()100 @reset()
101 $.stopEvent(event)
95 else if not @doc and @input.value102 else if not @doc and @input.value
96 return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey103 return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey
97 if event.which is 9 or # tab104 if event.which is 9 or # tab
assets/stylesheets/components/_header.scss+1−0
@@ -215,5 +215,6 @@ · 214 unmodified lines
215 color: var(--textColorLight);215 color: var(--textColorLight);
216 background: var(--searchTagBackground);216 background: var(--searchTagBackground);
217 border-radius: 2px;217 border-radius: 2px;
218 cursor: pointer;
218 @extend %truncate-text;219 @extend %truncate-text;
219}220}