Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
7e0a4c5e
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7e0a4c5e
编写于
5月 18, 2017
作者:
D
Douwe Maan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't wrap pasted code when it's already inside code tags
上级
36ede008
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
3 deletion
+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
未找到文件。
app/assets/javascripts/copy_as_gfm.js
浏览文件 @
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
浏览文件 @
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
浏览文件 @
7e0a4c5e
---
title
:
Don't wrap pasted code when it's already inside code tags
merge_request
:
author
:
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录