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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
71a56d9c
Commit
71a56d9c
authored
Feb 12, 2019
by
Tim Zallmann
Committed by
Phil Hughes
Feb 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transforming Gfm also on paste so it works also in FF
parent
d29e81b2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
5 deletions
+29
-5
app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
+29
-5
No files found.
app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
View file @
71a56d9c
...
@@ -36,13 +36,20 @@ export class CopyAsGFM {
...
@@ -36,13 +36,20 @@ export class CopyAsGFM {
div
.
appendChild
(
el
.
cloneNode
(
true
));
div
.
appendChild
(
el
.
cloneNode
(
true
));
const
html
=
div
.
innerHTML
;
const
html
=
div
.
innerHTML
;
clipboardData
.
setData
(
'
text/plain
'
,
el
.
textContent
);
clipboardData
.
setData
(
'
text/html
'
,
html
);
// We are also setting this as fallback to transform the selection to gfm on paste
clipboardData
.
setData
(
'
text/x-gfm-html
'
,
html
);
CopyAsGFM
.
nodeToGFM
(
el
)
CopyAsGFM
.
nodeToGFM
(
el
)
.
then
(
res
=>
{
.
then
(
res
=>
{
clipboardData
.
setData
(
'
text/plain
'
,
el
.
textContent
);
clipboardData
.
setData
(
'
text/x-gfm
'
,
res
);
clipboardData
.
setData
(
'
text/x-gfm
'
,
res
);
clipboardData
.
setData
(
'
text/html
'
,
html
);
})
})
.
catch
(()
=>
{});
.
catch
(()
=>
{
// Not showing the error as Firefox might doesn't allow
// it or other browsers who have a time limit on the execution
// of the copy event
});
}
}
static
pasteGFM
(
e
)
{
static
pasteGFM
(
e
)
{
...
@@ -51,11 +58,28 @@ export class CopyAsGFM {
...
@@ -51,11 +58,28 @@ export class CopyAsGFM {
const
text
=
clipboardData
.
getData
(
'
text/plain
'
);
const
text
=
clipboardData
.
getData
(
'
text/plain
'
);
const
gfm
=
clipboardData
.
getData
(
'
text/x-gfm
'
);
const
gfm
=
clipboardData
.
getData
(
'
text/x-gfm
'
);
if
(
!
gfm
)
return
;
const
gfmHtml
=
clipboardData
.
getData
(
'
text/x-gfm-html
'
);
if
(
!
gfm
&&
!
gfmHtml
)
return
;
e
.
preventDefault
();
e
.
preventDefault
();
window
.
gl
.
utils
.
insertText
(
e
.
target
,
textBefore
=>
{
// We have the original selection already converted to gfm
if
(
gfm
)
{
CopyAsGFM
.
insertPastedText
(
e
.
target
,
text
,
gfm
);
}
else
{
// Due to the async copy call we are not able to produce gfm so we transform the cached HTML
const
div
=
document
.
createElement
(
'
div
'
);
div
.
innerHTML
=
gfmHtml
;
CopyAsGFM
.
nodeToGFM
(
div
)
.
then
(
transformedGfm
=>
{
CopyAsGFM
.
insertPastedText
(
e
.
target
,
text
,
transformedGfm
);
})
.
catch
(()
=>
{});
}
}
static
insertPastedText
(
target
,
text
,
gfm
)
{
window
.
gl
.
utils
.
insertText
(
target
,
textBefore
=>
{
// If the text before the cursor contains an odd number of backticks,
// If the text before the cursor contains an odd number of backticks,
// we are either inside an inline code span that starts with 1 backtick
// we are either inside an inline code span that starts with 1 backtick
// or a code block that starts with 3 backticks.
// or a code block that starts with 3 backticks.
...
...
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