Improve behavior of search scope when hitting escape

Closes #639.
pull/647/head
Thibaut Courouble 8 years ago
parent 4bc31ad41f
commit 48d85f1124

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

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

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

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

Loading…
Cancel
Save