diff --git a/assets/javascripts/lib/events.coffee b/assets/javascripts/lib/events.coffee index feeb5498..05936076 100644 --- a/assets/javascripts/lib/events.coffee +++ b/assets/javascripts/lib/events.coffee @@ -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' @ diff --git a/assets/javascripts/views/search/search.coffee b/assets/javascripts/views/search/search.coffee index b9d72b6a..6edbe2fd 100644 --- a/assets/javascripts/views/search/search.coffee +++ b/assets/javascripts/views/search/search.coffee @@ -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 diff --git a/assets/javascripts/views/search/search_scope.coffee b/assets/javascripts/views/search/search_scope.coffee index 500ba20f..24de57ce 100644 --- a/assets/javascripts/views/search/search_scope.coffee +++ b/assets/javascripts/views/search/search_scope.coffee @@ -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 diff --git a/assets/javascripts/views/sidebar/sidebar.coffee b/assets/javascripts/views/sidebar/sidebar.coffee index de74261f..cef9e8d0 100644 --- a/assets/javascripts/views/sidebar/sidebar.coffee +++ b/assets/javascripts/views/sidebar/sidebar.coffee @@ -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