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

Remove scope by clicking on it or by backspacing into it
pull/1028/head
Jasper van Merle 6 years ago committed by GitHub
commit 22d78b5e71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,6 +30,9 @@ class app.views.Search extends app.View
.on 'results', @onResults
.on 'end', @onEnd
@scope
.on 'change', @onScopeChange
app.on 'ready', @onReady
$.on window, 'hashchange', @searchUrl
$.on window, 'focus', @onWindowFocus
@ -138,6 +141,11 @@ class app.views.Search extends app.View
$.stopEvent(event)
return
onScopeChange: =>
@value = ''
@onInput()
return
afterRoute: (name, context) =>
return if app.shortcuts.eventInProgress?.name is 'escape'
@reset(true) if not context.init and app.router.isIndex()

@ -6,6 +6,7 @@ class app.views.SearchScope extends app.View
tag: '._search-tag'
@events:
click: 'onClick'
keydown: 'onKeydown'
@routes:
@ -87,11 +88,17 @@ class app.views.SearchScope extends app.View
@trigger 'change', null, previousDoc
return
onClick: (event) =>
if event.target is @tag
@reset()
$.stopEvent(event)
return
onKeydown: (event) =>
if event.which is 8 # backspace
if @doc and not @input.value
$.stopEvent(event)
if @doc and @input.selectionEnd is 0
@reset()
$.stopEvent(event)
else if not @doc and @input.value
return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey
if event.which is 9 or # tab

@ -215,5 +215,6 @@
color: var(--textColorLight);
background: var(--searchTagBackground);
border-radius: 2px;
cursor: pointer;
@extend %truncate-text;
}

Loading…
Cancel
Save