Fix quoting notes

This commit is contained in:
Bojan Mojsilovic 2024-02-02 11:36:00 +01:00
parent 0d85008bcb
commit af2fc9ac76

View File

@ -472,38 +472,44 @@ const EditBox: Component<{
}, 500);
})
createEffect(() => {
const quote = account?.quotedNote;
if (!textArea || !quote) return;
const addQuote = (quote: string | undefined) => {
setMessage((msg) => {
if (!textArea || !quote) return msg;
let position = textArea.selectionStart;
const isEmptyMessage = message().length === 0;
const isEmptyMessage = msg.length === 0;
setMessage((msg) => {
if (isEmptyMessage) return `\r\n\r\n${quote} `;
const newMsg = isEmptyMessage ?
`\r\n\r\n${quote} ` :
msg.slice(0, position) + quote + ' ' + msg.slice(position, msg.length);
return msg.slice(0, position) + quote + ' ' + msg.slice(position, msg.length);
});
position = isEmptyMessage ? 0 : position + quote.length + 1;
textArea.value = message();
account.actions.quoteNote(undefined);
textArea.value = newMsg;
// account.actions.quoteNote(undefined);
onExpandableTextareaInput(new InputEvent('input'));
textArea.focus();
textArea?.focus();
textArea.selectionEnd = position;
return newMsg;
});
};
createEffect(() => {
if (props.open) {
if (account?.quotedNote) {
addQuote(account.quotedNote);
return;
}
const draft = readNoteDraft(account?.publicKey, props.replyToNote?.post.noteId);
setMessage(draft);
if (textArea)
textArea.value = draft;
} else {
account?.actions.quoteNote(undefined)
}
})