Skip to content
Prev Previous commit
Next Next commit
fix(files): handle ordered-list checkboxes and fix index drift
  • Loading branch information
waleedlatif1 committed Mar 28, 2026
commit a7e9399eeaf75d3cb924749cb67692659b34dfa6
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,13 @@ function PptxPreview({

function toggleMarkdownCheckbox(markdown: string, targetIndex: number, checked: boolean): string {
let currentIndex = 0
return markdown.replace(/^(\s*[-*+]\s+)\[([ xX])\]/gm, (match, prefix: string) => {
if (currentIndex++ !== targetIndex) return match
return `${prefix}[${checked ? 'x' : ' '}]`
})
return markdown.replace(
/^(\s*(?:[-*+]|\d+[.)]) +)\[([ xX])\]/gm,
(match, prefix: string) => {
if (currentIndex++ !== targetIndex) return match
return `${prefix}[${checked ? 'x' : ' '}]`
}
)
}
Comment thread
waleedlatif1 marked this conversation as resolved.

const UnsupportedPreview = memo(function UnsupportedPreview({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ const MarkdownPreview = memo(function MarkdownPreview({
[onCheckboxToggle]
)

const committedCheckboxCount = useMemo(
() => (committed ? (committed.match(/^[ \t]*(?:[-*+]|\d+[.)]) +\[[ xX]\]/gm) ?? []).length : 0),
[committed]
)

checkboxCounterRef.current = 0

const committedMarkdown = useMemo(
Expand All @@ -249,6 +254,8 @@ const MarkdownPreview = memo(function MarkdownPreview({
[committed, components]
Comment thread
waleedlatif1 marked this conversation as resolved.
)
Comment thread
waleedlatif1 marked this conversation as resolved.

checkboxCounterRef.current = committedCheckboxCount
Comment thread
waleedlatif1 marked this conversation as resolved.
Outdated

return (
<div ref={scrollRef} className='h-full overflow-auto p-6'>
{committedMarkdown}
Expand Down
Loading