summaryrefslogtreecommitdiffstats
path: root/web_src
diff options
context:
space:
mode:
author0ko <0ko@noreply.codeberg.org>2025-01-20 13:51:39 +0100
committer0ko <0ko@noreply.codeberg.org>2025-01-20 13:51:39 +0100
commit0379739ac9cfbbe3ba1e78e70b8a76b2efc72480 (patch)
tree4a406ad4810932a822212e1b2f904d37234388bf /web_src
parentfeat: implement migration of website field from gogs/gitea/github (#6474) (diff)
parentLeave list/quote expanison with double enter (diff)
downloadforgejo-0379739ac9cfbbe3ba1e78e70b8a76b2efc72480.tar.xz
forgejo-0379739ac9cfbbe3ba1e78e70b8a76b2efc72480.zip
Fix mention and emoji expansion & Improve leaving list completion (#6597)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6597 Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Diffstat (limited to 'web_src')
-rw-r--r--web_src/js/features/comp/ComboMarkdownEditor.js24
1 files changed, 20 insertions, 4 deletions
diff --git a/web_src/js/features/comp/ComboMarkdownEditor.js b/web_src/js/features/comp/ComboMarkdownEditor.js
index 8ae5defa47..89a252f6f3 100644
--- a/web_src/js/features/comp/ComboMarkdownEditor.js
+++ b/web_src/js/features/comp/ComboMarkdownEditor.js
@@ -99,6 +99,8 @@ class ComboMarkdownEditor {
e.target._shiftDown = true;
}
if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey && !e.altKey) {
+ // Prevent special line break handling if currently a text expander popup is open
+ if (this.textarea.hasAttribute('aria-expanded')) return;
if (!this.breakLine()) return; // Nothing changed, let the default handler work.
this.options?.onContentChanged?.(this, e);
e.preventDefault();
@@ -407,13 +409,27 @@ class ComboMarkdownEditor {
// Find the beginning of the current line.
const lineStart = Math.max(0, value.lastIndexOf('\n', start - 1) + 1);
// Find the end and extract the line.
- const lineEnd = value.indexOf('\n', start);
- const line = value.slice(lineStart, lineEnd === -1 ? value.length : lineEnd);
+ const nextLF = value.indexOf('\n', start);
+ const lineEnd = nextLF === -1 ? value.length : nextLF;
+ const line = value.slice(lineStart, lineEnd);
// Match any whitespace at the start + any repeatable prefix + exactly one space after.
- const prefix = line.match(/^\s*((\d+)[.)]\s|[-*+]\s+(\[[ x]\]\s?)?|(>\s+)+)?/);
+ const prefix = line.match(/^\s*((\d+)[.)]\s|[-*+]\s{1,4}\[[ x]\]\s?|[-*+]\s|(>\s?)+)?/);
// Defer to browser if we can't do anything more useful, or if the cursor is inside the prefix.
- if (!prefix || !prefix[0].length || lineStart + prefix[0].length > start) return false;
+ if (!prefix) return false;
+ const prefixLength = prefix[0].length;
+ if (!prefixLength || lineStart + prefixLength > start) return false;
+ // If the prefix is just indentation (which should always be an even number of spaces or tabs), check if a single whitespace is added to the end of the line.
+ // If this is the case do not leave the indentation and continue with the prefix.
+ if ((prefixLength % 2 === 1 && /^ +$/.test(prefix[0])) || /^\t+ $/.test(prefix[0])) {
+ prefix[0] = prefix[0].slice(0, prefixLength - 1);
+ } else if (prefixLength === lineEnd - lineStart) {
+ this.textarea.setSelectionRange(lineStart, lineEnd);
+ if (!document.execCommand('insertText', false, '\n')) {
+ this.textarea.setRangeText('\n');
+ }
+ return true;
+ }
// Insert newline + prefix.
let text = `\n${prefix[0]}`;