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
351d5f3e
Commit
351d5f3e
authored
Jun 27, 2018
by
Jan Beckmann
Committed by
Phil Hughes
Jun 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Copying ordered list to new comment becomes unordered"
parent
87f7597a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
1 deletion
+74
-1
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+14
-1
changelogs/unreleased/40484-ordered-lists-copy-gfm.yml
changelogs/unreleased/40484-ordered-lists-copy-gfm.yml
+5
-0
spec/javascripts/behaviors/copy_as_gfm_spec.js
spec/javascripts/behaviors/copy_as_gfm_spec.js
+55
-0
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
351d5f3e
...
@@ -189,12 +189,25 @@ export const getParameterByName = (name, urlToParse) => {
...
@@ -189,12 +189,25 @@ export const getParameterByName = (name, urlToParse) => {
return
decodeURIComponent
(
results
[
2
].
replace
(
/
\+
/g
,
'
'
));
return
decodeURIComponent
(
results
[
2
].
replace
(
/
\+
/g
,
'
'
));
};
};
const
handleSelectedRange
=
(
range
)
=>
{
const
container
=
range
.
commonAncestorContainer
;
// add context to fragment if needed
if
(
container
.
tagName
===
'
OL
'
)
{
const
parentContainer
=
document
.
createElement
(
container
.
tagName
);
parentContainer
.
appendChild
(
range
.
cloneContents
());
return
parentContainer
;
}
return
range
.
cloneContents
();
};
export
const
getSelectedFragment
=
()
=>
{
export
const
getSelectedFragment
=
()
=>
{
const
selection
=
window
.
getSelection
();
const
selection
=
window
.
getSelection
();
if
(
selection
.
rangeCount
===
0
)
return
null
;
if
(
selection
.
rangeCount
===
0
)
return
null
;
const
documentFragment
=
document
.
createDocumentFragment
();
const
documentFragment
=
document
.
createDocumentFragment
();
for
(
let
i
=
0
;
i
<
selection
.
rangeCount
;
i
+=
1
)
{
for
(
let
i
=
0
;
i
<
selection
.
rangeCount
;
i
+=
1
)
{
documentFragment
.
appendChild
(
selection
.
getRangeAt
(
i
).
cloneContents
());
const
range
=
selection
.
getRangeAt
(
i
);
documentFragment
.
appendChild
(
handleSelectedRange
(
range
));
}
}
if
(
documentFragment
.
textContent
.
length
===
0
)
return
null
;
if
(
documentFragment
.
textContent
.
length
===
0
)
return
null
;
...
...
changelogs/unreleased/40484-ordered-lists-copy-gfm.yml
0 → 100644
View file @
351d5f3e
---
title
:
Keep lists ordered when copying only list items
merge_request
:
18522
author
:
Jan Beckmann
type
:
fixed
spec/javascripts/behaviors/copy_as_gfm_spec.js
View file @
351d5f3e
...
@@ -44,4 +44,59 @@ describe('CopyAsGFM', () => {
...
@@ -44,4 +44,59 @@ describe('CopyAsGFM', () => {
callPasteGFM
();
callPasteGFM
();
});
});
});
});
describe
(
'
CopyAsGFM.copyGFM
'
,
()
=>
{
// Stub getSelection to return a purpose-built object.
const
stubSelection
=
(
html
,
parentNode
)
=>
({
getRangeAt
:
()
=>
({
commonAncestorContainer
:
{
tagName
:
parentNode
},
cloneContents
:
()
=>
{
const
fragment
=
document
.
createDocumentFragment
();
const
node
=
document
.
createElement
(
'
div
'
);
node
.
innerHTML
=
html
;
Array
.
from
(
node
.
childNodes
).
forEach
((
item
)
=>
fragment
.
appendChild
(
item
));
return
fragment
;
},
}),
rangeCount
:
1
,
});
const
clipboardData
=
{
setData
()
{},
};
const
simulateCopy
=
()
=>
{
const
e
=
{
originalEvent
:
{
clipboardData
,
},
preventDefault
()
{},
stopPropagation
()
{},
};
CopyAsGFM
.
copyAsGFM
(
e
,
CopyAsGFM
.
transformGFMSelection
);
return
clipboardData
;
};
beforeEach
(()
=>
spyOn
(
clipboardData
,
'
setData
'
));
describe
(
'
list handling
'
,
()
=>
{
it
(
'
uses correct gfm for unordered lists
'
,
()
=>
{
const
selection
=
stubSelection
(
'
<li>List Item1</li><li>List Item2</li>
\n
'
,
'
UL
'
);
spyOn
(
window
,
'
getSelection
'
).
and
.
returnValue
(
selection
);
simulateCopy
();
const
expectedGFM
=
'
- List Item1
\n
- List Item2
'
;
expect
(
clipboardData
.
setData
).
toHaveBeenCalledWith
(
'
text/x-gfm
'
,
expectedGFM
);
});
it
(
'
uses correct gfm for ordered lists
'
,
()
=>
{
const
selection
=
stubSelection
(
'
<li>List Item1</li><li>List Item2</li>
\n
'
,
'
OL
'
);
spyOn
(
window
,
'
getSelection
'
).
and
.
returnValue
(
selection
);
simulateCopy
();
const
expectedGFM
=
'
1. List Item1
\n
1. List Item2
'
;
expect
(
clipboardData
.
setData
).
toHaveBeenCalledWith
(
'
text/x-gfm
'
,
expectedGFM
);
});
});
});
});
});
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