keep indent on enter

This commit is contained in:
LenAnderson 2024-07-04 12:20:58 -04:00
parent fcf1830887
commit 92f4402b63

View File

@ -354,6 +354,21 @@ export class QuickReply {
message.selectionStart = start - 1;
message.selectionEnd = end - count;
updateSyntax();
} else if (evt.key == 'Enter' && !evt.ctrlKey && !evt.shiftKey && !evt.altKey) {
evt.stopImmediatePropagation();
evt.stopPropagation();
evt.preventDefault();
const start = message.selectionStart;
const end = message.selectionEnd;
const lineStart = message.value.lastIndexOf('\n', start - 1);
const indent = /^(\s*)/.exec(message.value.slice(lineStart).replace(/^\n*/, ''))[1] ?? '';
const x = message.value.slice(0, start);
const y = message.value.slice(end);
const z = message.value.slice(lineStart);
message.value = `${message.value.slice(0, start)}\n${indent}${message.value.slice(end)}`;
message.selectionStart = start + 1 + indent.length;
message.selectionEnd = message.selectionStart;
updateSyntax();
} else if (evt.key == 'Enter' && evt.ctrlKey && !evt.shiftKey && !evt.altKey) {
evt.stopPropagation();
evt.preventDefault();