Skip to content

Commit 22d78b5

Browse files
authored
Remove scope by clicking on it or by backspacing into it (#942)
Remove scope by clicking on it or by backspacing into it
2 parents d477ed1 + 4d4a8f9 commit 22d78b5

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

assets/javascripts/views/search/search.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class app.views.Search extends app.View
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
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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class app.views.SearchScope extends app.View
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
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,6 @@
215215
color: var(--textColorLight);
216216
background: var(--searchTagBackground);
217217
border-radius: 2px;
218+
cursor: pointer;
218219
@extend %truncate-text;
219220
}

0 commit comments

Comments
 (0)