Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-12-19 00:12:08 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-12-19 00:12:08 +0300
commit2d277754ebd347fd7c98a55d41f6c4de5e9920cc (patch)
tree5491a3e5e3aaffac25152f34f42c9be16e9c285a /app/assets
parent5ba99858f15c33bf96f94cc5e9663f01c3532689 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets')
-rw-r--r--app/assets/javascripts/content_editor/extensions/copy_paste.js34
1 files changed, 19 insertions, 15 deletions
diff --git a/app/assets/javascripts/content_editor/extensions/copy_paste.js b/app/assets/javascripts/content_editor/extensions/copy_paste.js
index d29a407c5ca..23f2da7bc28 100644
--- a/app/assets/javascripts/content_editor/extensions/copy_paste.js
+++ b/app/assets/javascripts/content_editor/extensions/copy_paste.js
@@ -149,21 +149,26 @@ export default Extension.create({
const { clipboardData } = event;
const gfmContent = clipboardData.getData(GFM_FORMAT);
-
- if (gfmContent) {
- return this.editor.commands.pasteContent(gfmContent, true);
- }
-
const textContent = clipboardData.getData(TEXT_FORMAT);
const htmlContent = clipboardData.getData(HTML_FORMAT);
const { from, to } = view.state.selection;
+ const isCodeBlockActive = CODE_BLOCK_NODE_TYPES.some((type) =>
+ this.editor.isActive(type),
+ );
- if (pasteRaw) {
- this.editor.commands.insertContentAt(
- { from, to },
- textContent.replace(/^\s+|\s+$/gm, ''),
- );
+ if (pasteRaw || isCodeBlockActive) {
+ const isMarkdownCodeBlockActive = this.editor.isActive(CodeBlockHighlight.name, {
+ language: 'markdown',
+ });
+
+ const contentToInsert = isMarkdownCodeBlockActive
+ ? gfmContent || textContent
+ : textContent.replace(/^\s+|\s+$/gm, '');
+
+ if (!contentToInsert) return false;
+
+ this.editor.commands.insertContentAt({ from, to }, contentToInsert);
return true;
}
@@ -172,11 +177,6 @@ export default Extension.create({
const vsCodeMeta = hasVsCode ? JSON.parse(clipboardData.getData(VS_CODE_FORMAT)) : {};
const language = vsCodeMeta.mode;
- // if a code block is active, paste as plain text
- if (!textContent || CODE_BLOCK_NODE_TYPES.some((type) => this.editor.isActive(type))) {
- return false;
- }
-
if (hasVsCode) {
return this.editor.commands.pasteContent(
language === 'markdown' ? textContent : `\`\`\`${language}\n${textContent}\n\`\`\``,
@@ -184,6 +184,10 @@ export default Extension.create({
);
}
+ if (gfmContent) {
+ return this.editor.commands.pasteContent(gfmContent, true);
+ }
+
const preStartRegex = /^<pre[^>]*lang="markdown"[^>]*>/;
const preEndRegex = /<\/pre>$/;
const htmlContentWithoutMeta = htmlContent?.replace(/^<meta[^>]*>/, '');