Skip to content

Commit a7e9399

Browse files
committed
fix(files): handle ordered-list checkboxes and fix index drift
1 parent 11aea6b commit a7e9399

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/file-viewer.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,13 @@ function PptxPreview({
716716

717717
function toggleMarkdownCheckbox(markdown: string, targetIndex: number, checked: boolean): string {
718718
let currentIndex = 0
719-
return markdown.replace(/^(\s*[-*+]\s+)\[([ xX])\]/gm, (match, prefix: string) => {
720-
if (currentIndex++ !== targetIndex) return match
721-
return `${prefix}[${checked ? 'x' : ' '}]`
722-
})
719+
return markdown.replace(
720+
/^(\s*(?:[-*+]|\d+[.)]) +)\[([ xX])\]/gm,
721+
(match, prefix: string) => {
722+
if (currentIndex++ !== targetIndex) return match
723+
return `${prefix}[${checked ? 'x' : ' '}]`
724+
}
725+
)
723726
}
724727

725728
const UnsupportedPreview = memo(function UnsupportedPreview({

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/preview-panel.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ const MarkdownPreview = memo(function MarkdownPreview({
237237
[onCheckboxToggle]
238238
)
239239

240+
const committedCheckboxCount = useMemo(
241+
() => (committed ? (committed.match(/^[ \t]*(?:[-*+]|\d+[.)]) +\[[ xX]\]/gm) ?? []).length : 0),
242+
[committed]
243+
)
244+
240245
checkboxCounterRef.current = 0
241246

242247
const committedMarkdown = useMemo(
@@ -249,6 +254,8 @@ const MarkdownPreview = memo(function MarkdownPreview({
249254
[committed, components]
250255
)
251256

257+
checkboxCounterRef.current = committedCheckboxCount
258+
252259
return (
253260
<div ref={scrollRef} className='h-full overflow-auto p-6'>
254261
{committedMarkdown}

0 commit comments

Comments
 (0)