Skip to content

Commit c6f0f16

Browse files
committed
Limit new event listener to Chrome for Android
1 parent 504f95e commit c6f0f16

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

assets/javascripts/lib/util.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ isIE = null
352352
$.isIE = ->
353353
isIE ?= navigator.userAgent?.indexOf('MSIE') >= 0 || navigator.userAgent?.indexOf('rv:11.0') >= 0
354354

355+
isChromeForAndroid = null
356+
$.isChromeForAndroid = ->
357+
isChromeForAndroid ?= navigator.userAgent?.indexOf('Android') >= 0 && /Chrome\/([.0-9])+ Mobile/.test(navigator.userAgent)
358+
355359
isAndroid = null
356360
$.isAndroid = ->
357361
isAndroid ?= navigator.userAgent?.indexOf('Android') >= 0

assets/javascripts/views/search/search_scope.coffee

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,27 @@ class app.views.SearchScope extends app.View
8888
@trigger 'change', null, previousDoc
8989
return
9090

91+
doScopeSearch: (event) =>
92+
@search @input.value[0...@input.selectionStart]
93+
$.stopEvent(event) if @doc
94+
return
95+
9196
onKeydown: (event) =>
9297
if event.which is 8 # backspace
9398
if @doc and not @input.value
9499
$.stopEvent(event)
95100
@reset()
96-
else if not @doc and @input.value
101+
else if not @doc and @input.value and not $.isChromeForAndroid()
97102
return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey
98103
if event.which is 9 or # tab
99104
(event.which is 32 and app.isMobile()) # space
100-
@search @input.value[0...@input.selectionStart]
101-
$.stopEvent(event) if @doc
105+
@doScopeSearch(event)
102106
return
103107

104108
onTextInput: (event) =>
105-
if event.data == ' ' and app.isMobile()
106-
@search @input.value[0...@input.selectionStart]
107-
$.stopEvent(event) if @doc
109+
return unless $.isChromeForAndroid()
110+
if not @doc and @input.value and event.data == ' '
111+
@doScopeSearch(event)
108112
return
109113

110114
extractHashValue: ->

0 commit comments

Comments
 (0)