···9999 e.target._shiftDown = true;
100100 }
101101 if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey && !e.altKey) {
102102+ // Prevent special line break handling if currently a text expander popup is open
103103+ if (this.textarea.hasAttribute('aria-expanded')) return;
102104 if (!this.breakLine()) return; // Nothing changed, let the default handler work.
103105 this.options?.onContentChanged?.(this, e);
104106 e.preventDefault();
···407409 // Find the beginning of the current line.
408410 const lineStart = Math.max(0, value.lastIndexOf('\n', start - 1) + 1);
409411 // Find the end and extract the line.
410410- const lineEnd = value.indexOf('\n', start);
411411- const line = value.slice(lineStart, lineEnd === -1 ? value.length : lineEnd);
412412+ const nextLF = value.indexOf('\n', start);
413413+ const lineEnd = nextLF === -1 ? value.length : nextLF;
414414+ const line = value.slice(lineStart, lineEnd);
412415 // Match any whitespace at the start + any repeatable prefix + exactly one space after.
413413- const prefix = line.match(/^\s*((\d+)[.)]\s|[-*+]\s+(\[[ x]\]\s?)?|(>\s+)+)?/);
416416+ const prefix = line.match(/^\s*((\d+)[.)]\s|[-*+]\s{1,4}\[[ x]\]\s?|[-*+]\s|(>\s?)+)?/);
414417415418 // Defer to browser if we can't do anything more useful, or if the cursor is inside the prefix.
416416- if (!prefix || !prefix[0].length || lineStart + prefix[0].length > start) return false;
419419+ if (!prefix) return false;
420420+ const prefixLength = prefix[0].length;
421421+ if (!prefixLength || lineStart + prefixLength > start) return false;
422422+ // 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.
423423+ // If this is the case do not leave the indentation and continue with the prefix.
424424+ if ((prefixLength % 2 === 1 && /^ +$/.test(prefix[0])) || /^\t+ $/.test(prefix[0])) {
425425+ prefix[0] = prefix[0].slice(0, prefixLength - 1);
426426+ } else if (prefixLength === lineEnd - lineStart) {
427427+ this.textarea.setSelectionRange(lineStart, lineEnd);
428428+ if (!document.execCommand('insertText', false, '\n')) {
429429+ this.textarea.setRangeText('\n');
430430+ }
431431+ return true;
432432+ }
417433418434 // Insert newline + prefix.
419435 let text = `\n${prefix[0]}`;