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
3030 .on 'results', @onResults
3131 .on 'end', @onEnd
3232
33+ @scope
34+ .on 'change', @onScopeChange
35+
3336 app.on 'ready', @onReady
3437 $.on window, 'hashchange', @searchUrl
3538 $.on window, 'focus', @onWindowFocus
@@ -138,6 +141,11 @@ class app.views.Search extends app.View · 102 unmodified lines
138141 $.stopEvent(event)
139142 return
140143
144+ onScopeChange: =>
145+ @value = ''
146+ @onInput()
147+ return
148+
141149 afterRoute: (name, context) =>
142150 return if app.shortcuts.eventInProgress?.name is 'escape'
143151 @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
66 tag: '._search-tag'
77
88 @events:
9+ click: 'onClick'
910 keydown: 'onKeydown'
1011
1112 @routes:
@@ -87,11 +88,17 @@ class app.views.SearchScope extends app.View · 75 unmodified lines
8788 @trigger 'change', null, previousDoc
8889 return
8990
91+ onClick: (event) =>
92+ if event.target is @tag
93+ @reset()
94+ $.stopEvent(event)
95+ return
96+
9097 onKeydown: (event) =>
9198 if event.which is 8 # backspace
92− if @doc and not @input.value
93− $.stopEvent(event)
99+ if @doc and @input.selectionEnd is 0
94100 @reset()
101+ $.stopEvent(event)
95102 else if not @doc and @input.value
96103 return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey
97104 if event.which is 9 or # tab
assets/stylesheets/components/_header.scss+1−0
@@ -215,5 +215,6 @@ · 214 unmodified lines
215215 color: var(--textColorLight);
216216 background: var(--searchTagBackground);
217217 border-radius: 2px;
218+ cursor: pointer;
218219 @extend %truncate-text;
219220 }