Skip to content

Commit a0c12c9

Browse files
authored
Fix single documentation search on Android (#941)
Fix single documentation search on Android
2 parents e684e8c + 1c007d8 commit a0c12c9

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
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: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class app.views.SearchScope extends app.View
88
@events:
99
click: 'onClick'
1010
keydown: 'onKeydown'
11+
textInput: 'onTextInput'
1112

1213
@routes:
1314
after: 'afterRoute'
@@ -88,6 +89,11 @@ class app.views.SearchScope extends app.View
8889
@trigger 'change', null, previousDoc
8990
return
9091

92+
doScopeSearch: (event) =>
93+
@search @input.value[0...@input.selectionStart]
94+
$.stopEvent(event) if @doc
95+
return
96+
9197
onClick: (event) =>
9298
if event.target is @tag
9399
@reset()
@@ -99,12 +105,17 @@ class app.views.SearchScope extends app.View
99105
if @doc and @input.selectionEnd is 0
100106
@reset()
101107
$.stopEvent(event)
102-
else if not @doc and @input.value
108+
else if not @doc and @input.value and not $.isChromeForAndroid()
103109
return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey
104110
if event.which is 9 or # tab
105111
(event.which is 32 and app.isMobile()) # space
106-
@search @input.value[0...@input.selectionStart]
107-
$.stopEvent(event) if @doc
112+
@doScopeSearch(event)
113+
return
114+
115+
onTextInput: (event) =>
116+
return unless $.isChromeForAndroid()
117+
if not @doc and @input.value and event.data == ' '
118+
@doScopeSearch(event)
108119
return
109120

110121
extractHashValue: ->

0 commit comments

Comments
 (0)