summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfredo Sumaran <alfredo@gitlab.com>2016-03-23 17:30:11 -0500
committerAlfredo Sumaran <alfredo@gitlab.com>2016-03-23 17:30:11 -0500
commit8c1d50e69c4fc8926cc63c62d3f900cdfd4f6d28 (patch)
tree0d5c92dfbed5a7755d04c964037f1bb17317f6e3
parentabe56ad6f54ddce9b042e208c4ad8bb149b41a16 (diff)
downloadgitlab-ce-8c1d50e69c4fc8926cc63c62d3f900cdfd4f6d28.tar.gz
Fixes removing the location badge with backspace on the last character
-rw-r--r--app/assets/javascripts/search_autocomplete.js.coffee23
1 files changed, 19 insertions, 4 deletions
diff --git a/app/assets/javascripts/search_autocomplete.js.coffee b/app/assets/javascripts/search_autocomplete.js.coffee
index 821e4c27570..89dab2cd63d 100644
--- a/app/assets/javascripts/search_autocomplete.js.coffee
+++ b/app/assets/javascripts/search_autocomplete.js.coffee
@@ -36,6 +36,8 @@ class @SearchAutocomplete
@searchInput.addClass('disabled')
+ @saveTextLength()
+
@bindEvents()
# Finds an element inside wrapper element
@@ -45,6 +47,9 @@ class @SearchAutocomplete
saveOriginalState: ->
@originalState = @serializeState()
+ saveTextLength: ->
+ @lastTextLength = @searchInput.val().length
+
createAutocomplete: ->
@searchInput.glDropdown
filterInputBlur: false
@@ -65,6 +70,8 @@ class @SearchAutocomplete
# Prevent multiple ajax calls
return if @loadingSuggestions
+ return if @badgePresent()
+
@loadingSuggestions = true
jqXHR = $.get(@autocompletePath, {
@@ -102,10 +109,11 @@ class @SearchAutocomplete
scope: @scopeInputEl.val()
# Location badge
- _location: $.trim(@locationText.text())
+ _location: @locationText.text()
}
bindEvents: ->
+ @searchInput.on 'keydown', @onSearchInputKeyDown
@searchInput.on 'keyup', @onSearchInputKeyUp
@searchInput.on 'click', @onSearchInputClick
@searchInput.on 'focus', @onSearchInputFocus
@@ -123,12 +131,19 @@ class @SearchAutocomplete
onDropdownOpen: (e) =>
@dropdown.dropdown('toggle')
+ onSearchInputKeyDown: =>
+ # Saves last length of the entered text
+ @saveTextLength()
+
onSearchInputKeyUp: (e) =>
switch e.keyCode
when KEYCODE.BACKSPACE
- if e.currentTarget.value is ''
- @removeLocationBadge()
- @searchInput.focus()
+ # when trying to remove the location badge
+ if @lastTextLength is 0 and @badgePresent()
+ @removeLocationBadge()
+
+ # When removing the last character and no badge is present
+ if @lastTextLength is 1 and !@badgePresent()
@disableAutocomplete()
when KEYCODE.ESCAPE
if @badgePresent()