[devdocsgjs/main: 511/1867] Remove scope by clicking on it or by backspacing into it




commit 8039610888592c57d5ed4d694c0633120154bace
Author: Jasper van Merle <jaspervmerle gmail com>
Date:   Sun Nov 25 01:22:15 2018 +0100

    Remove scope by clicking on it or by backspacing into it

 assets/javascripts/views/search/search.coffee       |  7 +++++++
 assets/javascripts/views/search/search_scope.coffee | 13 +++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/assets/javascripts/views/search/search.coffee b/assets/javascripts/views/search/search.coffee
index 8fab885c..ad5b6a0c 100644
--- a/assets/javascripts/views/search/search.coffee
+++ b/assets/javascripts/views/search/search.coffee
@@ -30,6 +30,9 @@ class app.views.Search extends app.View
       .on 'results', @onResults
       .on 'end', @onEnd
 
+    @scope
+      .on 'change', @onScopeChange
+
     app.on 'ready', @onReady
     $.on window, 'hashchange', @searchUrl
     $.on window, 'focus', @onWindowFocus
@@ -138,6 +141,10 @@ class app.views.Search extends app.View
     $.stopEvent(event)
     return
 
+  onScopeChange: =>
+    @value = ''
+    return
+
   afterRoute: (name, context) =>
     return if app.shortcuts.eventInProgress?.name is 'escape'
     @reset(true) if not context.init and app.router.isIndex()
diff --git a/assets/javascripts/views/search/search_scope.coffee 
b/assets/javascripts/views/search/search_scope.coffee
index 24de57ce..8ad033ec 100644
--- a/assets/javascripts/views/search/search_scope.coffee
+++ b/assets/javascripts/views/search/search_scope.coffee
@@ -6,6 +6,7 @@ class app.views.SearchScope extends app.View
     tag:   '._search-tag'
 
   @events:
+    click: 'onClick'
     keydown: 'onKeydown'
 
   @routes:
@@ -87,11 +88,19 @@ class app.views.SearchScope extends app.View
     @trigger 'change', null, previousDoc
     return
 
+  onClick: (event) =>
+    if event.target is @tag
+      @reset()
+      $.trigger @input, 'input'
+      $.stopEvent(event)
+    return
+
   onKeydown: (event) =>
     if event.which is 8 # backspace
-      if @doc and not @input.value
-        $.stopEvent(event)
+      if @doc and @input.selectionEnd is 0
         @reset()
+        $.trigger @input, 'input'
+        $.stopEvent(event)
     else if not @doc and @input.value
       return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey
       if event.which is 9 or # tab


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]