p2: add quote and code-block text formatting
All checks were successful
CI / test (push) Successful in 20s

This commit is contained in:
2026-03-08 14:12:12 +03:00
parent 33e467d2a5
commit 07e970e81f
3 changed files with 56 additions and 2 deletions

View File

@@ -872,6 +872,31 @@ export function MessageComposer() {
});
}
function insertQuoteBlock() {
const textarea = textareaRef.current;
if (!textarea) {
return;
}
const start = textarea.selectionStart ?? text.length;
const end = textarea.selectionEnd ?? text.length;
const selected = text.slice(start, end);
const source = selected || "quote";
const quoted = source
.split("\n")
.map((line) => `> ${line}`)
.join("\n");
const nextValue = `${text.slice(0, start)}${quoted}${text.slice(end)}`;
setText(nextValue);
if (activeChatId) {
setDraft(activeChatId, nextValue);
}
requestAnimationFrame(() => {
textarea.focus();
const pos = start + quoted.length;
textarea.setSelectionRange(pos, pos);
});
}
return (
<div className="border-t border-slate-700/50 bg-slate-900/55 p-3">
{activeChatId && replyToByChat[activeChatId] ? (
@@ -950,6 +975,12 @@ export function MessageComposer() {
<button className="rounded px-2 py-1 text-xs hover:bg-slate-800" onClick={() => insertFormatting("`", "`")} type="button" title="Monospace">
M
</button>
<button className="rounded px-2 py-1 text-xs hover:bg-slate-800" onClick={() => insertFormatting("```\n", "\n```", "code")} type="button" title="Code block">
{"</>"}
</button>
<button className="rounded px-2 py-1 text-xs hover:bg-slate-800" onClick={insertQuoteBlock} type="button" title="Quote">
</button>
<button className="rounded px-2 py-1 text-xs hover:bg-slate-800" onClick={insertLink} type="button" title="Link">
🔗
</button>