Correctly checks for character before GFM input char
It must not be letter or number to work
This commit is contained in:
parent
94e0ca0049
commit
45fa7fd4dd
|
@ -43,6 +43,17 @@ GitLab.GfmAutoComplete =
|
|||
@at
|
||||
else
|
||||
value
|
||||
matcher: (flag, subtext, should_startWithSpace) ->
|
||||
# escape RegExp
|
||||
flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")
|
||||
|
||||
# À
|
||||
_a = decodeURI("%C3%80")
|
||||
# ÿ
|
||||
_y = decodeURI("%C3%BF")
|
||||
regexp = new RegExp "(?:\\B|\\W|\\s)#{flag}([A-Za-z#{_a}-#{_y}0-9_\'\.\+\-]*)|([^\\x00-\\xff]*)$", 'gi'
|
||||
match = regexp.exec subtext
|
||||
if match then match[2] || match[1] else null
|
||||
|
||||
# Add GFM auto-completion to all input fields, that accept GFM input.
|
||||
setup: (wrap) ->
|
||||
|
@ -89,6 +100,7 @@ GitLab.GfmAutoComplete =
|
|||
sorter: @DefaultOptions.sorter
|
||||
filter: @DefaultOptions.filter
|
||||
beforeInsert: @DefaultOptions.beforeInsert
|
||||
matcher: @DefaultOptions.matcher
|
||||
|
||||
# Team Members
|
||||
@input.atwho
|
||||
|
@ -106,6 +118,7 @@ GitLab.GfmAutoComplete =
|
|||
sorter: @DefaultOptions.sorter
|
||||
filter: @DefaultOptions.filter
|
||||
beforeInsert: @DefaultOptions.beforeInsert
|
||||
matcher: @DefaultOptions.matcher
|
||||
beforeSave: (members) ->
|
||||
$.map members, (m) ->
|
||||
return m if not m.username?
|
||||
|
@ -133,6 +146,7 @@ GitLab.GfmAutoComplete =
|
|||
sorter: @DefaultOptions.sorter
|
||||
filter: @DefaultOptions.filter
|
||||
beforeInsert: @DefaultOptions.beforeInsert
|
||||
matcher: @DefaultOptions.matcher
|
||||
beforeSave: (issues) ->
|
||||
$.map issues, (i) ->
|
||||
return i if not i.title?
|
||||
|
@ -154,6 +168,7 @@ GitLab.GfmAutoComplete =
|
|||
data: ['loading']
|
||||
startWithSpace: false
|
||||
callbacks:
|
||||
matcher: @DefaultOptions.matcher
|
||||
beforeSave: (milestones) ->
|
||||
$.map milestones, (m) ->
|
||||
return m if not m.title?
|
||||
|
@ -178,6 +193,7 @@ GitLab.GfmAutoComplete =
|
|||
sorter: @DefaultOptions.sorter
|
||||
filter: @DefaultOptions.filter
|
||||
beforeInsert: @DefaultOptions.beforeInsert
|
||||
matcher: @DefaultOptions.matcher
|
||||
beforeSave: (merges) ->
|
||||
$.map merges, (m) ->
|
||||
return m if not m.title?
|
||||
|
@ -194,6 +210,7 @@ GitLab.GfmAutoComplete =
|
|||
insertTpl: '${atwho-at}${title}'
|
||||
startWithSpace: false
|
||||
callbacks:
|
||||
matcher: @DefaultOptions.matcher
|
||||
beforeSave: (merges) ->
|
||||
sanitizeLabelTitle = (title)->
|
||||
if /[\w\?&]+\s+[\w\?&]+/g.test(title)
|
||||
|
|
|
@ -9,16 +9,34 @@ feature 'GFM autocomplete', feature: true, js: true do
|
|||
project.team << [user, :master]
|
||||
login_as(user)
|
||||
visit namespace_project_issue_path(project.namespace, project, issue)
|
||||
|
||||
sleep 2
|
||||
end
|
||||
|
||||
it 'opens autocomplete menu when doesnt starts with space' do
|
||||
sleep 2
|
||||
|
||||
it 'opens autocomplete menu when field starts with text' do
|
||||
page.within '.timeline-content-form' do
|
||||
find('#note_note').native.send_keys('testing')
|
||||
find('#note_note').native.send_keys('')
|
||||
find('#note_note').native.send_keys('@')
|
||||
end
|
||||
|
||||
expect(page).to have_selector('.atwho-view')
|
||||
end
|
||||
|
||||
it 'opens autocomplete menu when field is prefixed with non-text character' do
|
||||
page.within '.timeline-content-form' do
|
||||
find('#note_note').native.send_keys('')
|
||||
find('#note_note').native.send_keys('@')
|
||||
end
|
||||
|
||||
expect(page).to have_selector('.atwho-view')
|
||||
end
|
||||
|
||||
it 'doesnt open autocomplete menu character is prefixed with text' do
|
||||
page.within '.timeline-content-form' do
|
||||
find('#note_note').native.send_keys('testing')
|
||||
find('#note_note').native.send_keys('@')
|
||||
end
|
||||
|
||||
expect(page).not_to have_selector('.atwho-view')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue