Closes #639.
Unified · Split
| @@ -15,8 +15,10 @@ · 14 unmodified lines | ||
| 15 | 15 | @ |
| 16 | 16 | |
| 17 | 17 | trigger: (event, args...) -> |
| 18 | + @eventInProgress = { name: event, args: args } | |
| 18 | 19 | if callbacks = @_callbacks?[event] |
| 19 | 20 | callback? args... for callback in callbacks.slice(0) |
| 21 | + @eventInProgress = null | |
| 20 | 22 | @trigger 'all', event, args... unless event is 'all' |
| 21 | 23 | @ |
| 22 | 24 | |
| @@ -44,7 +44,11 @@ class app.views.Search extends app.View · 43 unmodified lines | ||
| 44 | 44 | @input.focus() unless document.activeElement?.tagName is 'INPUT' |
| 45 | 45 | return |
| 46 | 46 | |
| 47 | − reset: -> | |
| 47 | + getScopeDoc: -> | |
| 48 | + @scope.getScope() if @scope.isActive() | |
| 49 | + | |
| 50 | + reset: (force) -> | |
| 51 | + @scope.reset() if force or not @input.value | |
| 48 | 52 | @el.reset() |
| 49 | 53 | @onInput() |
| 50 | 54 | @autoFocus() |
| @@ -129,7 +133,8 @@ class app.views.Search extends app.View · 78 unmodified lines | ||
| 129 | 133 | return |
| 130 | 134 | |
| 131 | 135 | afterRoute: (name, context) => |
| 132 | − @reset() if not context.init and app.router.isIndex() | |
| 136 | + return if app.shortcuts.eventInProgress?.name is 'escape' | |
| 137 | + @reset(true) if not context.init and app.router.isIndex() | |
| 133 | 138 | @delay @searchUrl if context.hash |
| 134 | 139 | @delay @autoFocus |
| 135 | 140 | return |
| @@ -11,9 +11,6 @@ class app.views.SearchScope extends app.View · 10 unmodified lines | ||
| 11 | 11 | @routes: |
| 12 | 12 | after: 'afterRoute' |
| 13 | 13 | |
| 14 | − @shortcuts: | |
| 15 | − escape: 'reset' | |
| 16 | − | |
| 17 | 14 | constructor: (@el) -> super |
| 18 | 15 | |
| 19 | 16 | init: -> |
| @@ -29,6 +26,9 @@ class app.views.SearchScope extends app.View · 9 unmodified lines | ||
| 29 | 26 | getScope: -> |
| 30 | 27 | @doc or app |
| 31 | 28 | |
| 29 | + isActive: -> | |
| 30 | + !!@doc | |
| 31 | + | |
| 32 | 32 | name: -> |
| 33 | 33 | @doc?.name |
| 34 | 34 | |
| @@ -129,7 +129,8 @@ class app.views.Sidebar extends app.View · 128 unmodified lines | ||
| 129 | 129 | |
| 130 | 130 | onEscape: => |
| 131 | 131 | @reset() |
| 132 | − @scrollToTop() | |
| 132 | + @resetDisplay() | |
| 133 | + if doc = @search.getScopeDoc() then @docList.reveal(doc.toEntry()) else @scrollToTop() | |
| 133 | 134 | return |
| 134 | 135 | |
| 135 | 136 | onDocEnabled: -> |
| @@ -137,6 +138,8 @@ class app.views.Sidebar extends app.View · 1 unmodified line | ||
| 137 | 138 | @reset() |
| 138 | 139 | return |
| 139 | 140 | |
| 140 | − afterRoute: => | |
| 141 | + afterRoute: (name, context) => | |
| 142 | + return if app.shortcuts.eventInProgress?.name is 'escape' | |
| 143 | + @reset() if not context.init and app.router.isIndex() | |
| 141 | 144 | @resetDisplay() |
| 142 | 145 | return |