Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
feat: complete TipTap migration — all views use rich text editor
Gabriel Steind0a028d7d5ee
diff --git a/src/components/notes/NoteEditor.tsx b/src/components/notes/NoteEditor.tsxindex ceecdfb0a..f894fd93c 100644--- a/src/components/notes/NoteEditor.tsx+++ b/src/components/notes/NoteEditor.tsx@@ -1,4 +1,4 @@-import { useState, useRef, useEffect, useLayoutEffect, useMemo, useCallback } from "react";+import { useState, useRef, useEffect, useMemo, useCallback } from "react";import { useTranslation } from "react-i18next";import {Download,@@ -9,8 +9,8 @@ import {Radio,MessageSquareText,} from "lucide-react";-import { MarkdownTextarea } from "../ui/MarkdownTextarea";import { RichTextEditor } from "../ui/RichTextEditor";+import type { Editor } from "@tiptap/react";import { MeetingTranscriptChat } from "./MeetingTranscriptChat";import type { TranscriptSegment } from "../../hooks/useMeetingTranscription";import {@@ -82,70 +82,6 @@ interface DictationRange {committedChars: number;}-interface TextSelectionRange {- start: number;- end: number;-}--interface PendingSelectionRestore extends TextSelectionRange {- version: number;-}--function transformSelectionForReplacement(- selection: TextSelectionRange,- replaceStart: number,- replaceEnd: number,- insertLength: number-): TextSelectionRange {- const replacementEnd = replaceStart + insertLength;-- const overlapsReplacement =- selection.start === selection.end- ? selection.start >= replaceStart && selection.start <= replaceEnd- : selection.start < replaceEnd && selection.end > replaceStart;-- if (overlapsReplacement) {- return { start: replacementEnd, end: replacementEnd };- }-- const delta = insertLength - (replaceEnd - replaceStart);- const shift = (index: number) => {- if (index > replaceEnd) return index + delta;- if (index === replaceEnd) return replacementEnd;- return index;- };-- return {- start: shift(selection.start),- end: shift(selection.end),- };-}--function mapIndexThroughUserEdit(- index: number,- editStart: number,- editEnd: number,- insertLength: number-): number {- const delta = insertLength - (editEnd - editStart);-- if (editStart === editEnd) {- return index < editStart ? index : index + delta;- }-- if (index < editStart) return index;- if (index > editEnd) return index + delta;- return editStart + insertLength;-}--function mapIndexAfterRangeRemoval(index: number, removeStart: number, removeEnd: number): number {- const removedLength = removeEnd - removeStart;-- if (index < removeStart) return index;- if (index > removeEnd) return index - removedLength;- return removeStart;-}-export default function NoteEditor({note,onTitleChange,@@ -175,7 +111,7 @@ export default function NoteEditor({}: NoteEditorProps) {const { t } = useTranslation();const [viewMode, setViewMode] = useState<MeetingViewMode>("raw");- const textareaRef = useRef<HTMLTextAreaElement>(null);+ const editorRef = useRef<Editor | null>(null);const titleRef = useRef<HTMLDivElement>(null);const prevNoteIdRef = useRef<number>(note.id);@@ -198,54 +134,17 @@ export default function NoteEditor({}, []);const cursorPosRef = useRef(0);- const selectionEndRef = useRef(0);const dictationRef = useRef<DictationRange | null>(null);const prevRecordingRef = useRef(false);- const expectedSelectionRef = useRef<TextSelectionRange>({ start: 0, end: 0 });- const selectionVersionRef = useRef(0);- const pendingSelectionRestoreRef = useRef<PendingSelectionRestore | null>(null);- const suppressSelectionCaptureRef = useRef(false);- const beforeInputSelectionRef = useRef<TextSelectionRange | null>(null);const contentRef = useRef(note.content);contentRef.current = note.content;- const syncSelectionRefs = useCallback((start: number, end: number) => {- cursorPosRef.current = start;- selectionEndRef.current = end;- expectedSelectionRef.current = { start, end };- }, []);-- const queueSelectionRestore = useCallback(- (start: number, end: number, version = selectionVersionRef.current) => {- syncSelectionRefs(start, end);- pendingSelectionRestoreRef.current = { start, end, version };- },- [syncSelectionRefs]- );-- const applyProgrammaticSelection = useCallback(- (start: number, end: number) => {- const ta = textareaRef.current;- if (!ta) return;- suppressSelectionCaptureRef.current = true;- ta.setSelectionRange(start, end);- queueMicrotask(() => {- suppressSelectionCaptureRef.current = false;- });- syncSelectionRefs(start, end);- },- [syncSelectionRefs]- );-const commitContentChange = useCallback(- (newContent: string, nextSelection?: TextSelectionRange, selectionVersion?: number) => {- if (nextSelection) {- queueSelectionRestore(nextSelection.start, nextSelection.end, selectionVersion);- }+ (newContent: string) => {contentRef.current = newContent;onContentChange(newContent);},- [onContentChange, queueSelectionRestore]+ [onContentChange]);const replaceContentRange = useCallback(@@ -254,123 +153,12 @@ export default function NoteEditor({const before = currentContent.slice(0, replaceStart);const after = currentContent.slice(replaceEnd);const newContent = before + insertText + after;- const selectionBefore = expectedSelectionRef.current;- const selectionVersion = selectionVersionRef.current;- const nextSelection = transformSelectionForReplacement(- selectionBefore,- replaceStart,- replaceEnd,- insertText.length- );-- commitContentChange(newContent, nextSelection, selectionVersion);+ commitContentChange(newContent);return newContent;},[commitContentChange]);- const reanchorDictationToSelection = useCallback(- (anchorStart: number, anchorEnd: number, selectionVersion: number) => {- const range = dictationRef.current;- if (!range) return;-- if (range.partialStart === range.end) {- range.start = anchorStart;- range.partialStart = anchorStart;- range.end = anchorEnd;- return;- }-- const currentContent = contentRef.current;- const partialText = currentContent.slice(range.partialStart, range.end);-- if (!partialText) {- range.start = anchorStart;- range.partialStart = anchorStart;- range.end = anchorEnd;- return;- }-- const withoutPartial =- currentContent.slice(0, range.partialStart) + currentContent.slice(range.end);- const targetStart = mapIndexAfterRangeRemoval(anchorStart, range.partialStart, range.end);- const targetEnd = mapIndexAfterRangeRemoval(anchorEnd, range.partialStart, range.end);- const newContent =- withoutPartial.slice(0, targetStart) + partialText + withoutPartial.slice(targetEnd);-- const newPartialStart = targetStart;- const newEnd = newPartialStart + partialText.length;-- range.start = newPartialStart;- range.partialStart = newPartialStart;- range.end = newEnd;-- commitContentChange(newContent, { start: newEnd, end: newEnd }, selectionVersion);- },- [commitContentChange]- );-- const captureUserSelection = useCallback(- (start: number, end: number) => {- const prev = expectedSelectionRef.current;- const changed = prev.start !== start || prev.end !== end;-- syncSelectionRefs(start, end);-- if (!changed) return;-- selectionVersionRef.current += 1;-- if (dictationRef.current) {- reanchorDictationToSelection(start, end, selectionVersionRef.current);- }- },- [reanchorDictationToSelection, syncSelectionRefs]- );-- useLayoutEffect(() => {- const pending = pendingSelectionRestoreRef.current;- if (!pending) return;- pendingSelectionRestoreRef.current = null;- if (pending.version !== selectionVersionRef.current) return;- applyProgrammaticSelection(pending.start, pending.end);- }, [note.content, applyProgrammaticSelection]);-- // Capture selection before browser applies user edits so dictation range- // adjustments handle replacements/paste correctly.- useEffect(() => {- const ta = textareaRef.current;- if (!ta) return;- const handler = () => {- if (suppressSelectionCaptureRef.current) return;- beforeInputSelectionRef.current = {- start: ta.selectionStart,- end: ta.selectionEnd,- };- };- ta.addEventListener("beforeinput", handler);- return () => {- ta.removeEventListener("beforeinput", handler);- };- }, [viewMode]);-- // Capture cursor on mouse interaction — click for positioning,- // mouseup for drag-selections (click may not fire if drag distance is large)- useEffect(() => {- const ta = textareaRef.current;- if (!ta) return;- const handler = () => {- if (suppressSelectionCaptureRef.current) return;- captureUserSelection(ta.selectionStart, ta.selectionEnd);- };- ta.addEventListener("click", handler);- ta.addEventListener("mouseup", handler);- return () => {- ta.removeEventListener("click", handler);- ta.removeEventListener("mouseup", handler);- };- }, [captureUserSelection, viewMode]);-const segmentContainerRef = useRef<HTMLDivElement>(null);const [indicatorStyle, setIndicatorStyle] = useState<React.CSSProperties>({ opacity: 0 });@@ -445,16 +233,9 @@ export default function NoteEditor({if (titleRef.current && titleRef.current.textContent !== note.title) {titleRef.current.textContent = note.title || "";}- textareaRef.current?.focus();- if (textareaRef.current) {- const start = textareaRef.current.selectionStart;- const end = textareaRef.current.selectionEnd;- syncSelectionRefs(start, end);- }- pendingSelectionRestoreRef.current = null;- beforeInputSelectionRef.current = null;+ editorRef.current?.commands.focus();}- }, [note.id, isMeetingRecording, syncSelectionRefs]);+ }, [note.id, isMeetingRecording]);useEffect(() => {if (titleRef.current && titleRef.current.textContent !== note.title) {@@ -472,7 +253,7 @@ export default function NoteEditor({const handleTitleKeyDown = useCallback((e: React.KeyboardEvent) => {if (e.key === "Enter") {e.preventDefault();- textareaRef.current?.focus();+ editorRef.current?.commands.focus();}}, []);@@ -483,11 +264,13 @@ export default function NoteEditor({}, []);const handleStartRecording = useCallback(() => {- if (textareaRef.current) {- syncSelectionRefs(textareaRef.current.selectionStart, textareaRef.current.selectionEnd);+ const ed = editorRef.current;+ if (ed) {+ const { from } = ed.state.selection;+ cursorPosRef.current = ed.state.doc.textBetween(0, from, "\n").length;}onStartRecording();- }, [onStartRecording, syncSelectionRefs]);+ }, [onStartRecording]);const prevMeetingRecRef = useRef(false);useEffect(() => {@@ -498,12 +281,11 @@ export default function NoteEditor({useEffect(() => {if (isRecording && !prevRecordingRef.current) {- const selStart = cursorPosRef.current;- const selEnd = selectionEndRef.current;+ const pos = cursorPosRef.current;dictationRef.current = {- start: selStart,- partialStart: selStart,- end: selEnd,+ start: pos,+ partialStart: pos,+ end: pos,committedChars: 0,};if (viewMode === "enhanced") setViewMode("raw");@@ -605,71 +387,33 @@ export default function NoteEditor({prevDictationProcessingRef.current = isProcessing;}, [isProcessing]);- const handleSelect = () => {- if (textareaRef.current && document.activeElement === textareaRef.current) {- if (suppressSelectionCaptureRef.current) return;- captureUserSelection(textareaRef.current.selectionStart, textareaRef.current.selectionEnd);+ const handleSelect = useCallback(() => {+ const ed = editorRef.current;+ if (ed) {+ const { from } = ed.state.selection;+ cursorPosRef.current = ed.state.doc.textBetween(0, from, "\n").length;}- };-- const handleContentChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {- const newValue = e.target.value;-- // Skip no-op changes (e.g. React controlled-component echo during dictation)- if (newValue === note.content) return;-- if (dictationRef.current) {- const beforeInput = beforeInputSelectionRef.current;- beforeInputSelectionRef.current = null;-- if (beforeInput) {- const replacedLength = beforeInput.end - beforeInput.start;- const insertLength = newValue.length - (note.content.length - replacedLength);- const range = dictationRef.current;-- const nextStart = mapIndexThroughUserEdit(- range.start,- beforeInput.start,- beforeInput.end,- insertLength- );- const nextPartialStart = mapIndexThroughUserEdit(- range.partialStart,- beforeInput.start,- beforeInput.end,- insertLength- );- const nextEnd = mapIndexThroughUserEdit(- range.end,- beforeInput.start,- beforeInput.end,- insertLength- );-- range.start = Math.min(nextStart, newValue.length);- range.partialStart = Math.min(Math.max(nextPartialStart, range.start), newValue.length);- range.end = Math.min(Math.max(nextEnd, range.partialStart), newValue.length);- } else {- const delta = newValue.length - note.content.length;- const editPos = e.target.selectionStart - delta;- if (editPos <= dictationRef.current.start) {- dictationRef.current.start += delta;- dictationRef.current.partialStart += delta;- dictationRef.current.end += delta;- } else if (editPos <= dictationRef.current.partialStart) {- dictationRef.current.partialStart += delta;- dictationRef.current.end += delta;- } else if (editPos < dictationRef.current.end) {- dictationRef.current.end += delta;+ }, []);++ const handleContentChange = useCallback(+ (newValue: string) => {+ if (newValue === contentRef.current) return;++ if (dictationRef.current) {+ const delta = newValue.length - contentRef.current.length;+ if (delta !== 0) {+ const range = dictationRef.current;+ range.start = Math.max(0, range.start + delta);+ range.partialStart = Math.max(range.start, range.partialStart + delta);+ range.end = Math.max(range.partialStart, range.end + delta);}}- }- beforeInputSelectionRef.current = null;- contentRef.current = newValue;- onContentChange(newValue);- captureUserSelection(e.target.selectionStart, e.target.selectionEnd);- };+ contentRef.current = newValue;+ onContentChange(newValue);+ },+ [onContentChange]+ );const handleEnhancedChange = useCallback((value: string) => {@@ -832,11 +576,11 @@ export default function NoteEditor({) : viewMode === "enhanced" && enhancement ? (<RichTextEditor value={enhancement.content} onChange={handleEnhancedChange} />) : (- <MarkdownTextarea+ <RichTextEditorvalue={note.content}onChange={handleContentChange}onSelect={handleSelect}- textareaRef={textareaRef}+ editorRef={editorRef}placeholder={t("notes.editor.startWriting")}disabled={actionProcessingState === "processing"}/>diff --git a/src/components/ui/MarkdownTextarea.tsx b/src/components/ui/MarkdownTextarea.tsxdeleted file mode 100644index da3e37f1e..000000000--- a/src/components/ui/MarkdownTextarea.tsx+++ /dev/null@@ -1,478 +0,0 @@-import {- useState,- useRef,- useMemo,- useCallback,- type ReactNode,- type ChangeEvent,- type KeyboardEvent,- type RefObject,-} from "react";-import { cn } from "../lib/utils";--function applyChange(ta: HTMLTextAreaElement, start: number, end: number, insert: string) {- ta.focus();- ta.setSelectionRange(start, end);- document.execCommand("insertText", false, insert);-}--const BULLET_RE = /^(\s*)([-*]) $/;-const BULLET_CONTENT_RE = /^(\s*)([-*]) (.+)$/;-const NUM_RE = /^(\s*)(\d+)\. $/;-const NUM_CONTENT_RE = /^(\s*)(\d+)\. (.+)$/;--interface MarkdownTextareaProps {- value: string;- onChange?: (e: ChangeEvent<HTMLTextAreaElement>) => void;- onSelect?: () => void;- onBlur?: () => void;- placeholder?: string;- className?: string;- disabled?: boolean;- textareaRef?: RefObject<HTMLTextAreaElement | null>;-}--const BULLETS = ["•", "◦", "▸"];-const RE_INLINE_MD = /(\*\*\*(.+?)\*\*\*)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(`([^`]+)`)/g;--function bulletChar(indent: string) {- const level = Math.floor(indent.length / 2);- return BULLETS[Math.min(level, BULLETS.length - 1)];-}--const SYN_ACTIVE = "text-foreground/15";--function parseInline(text: string, lineKey: number, active = false): ReactNode[] {- if (!text) return [];-- const syn = active ? SYN_ACTIVE : "invisible";- const tokens: ReactNode[] = [];- RE_INLINE_MD.lastIndex = 0;- let lastIdx = 0;- let mi = 0;- let m: RegExpExecArray | null;-- while ((m = RE_INLINE_MD.exec(text)) !== null) {- if (m.index > lastIdx) tokens.push(text.slice(lastIdx, m.index));- const k = `${lineKey}-${mi++}`;-- if (m[1]) {- tokens.push(- <span key={k}>- <span className={syn}>{"***"}</span>- <span className="font-semibold italic">{m[2]}</span>- <span className={syn}>{"***"}</span>- </span>- );- } else if (m[3]) {- tokens.push(- <span key={k}>- <span className={syn}>{"**"}</span>- <span className="font-semibold">{m[4]}</span>- <span className={syn}>{"**"}</span>- </span>- );- } else if (m[5]) {- tokens.push(- <span key={k}>- <span className={syn}>{"*"}</span>- <span className="italic">{m[6]}</span>- <span className={syn}>{"*"}</span>- </span>- );- } else if (m[7]) {- tokens.push(- <span key={k}>- <span className={syn}>{"`"}</span>- <span className="bg-foreground/[0.04] dark:bg-white/[0.06] rounded-sm px-px">{m[8]}</span>- <span className={syn}>{"`"}</span>- </span>- );- }-- lastIdx = m.index + m[0].length;- }-- if (lastIdx < text.length) tokens.push(text.slice(lastIdx));- return tokens;-}--function renderOverlay(text: string, cursorLine = -1): ReactNode[] {- if (!text) return [];-- const lines = text.split("\n");- const out: ReactNode[] = [];-- for (let i = 0; i < lines.length; i++) {- if (i > 0) out.push("\n");-- const line = lines[i];- if (!line) continue;-- const active = i === cursorLine;- const syn = active ? SYN_ACTIVE : "invisible";-- // Header- const hm = line.match(/^(#{1,3})\s/);- if (hm) {- const n = hm[1].length;- out.push(- <span key={`l${i}`} className="font-bold">- <span className={syn}>{line.slice(0, n + 1)}</span>- {parseInline(line.slice(n + 1), i, active)}- </span>- );- continue;- }-- // Checkbox: `- [ ] item` or `- [x] item`- const cbm = line.match(/^(\s*)([-*]) (\[[ x]\]) /);- if (cbm) {- const indent = cbm[1];- const marker = cbm[2];- const bracket = cbm[3];- const checked = bracket === "[x]";- const p = cbm[0].length;- const content = line.slice(p);- out.push(- <span key={`l${i}`} className={checked ? "text-foreground/40" : ""}>- {indent}- <span className="relative">- <span className="invisible">{`${marker} ${bracket}`}</span>- <span- className={cn(- "absolute left-0 top-0.5 inline-flex items-center justify-center w-3.5 h-3.5 rounded-sm border text-[9px] leading-none",- checked- ? "bg-primary/80 border-primary/80 text-primary-foreground"- : "border-foreground/25"- )}- >- {checked ? "✓" : ""}- </span>- </span>{" "}- {checked ? (- <span className="line-through">{parseInline(content, i, active)}</span>- ) : (- parseInline(content, i, active)- )}- </span>- );- continue;- }-- // Bullet list: `- item` or `* item` (with optional indent)- const bm = line.match(/^(\s*)([-*])( )/);- if (bm) {- const indent = bm[1];- const marker = bm[2];- const p = bm[0].length;- const content = line.slice(p);- out.push(- <span key={`l${i}`}>- {indent}- <span className="relative">- <span className="invisible">{marker}</span>- <span className="absolute left-0 text-foreground/40">{bulletChar(indent)}</span>- </span>{" "}- {parseInline(content, i, active)}- </span>- );- continue;- }-- // Numbered list: `1. item` (with optional indent)- const nm = line.match(/^(\s*)(\d+)(\.)( ?)/);- if (nm) {- const indent = nm[1];- const num = nm[2];- const dot = nm[3];- const space = nm[4];- const p = nm[0].length;- const content = line.slice(p);- out.push(- <span key={`l${i}`}>- {indent}- <span className="text-foreground/45">{num}</span>- <span className={syn}>{dot}</span>- {space}- {parseInline(content, i, active)}- </span>- );- continue;- }-- // Blockquote- if (line.startsWith("> ")) {- out.push(- <span key={`l${i}`} className="text-foreground/50 italic">- <span className={syn}>{"> "}</span>- {parseInline(line.slice(2), i, active)}- </span>- );- continue;- }-- // Horizontal rule- if (/^(-{3,}|\*{3,}|_{3,})$/.test(line)) {- out.push(- <span key={`l${i}`} className={syn}>- {line}- </span>- );- continue;- }-- // Regular line- const inlined = parseInline(line, i, active);- if (inlined.length === 1 && typeof inlined[0] === "string") {- out.push(inlined[0]);- } else {- out.push(<span key={`l${i}`}>{inlined}</span>);- }- }-- return out;-}--const SHARED = "leading-[1.7] text-sm px-5 py-3 pb-20 whitespace-pre-wrap break-words";--export function MarkdownTextarea({- value,- onChange,- onSelect,- onBlur,- placeholder,- className,- disabled,- textareaRef: externalRef,-}: MarkdownTextareaProps) {- const localRef = useRef<HTMLTextAreaElement>(null);- const overlayRef = useRef<HTMLDivElement>(null);- const taRef = externalRef || localRef;- const [cursorLine, setCursorLine] = useState(-1);-- const syncScroll = useCallback(() => {- if (taRef.current && overlayRef.current) {- overlayRef.current.scrollTop = taRef.current.scrollTop;- }- }, [taRef]);-- const updateCursorLine = useCallback(() => {- const ta = taRef.current;- if (!ta) return;- const line = ta.value.slice(0, ta.selectionStart).split("\n").length - 1;- if (line !== cursorLine) setCursorLine(line);- }, [taRef, cursorLine]);-- const overlay = useMemo(() => renderOverlay(value, cursorLine), [value, cursorLine]);-- const handleKeyDown = useCallback(- (e: KeyboardEvent<HTMLTextAreaElement>) => {- const ta = taRef.current;- if (!ta) return;-- const { selectionStart: start, selectionEnd: end, value: val } = ta;- const before = val.slice(0, start);- const lineStart = before.lastIndexOf("\n") + 1;- const currentLine = before.slice(lineStart);- const lineEndIdx = val.indexOf("\n", start);- const fullLineEnd = lineEndIdx === -1 ? val.length : lineEndIdx;- const hasContentAfter = fullLineEnd > start;-- // Cmd+B → toggle bold- if (e.key === "b" && (e.metaKey || e.ctrlKey)) {- e.preventDefault();- const sel = val.slice(start, end);- if (start === end) {- applyChange(ta, start, end, "****");- ta.setSelectionRange(start + 2, start + 2);- } else if (val.slice(start - 2, start) === "**" && val.slice(end, end + 2) === "**") {- applyChange(ta, start - 2, end + 2, sel);- ta.setSelectionRange(start - 2, start - 2 + sel.length);- } else {- applyChange(ta, start, end, `**${sel}**`);- ta.setSelectionRange(start + 2, end + 2);- }- return;- }-- // Cmd+I → toggle italic- if (e.key === "i" && (e.metaKey || e.ctrlKey)) {- e.preventDefault();- const sel = val.slice(start, end);- if (start === end) {- applyChange(ta, start, end, "**");- ta.setSelectionRange(start + 1, start + 1);- } else if (- val[start - 1] === "*" &&- val[start - 2] !== "*" &&- val[end] === "*" &&- val[end + 1] !== "*"- ) {- applyChange(ta, start - 1, end + 1, sel);- ta.setSelectionRange(start - 1, start - 1 + sel.length);- } else {- applyChange(ta, start, end, `*${sel}*`);- ta.setSelectionRange(start + 1, end + 1);- }- return;- }-- // Cmd+E → toggle inline code- if (e.key === "e" && (e.metaKey || e.ctrlKey)) {- e.preventDefault();- const sel = val.slice(start, end);- if (start === end) {- applyChange(ta, start, end, "``");- ta.setSelectionRange(start + 1, start + 1);- } else if (val[start - 1] === "`" && val[end] === "`") {- applyChange(ta, start - 1, end + 1, sel);- ta.setSelectionRange(start - 1, start - 1 + sel.length);- } else {- applyChange(ta, start, end, `\`${sel}\``);- ta.setSelectionRange(start + 1, end + 1);- }- return;- }-- if (e.key === "Enter" && !e.shiftKey && !e.metaKey && !e.ctrlKey) {- // Empty bullet line → remove prefix, exit list- const emptyBullet = currentLine.match(BULLET_RE);- if (emptyBullet) {- e.preventDefault();- if (hasContentAfter) {- applyChange(ta, start, end, `\n${emptyBullet[1]}${emptyBullet[2]} `);- } else {- applyChange(ta, lineStart, start, "");- }- return;- }-- // Empty numbered line → remove prefix, exit list- const emptyNum = currentLine.match(NUM_RE);- if (emptyNum) {- e.preventDefault();- if (hasContentAfter) {- const next = parseInt(emptyNum[2], 10) + 1;- applyChange(ta, start, end, `\n${emptyNum[1]}${next}. `);- } else {- applyChange(ta, lineStart, start, "");- }- return;- }-- // Bullet with content → continue list- const bullet = currentLine.match(BULLET_CONTENT_RE);- if (bullet) {- e.preventDefault();- applyChange(ta, start, end, `\n${bullet[1]}${bullet[2]} `);- return;- }-- // Numbered list with content → continue with next number- const num = currentLine.match(NUM_CONTENT_RE);- if (num) {- e.preventDefault();- const next = parseInt(num[2], 10) + 1;- applyChange(ta, start, end, `\n${num[1]}${next}. `);- return;- }- }-- if (e.key === "Tab") {- // Multi-line selection → indent/outdent all lines- if (start !== end && val.slice(start, end).includes("\n")) {- const firstLineStart = val.lastIndexOf("\n", start - 1) + 1;- const lastLineEndIdx = val.indexOf("\n", end);- const lastLineEnd = lastLineEndIdx === -1 ? val.length : lastLineEndIdx;- const block = val.slice(firstLineStart, lastLineEnd);- const lines = block.split("\n");-- e.preventDefault();- let newBlock: string;- if (e.shiftKey) {- newBlock = lines.map((l) => l.replace(/^ {1,2}/, "")).join("\n");- } else {- newBlock = lines.map((l) => " " + l).join("\n");- }- applyChange(ta, firstLineStart, lastLineEnd, newBlock);- ta.setSelectionRange(firstLineStart, firstLineStart + newBlock.length);- return;- }-- // Single line list indent/outdent- const isBullet = BULLET_RE.test(currentLine) || BULLET_CONTENT_RE.test(currentLine);- const numMatch = currentLine.match(/^(\s*)(\d+)\. /);-- if (isBullet || numMatch) {- e.preventDefault();- if (e.shiftKey) {- const spaceMatch = currentLine.match(/^ {1,2}/);- if (spaceMatch) {- const removed = spaceMatch[0].length;- applyChange(ta, lineStart, lineStart + removed, "");- ta.setSelectionRange(start - removed, start - removed);- }- } else if (numMatch) {- const prefixEnd = lineStart + numMatch[1].length + numMatch[2].length;- applyChange(ta, lineStart, prefixEnd, numMatch[1] + " 1");- const pos = lineStart + numMatch[1].length + 5;- ta.setSelectionRange(pos, pos);- } else {- applyChange(ta, lineStart, lineStart, " ");- ta.setSelectionRange(start + 2, start + 2);- }- return;- }- }- },- [taRef]- );-- return (- <div className={cn("relative w-full h-full", className)}>- <div- ref={overlayRef}- className={cn(- SHARED,- "absolute inset-0 overflow-hidden pointer-events-none text-foreground/90"- )}- aria-hidden="true"- >- {value ? overlay : <span className="text-foreground/15">{placeholder}</span>}- </div>- <textarea- ref={taRef}- value={value}- onChange={(e) => {- onChange?.(e);- updateCursorLine();- }}- onSelect={() => {- onSelect?.();- updateCursorLine();- }}- onBlur={() => {- onBlur?.();- setCursorLine(-1);- }}- onKeyDown={handleKeyDown}- onKeyUp={updateCursorLine}- onClick={updateCursorLine}- onScroll={syncScroll}- disabled={disabled}- className={cn(- SHARED,- "relative z-[1] w-full h-full bg-transparent! border-none! outline-none! resize-none rounded-none selection:bg-primary/15",- disabled && "pointer-events-none"- )}- style={{- boxShadow: "none",- color: "transparent",- caretColor: "var(--color-foreground)",- WebkitTextFillColor: "transparent",- }}- />- </div>- );-}diff --git a/src/index.css b/src/index.cssindex d8e69aab3..340ea6fd2 100644--- a/src/index.css+++ b/src/index.css@@ -888,6 +888,33 @@ body:has(.agent-overlay-window) #root {caret-color: var(--color-foreground);}+.rich-text-editor-content h1,+.rich-text-editor-content h2,+.rich-text-editor-content h3 {+ position: relative;+}++.rich-text-editor-content h1::before,+.rich-text-editor-content h2::before,+.rich-text-editor-content h3::before {+ position: absolute;+ right: 100%;+ padding-right: 0.375rem;+ font-weight: 400;+ color: oklch(0.5 0 0 / 0.15);+ font-size: 0.75rem;+}++.rich-text-editor-content h1::before {+ content: "#";+}+.rich-text-editor-content h2::before {+ content: "##";+}+.rich-text-editor-content h3::before {+ content: "###";+}+.rich-text-editor-content h1 {font-size: 1.125rem;font-weight: 700;@@ -993,7 +1020,9 @@ body:has(.agent-overlay-window) #root {border: 1.5px solid oklch(0.5 0 0 / 0.25);border-radius: 3px;cursor: pointer;- transition: background-color 100ms, border-color 100ms;+ transition:+ background-color 100ms,+ border-color 100ms;}.rich-text-editor-content ul[data-type="taskList"] li > label input[type="checkbox"]:checked {@@ -1018,6 +1047,12 @@ body:has(.agent-overlay-window) #root {}/* Dark mode adjustments */+.dark .rich-text-editor-content h1::before,+.dark .rich-text-editor-content h2::before,+.dark .rich-text-editor-content h3::before {+ color: oklch(0.7 0 0 / 0.15);+}+.dark .rich-text-editor-content li::marker {color: oklch(0.7 0 0 / 0.4);}