Improve behavior of search scope when hitting escape

Closes #639.
This commit is contained in:
Thibaut Courouble 2017-06-25 16:01:22 -04:00
parent 4bc31ad41f
commit 48d85f1124
4 changed files with 17 additions and 7 deletions

View file

@ -15,8 +15,10 @@
@
trigger: (event, args...) ->
@eventInProgress = { name: event, args: args }
if callbacks = @_callbacks?[event]
callback? args... for callback in callbacks.slice(0)
@eventInProgress = null
@trigger 'all', event, args... unless event is 'all'
@

View file

@ -44,7 +44,11 @@ class app.views.Search extends app.View
@input.focus() unless document.activeElement?.tagName is 'INPUT'
return
reset: ->
getScopeDoc: ->
@scope.getScope() if @scope.isActive()
reset: (force) ->
@scope.reset() if force or not @input.value
@el.reset()
@onInput()
@autoFocus()
@ -129,7 +133,8 @@ class app.views.Search extends app.View
return
afterRoute: (name, context) =>
@reset() if not context.init and app.router.isIndex()
return if app.shortcuts.eventInProgress?.name is 'escape'
@reset(true) if not context.init and app.router.isIndex()
@delay @searchUrl if context.hash
@delay @autoFocus
return

View file

@ -11,9 +11,6 @@ class app.views.SearchScope extends app.View
@routes:
after: 'afterRoute'
@shortcuts:
escape: 'reset'
constructor: (@el) -> super
init: ->
@ -29,6 +26,9 @@ class app.views.SearchScope extends app.View
getScope: ->
@doc or app
isActive: ->
!!@doc
name: ->
@doc?.name

View file

@ -129,7 +129,8 @@ class app.views.Sidebar extends app.View
onEscape: =>
@reset()
@scrollToTop()
@resetDisplay()
if doc = @search.getScopeDoc() then @docList.reveal(doc.toEntry()) else @scrollToTop()
return
onDocEnabled: ->
@ -137,6 +138,8 @@ class app.views.Sidebar extends app.View
@reset()
return
afterRoute: =>
afterRoute: (name, context) =>
return if app.shortcuts.eventInProgress?.name is 'escape'
@reset() if not context.init and app.router.isIndex()
@resetDisplay()
return