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