Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
45fa7fd4
Commit
45fa7fd4
authored
Jul 21, 2016
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly checks for character before GFM input char
It must not be letter or number to work
parent
94e0ca00
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
app/assets/javascripts/gfm_auto_complete.js.coffee
app/assets/javascripts/gfm_auto_complete.js.coffee
+17
-0
spec/features/issues/gfm_autocomplete_spec.rb
spec/features/issues/gfm_autocomplete_spec.rb
+21
-3
No files found.
app/assets/javascripts/gfm_auto_complete.js.coffee
View file @
45fa7fd4
...
...
@@ -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
)
...
...
spec/features/issues/gfm_autocomplete_spec.rb
View file @
45fa7fd4
...
...
@@ -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
)
end
it
'opens autocomplete menu when doesnt starts with space'
do
sleep
2
end
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment