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
7e0a4c5e
Commit
7e0a4c5e
authored
May 18, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't wrap pasted code when it's already inside code tags
parent
36ede008
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
+26
-3
app/assets/javascripts/copy_as_gfm.js
app/assets/javascripts/copy_as_gfm.js
+18
-1
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+4
-2
changelogs/unreleased/dm-paste-code-inside-gfm-code.yml
changelogs/unreleased/dm-paste-code-inside-gfm-code.yml
+4
-0
No files found.
app/assets/javascripts/copy_as_gfm.js
View file @
7e0a4c5e
...
...
@@ -299,12 +299,29 @@ class CopyAsGFM {
const
clipboardData
=
e
.
originalEvent
.
clipboardData
;
if
(
!
clipboardData
)
return
;
const
text
=
clipboardData
.
getData
(
'
text/plain
'
);
const
gfm
=
clipboardData
.
getData
(
'
text/x-gfm
'
);
if
(
!
gfm
)
return
;
e
.
preventDefault
();
window
.
gl
.
utils
.
insertText
(
e
.
target
,
gfm
);
window
.
gl
.
utils
.
insertText
(
e
.
target
,
(
textBefore
,
textAfter
)
=>
{
// 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
// or a code block that starts with 3 backticks.
// This logic still holds when there are one or more _closed_ code spans
// or blocks that will have 2 or 6 backticks.
// This will break down when the actual code block contains an uneven
// number of backticks, but this is a rare edge case.
const
backtickMatch
=
textBefore
.
match
(
/`/g
);
const
insideCodeBlock
=
backtickMatch
&&
(
backtickMatch
.
length
%
2
)
===
1
;
if
(
insideCodeBlock
)
{
return
text
;
}
return
gfm
;
});
}
static
transformGFMSelection
(
documentFragment
)
{
...
...
app/assets/javascripts/lib/utils/common_utils.js
View file @
7e0a4c5e
...
...
@@ -198,10 +198,12 @@
const
textBefore
=
value
.
substring
(
0
,
selectionStart
);
const
textAfter
=
value
.
substring
(
selectionEnd
,
value
.
length
);
const
newText
=
textBefore
+
text
+
textAfter
;
const
insertedText
=
text
instanceof
Function
?
text
(
textBefore
,
textAfter
)
:
text
;
const
newText
=
textBefore
+
insertedText
+
textAfter
;
target
.
value
=
newText
;
target
.
selectionStart
=
target
.
selectionEnd
=
selectionStart
+
t
ext
.
length
;
target
.
selectionStart
=
target
.
selectionEnd
=
selectionStart
+
insertedT
ext
.
length
;
// Trigger autosave
$
(
target
).
trigger
(
'
input
'
);
...
...
changelogs/unreleased/dm-paste-code-inside-gfm-code.yml
0 → 100644
View file @
7e0a4c5e
---
title
:
Don't wrap pasted code when it's already inside code tags
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