Remove scope by clicking on it or by backspacing into it
Unified · Split
| @@ -30,6 +30,9 @@ class app.views.Search extends app.View · 29 unmodified lines | |||
| 30 | .on 'results', @onResults | 30 | .on 'results', @onResults |
| 31 | .on 'end', @onEnd | 31 | .on 'end', @onEnd |
| 32 | 32 | ||
| 33 | @scope | ||
| 34 | .on 'change', @onScopeChange | ||
| 35 | |||
| 33 | app.on 'ready', @onReady | 36 | app.on 'ready', @onReady |
| 34 | $.on window, 'hashchange', @searchUrl | 37 | $.on window, 'hashchange', @searchUrl |
| 35 | $.on window, 'focus', @onWindowFocus | 38 | $.on window, 'focus', @onWindowFocus |
| @@ -138,6 +141,11 @@ class app.views.Search extends app.View · 102 unmodified lines | |||
| 138 | $.stopEvent(event) | 141 | $.stopEvent(event) |
| 139 | return | 142 | return |
| 140 | 143 | ||
| 144 | onScopeChange: => | ||
| 145 | @value = '' | ||
| 146 | @onInput() | ||
| 147 | return | ||
| 148 | |||
| 141 | afterRoute: (name, context) => | 149 | afterRoute: (name, context) => |
| 142 | return if app.shortcuts.eventInProgress?.name is 'escape' | 150 | return if app.shortcuts.eventInProgress?.name is 'escape' |
| 143 | @reset(true) if not context.init and app.router.isIndex() | 151 | @reset(true) if not context.init and app.router.isIndex() |
| @@ -6,6 +6,7 @@ class app.views.SearchScope extends app.View · 5 unmodified lines | |||
| 6 | tag: '._search-tag' | 6 | tag: '._search-tag' |
| 7 | 7 | ||
| 8 | @events: | 8 | @events: |
| 9 | click: 'onClick' | ||
| 9 | keydown: 'onKeydown' | 10 | keydown: 'onKeydown' |
| 10 | 11 | ||
| 11 | @routes: | 12 | @routes: |
| @@ -87,11 +88,17 @@ class app.views.SearchScope extends app.View · 75 unmodified lines | |||
| 87 | @trigger 'change', null, previousDoc | 88 | @trigger 'change', null, previousDoc |
| 88 | return | 89 | return |
| 89 | 90 | ||
| 91 | onClick: (event) => | ||
| 92 | if event.target is @tag | ||
| 93 | @reset() | ||
| 94 | $.stopEvent(event) | ||
| 95 | return | ||
| 96 | |||
| 90 | onKeydown: (event) => | 97 | onKeydown: (event) => |
| 91 | if event.which is 8 # backspace | 98 | if event.which is 8 # backspace |
| 92 | if @doc and not @input.value | 99 | if @doc and @input.selectionEnd is 0 |
| 93 | $.stopEvent(event) | ||
| 94 | @reset() | 100 | @reset() |
| 101 | $.stopEvent(event) | ||
| 95 | else if not @doc and @input.value | 102 | else if not @doc and @input.value |
| 96 | return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey | 103 | return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey |
| 97 | if event.which is 9 or # tab | 104 | if event.which is 9 or # tab |
| @@ -215,5 +215,6 @@ · 214 unmodified lines | |||
| 215 | color: var(--textColorLight); | 215 | color: var(--textColorLight); |
| 216 | background: var(--searchTagBackground); | 216 | background: var(--searchTagBackground); |
| 217 | border-radius: 2px; | 217 | border-radius: 2px; |
| 218 | cursor: pointer; | ||
| 218 | @extend %truncate-text; | 219 | @extend %truncate-text; |
| 219 | } | 220 | } |