summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-02-23 21:10:28 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-02-23 21:10:28 +0000
commit4e7abe540dbd1d170bfb2b3594e645cbfb48cac3 (patch)
treef3de940e069b4d927acfdf54247c9900113a4c79 /app/assets/javascripts/lib
parentf6b95a66bc12adeb4fac7277d1eb345d9e7819fd (diff)
downloadgitlab-ce-4e7abe540dbd1d170bfb2b3594e645cbfb48cac3.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r--app/assets/javascripts/lib/utils/text_markdown.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/app/assets/javascripts/lib/utils/text_markdown.js b/app/assets/javascripts/lib/utils/text_markdown.js
index ebc118c0d87..83ae7142cf2 100644
--- a/app/assets/javascripts/lib/utils/text_markdown.js
+++ b/app/assets/javascripts/lib/utils/text_markdown.js
@@ -2,6 +2,7 @@
import $ from 'jquery';
import Shortcuts from '~/behaviors/shortcuts/shortcuts';
import { insertText } from '~/lib/utils/common_utils';
+import { ENTER_KEY } from '~/lib/utils/keys';
import axios from '~/lib/utils/axios_utils';
const LINK_TAG_PATTERN = '[{text}](url)';
@@ -520,7 +521,7 @@ function continueOlText(listLineMatch, nextLineMatch) {
function handleContinueList(e, textArea) {
if (!gon.markdown_automatic_lists) return;
- if (!(e.key === 'Enter')) return;
+ if (!(e.key === ENTER_KEY)) return;
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
if (textArea.selectionStart !== textArea.selectionEnd) return;
@@ -577,6 +578,25 @@ function handleContinueList(e, textArea) {
}
}
+/**
+ * Adds a Markdown hard break when `Shift+Enter` is pressed
+ *
+ * @param {Object} e - the event
+ * @param {Object} textArea - the targeted text area
+ */
+function handleHardBreak(e, textArea) {
+ if (!(e.key === ENTER_KEY)) return;
+ if (!e.shiftKey) return;
+ if (e.altKey || e.ctrlKey || e.metaKey) return;
+
+ // prevent unintended line breaks inserted using Japanese IME on MacOS
+ if (compositioningNoteText) return;
+
+ e.preventDefault();
+
+ insertText(textArea, '\\\n');
+}
+
export function keypressNoteText(e) {
const textArea = this;
@@ -584,6 +604,7 @@ export function keypressNoteText(e) {
handleContinueList(e, textArea);
handleSurroundSelectedText(e, textArea);
+ handleHardBreak(e, textArea);
}
export function compositionStartNoteText() {