Modify editor behavior when quoting a note.

This commit is contained in:
Bojan Mojsilovic 2023-12-29 14:30:32 +01:00
parent a61738c746
commit 29e53c2224

View File

@ -443,12 +443,28 @@ const EditBox: Component<{
}) })
createEffect(() => { createEffect(() => {
if (account?.quotedNote && textArea) { const quote = account?.quotedNote;
setMessage((msg) => `${msg}${account.quotedNote} `); if (!textArea || !quote) return;
let position = textArea.selectionStart;
const isEmptyMessage = message().length === 0;
setMessage((msg) => {
if (isEmptyMessage) return `\r\n\r\n${quote} `;
return msg.slice(0, position) + quote + ' ' + msg.slice(position, msg.length);
});
position = isEmptyMessage ? 0 : position + quote.length + 1;
textArea.value = message(); textArea.value = message();
onExpandableTextareaInput(new InputEvent('input'))
account.actions.quoteNote(undefined); account.actions.quoteNote(undefined);
}
onExpandableTextareaInput(new InputEvent('input'));
textArea.focus();
textArea.selectionEnd = position;
}) })
const onEscape = (e: KeyboardEvent) => { const onEscape = (e: KeyboardEvent) => {