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
78e7efae
Commit
78e7efae
authored
May 18, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Copy as GFM even when parts of other elements are selected
parent
c013d23d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
8 deletions
+26
-8
app/assets/javascripts/copy_as_gfm.js
app/assets/javascripts/copy_as_gfm.js
+19
-3
app/assets/javascripts/shortcuts_issuable.js
app/assets/javascripts/shortcuts_issuable.js
+3
-5
changelogs/unreleased/dm-copy-gfm-when-parts-of-other-elements-are-selected.yml
...dm-copy-gfm-when-parts-of-other-elements-are-selected.yml
+4
-0
No files found.
app/assets/javascripts/copy_as_gfm.js
View file @
78e7efae
...
@@ -330,11 +330,27 @@ class CopyAsGFM {
...
@@ -330,11 +330,27 @@ class CopyAsGFM {
}
}
static
transformGFMSelection
(
documentFragment
)
{
static
transformGFMSelection
(
documentFragment
)
{
// If the documentFragment contains more than just Markdown, don't copy as GFM.
const
gfmEls
=
documentFragment
.
querySelectorAll
(
'
.md, .wiki
'
);
if
(
documentFragment
.
querySelector
(
'
.md, .wiki
'
))
return
null
;
switch
(
gfmEls
.
length
)
{
case
0
:
{
return
documentFragment
;
return
documentFragment
;
}
}
case
1
:
{
return
gfmEls
[
0
];
}
default
:
{
const
allGfmEl
=
document
.
createElement
(
'
div
'
);
for
(
let
i
=
0
;
i
<
gfmEls
.
length
;
i
+=
1
)
{
const
lineEl
=
gfmEls
[
i
];
allGfmEl
.
appendChild
(
lineEl
);
allGfmEl
.
appendChild
(
document
.
createTextNode
(
'
\n\n
'
));
}
return
allGfmEl
;
}
}
}
static
transformCodeSelection
(
documentFragment
)
{
static
transformCodeSelection
(
documentFragment
)
{
const
lineEls
=
documentFragment
.
querySelectorAll
(
'
.line
'
);
const
lineEls
=
documentFragment
.
querySelectorAll
(
'
.line
'
);
...
...
app/assets/javascripts/shortcuts_issuable.js
View file @
78e7efae
...
@@ -38,7 +38,7 @@ import './shortcuts_navigation';
...
@@ -38,7 +38,7 @@ import './shortcuts_navigation';
}
}
ShortcutsIssuable
.
prototype
.
replyWithSelectedText
=
function
()
{
ShortcutsIssuable
.
prototype
.
replyWithSelectedText
=
function
()
{
var
quote
,
documentFragment
,
selected
,
separator
;
var
quote
,
documentFragment
,
el
,
selected
,
separator
;
var
replyField
=
$
(
'
.js-main-target-form #note_note
'
);
var
replyField
=
$
(
'
.js-main-target-form #note_note
'
);
documentFragment
=
window
.
gl
.
utils
.
getSelectedFragment
();
documentFragment
=
window
.
gl
.
utils
.
getSelectedFragment
();
...
@@ -47,10 +47,8 @@ import './shortcuts_navigation';
...
@@ -47,10 +47,8 @@ import './shortcuts_navigation';
return
;
return
;
}
}
// If the documentFragment contains more than just Markdown, don't copy as GFM.
el
=
window
.
gl
.
CopyAsGFM
.
transformGFMSelection
(
documentFragment
.
cloneNode
(
true
));
if
(
documentFragment
.
querySelector
(
'
.md, .wiki
'
))
return
;
selected
=
window
.
gl
.
CopyAsGFM
.
nodeToGFM
(
el
);
selected
=
window
.
gl
.
CopyAsGFM
.
nodeToGFM
(
documentFragment
);
if
(
selected
.
trim
()
===
""
)
{
if
(
selected
.
trim
()
===
""
)
{
return
;
return
;
...
...
changelogs/unreleased/dm-copy-gfm-when-parts-of-other-elements-are-selected.yml
0 → 100644
View file @
78e7efae
---
title
:
Copy as GFM even when parts of other elements are selected
merge_request
:
author
:
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