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
Jérome Perrin
gitlab-ce
Commits
61271927
Commit
61271927
authored
May 23, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec
parent
7e0a4c5e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
6 deletions
+55
-6
app/assets/javascripts/copy_as_gfm.js
app/assets/javascripts/copy_as_gfm.js
+6
-6
spec/javascripts/copy_as_gfm_spec.js
spec/javascripts/copy_as_gfm_spec.js
+49
-0
No files found.
app/assets/javascripts/copy_as_gfm.js
View file @
61271927
...
...
@@ -273,12 +273,12 @@ const gfmRules = {
class
CopyAsGFM
{
constructor
()
{
$
(
document
).
on
(
'
copy
'
,
'
.md, .wiki
'
,
(
e
)
=>
{
this
.
copyAsGFM
(
e
,
CopyAsGFM
.
transformGFMSelection
);
});
$
(
document
).
on
(
'
copy
'
,
'
pre.code.highlight, .diff-content .line_content
'
,
(
e
)
=>
{
this
.
copyAsGFM
(
e
,
CopyAsGFM
.
transformCodeSelection
);
});
$
(
document
).
on
(
'
paste
'
,
'
.js-gfm-input
'
,
this
.
pasteGFM
.
bind
(
this
)
);
$
(
document
).
on
(
'
copy
'
,
'
.md, .wiki
'
,
(
e
)
=>
{
CopyAsGFM
.
copyAsGFM
(
e
,
CopyAsGFM
.
transformGFMSelection
);
});
$
(
document
).
on
(
'
copy
'
,
'
pre.code.highlight, .diff-content .line_content
'
,
(
e
)
=>
{
CopyAsGFM
.
copyAsGFM
(
e
,
CopyAsGFM
.
transformCodeSelection
);
});
$
(
document
).
on
(
'
paste
'
,
'
.js-gfm-input
'
,
CopyAsGFM
.
pasteGFM
);
}
copyAsGFM
(
e
,
transformer
)
{
static
copyAsGFM
(
e
,
transformer
)
{
const
clipboardData
=
e
.
originalEvent
.
clipboardData
;
if
(
!
clipboardData
)
return
;
...
...
@@ -292,10 +292,10 @@ class CopyAsGFM {
e
.
stopPropagation
();
clipboardData
.
setData
(
'
text/plain
'
,
el
.
textContent
);
clipboardData
.
setData
(
'
text/x-gfm
'
,
CopyAsGFM
.
nodeToGFM
(
el
));
clipboardData
.
setData
(
'
text/x-gfm
'
,
this
.
nodeToGFM
(
el
));
}
pasteGFM
(
e
)
{
static
pasteGFM
(
e
)
{
const
clipboardData
=
e
.
originalEvent
.
clipboardData
;
if
(
!
clipboardData
)
return
;
...
...
spec/javascripts/copy_as_gfm_spec.js
0 → 100644
View file @
61271927
require
(
'
~/copy_as_gfm
'
);
(()
=>
{
describe
(
'
gl.CopyAsGFM
'
,
()
=>
{
describe
(
'
gl.CopyAsGFM.pasteGFM
'
,
()
=>
{
function
callPasteGFM
()
{
const
e
=
{
originalEvent
:
{
clipboardData
:
{
getData
(
mimeType
)
{
// When GFM code is copied, we put the regular plain text
// on the clipboard as `text/plain`, and the GFM as `text/x-gfm`.
// This emulates the behavior of `getData` with that data.
if
(
mimeType
===
'
text/plain
'
)
{
return
'
code
'
;
}
if
(
mimeType
===
'
text/x-gfm
'
)
{
return
'
`code`
'
;
}
return
null
;
},
},
},
preventDefault
()
{},
};
window
.
gl
.
CopyAsGFM
.
pasteGFM
(
e
);
}
it
(
'
wraps pasted code when not already in code tags
'
,
()
=>
{
spyOn
(
window
.
gl
.
utils
,
'
insertText
'
).
and
.
callFake
((
el
,
textFunc
)
=>
{
const
insertedText
=
textFunc
(
'
This is code:
'
,
''
);
expect
(
insertedText
).
toEqual
(
'
`code`
'
);
});
callPasteGFM
();
});
it
(
'
does not wrap pasted code when already in code tags
'
,
()
=>
{
spyOn
(
window
.
gl
.
utils
,
'
insertText
'
).
and
.
callFake
((
el
,
textFunc
)
=>
{
const
insertedText
=
textFunc
(
'
This is code: `
'
,
'
`
'
);
expect
(
insertedText
).
toEqual
(
'
code
'
);
});
callPasteGFM
();
});
});
});
})();
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