Repository navigation
Conversation
Saving a table code block built a regular expression from the block's whole source. On a large table (about 40 KB) V8 throws "Regular expression too large", modifyFile swallows it, and the cell shows the new value while the note never changes. The same pattern started matching at the first table fence in the note, so editing a later block replaced everything from the first block down, and String.replace expanded $`, $& and $' in cell text into other parts of the note. Blocks are now found by a line scan of fences (backtick and tilde, longer closing fences, blocks nested in other fences skipped, list and callout prefixes kept) and matched on their source, with the processor's section line telling identical tables apart. Only the body is replaced and each line keeps its line ending. When no single block matches, nothing is written and a Notice says so, instead of overwriting the first table. The view advances its expected source only after a successful save, and one view's saves run in order. The opening fence is now kept: tablebase and notion-table blocks are no longer renamed to table. Known limits: a fence on the same line as a list marker is not recognized (the save is skipped with a Notice), and indented code is not told apart from list continuation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @yoava! Thank you again for your contribution to TableBase. I really appreciate the work on both PRs and am very glad that you are helping make the project more reliable. Before merging, please bring both PR #7 and PR #9 in line with the project guidelines:
Please also see the related note in PR #7. Thank you again for helping improve TableBase! |
| const lineEnding = lines[block.openLine].endsWith("\r") ? "\r" : ""; | ||
| const bodyLines = newBody.map((line) => `${block.prefix}${line}${lineEnding}`); | ||
| lines.splice(block.openLine + 1, block.closeLine - block.openLine - 1, ...bodyLines); |
There was a problem hiding this comment.
Thank you for improving code block synchronization. Could we preserve the existing line ending for each replaced body line here? Using the opening fence line ending for every new line can normalize a body that contains mixed LF and CRLF endings, creating unrelated changes and noisy diffs. A regression test with mixed line endings would make the intended behavior explicit.
fc93874 to
9542798
Compare
Problem
Editing a cell in a
tablecode block can fail to save, or save over the wrong part of the note.TableSyncService.syncCodeBlockbuilds a regular expression from the block's whole source and runscontent.replacewith it:Regular expression too large.VaultService.modifyFilecatches the error, so the cell shows the new value while the file stays unchanged, with no message.$in cell text corrupts the note. The replacement is a string, so$`,$&and$'expand. A cell containing`$`(a dollar sign in inline code) ends up holding all the text above the table.All four reproduce in Obsidian 1.12 on Linux.
Fix
>prefixes stripped for matching and put back on write.ctx.getSectionInfo(el)decides, and a block at that line that no longer matches is never swapped for another.syncCodeBlockreturns whether it wrote. When no single block matches, nothing is written and aNoticeappears. The view advances its expected source only after a successful save, and one view's saves run in order, so a quick second edit doesn't race the first.Behavior change: the opening fence is kept, so
tablebaseandnotion-tableblocks are no longer renamed totable.Known limits: a fence on the same line as a list marker (
- ```table) is not recognized, so that save is skipped with a notice. Indented code is not told apart from list continuation.Tests
npx vitest run: 350 passed. New cases intests/table-sync-service.test.tscover a large table, multiple blocks,$patterns, no match, identical tables with and without a line hint, fences nested in other code blocks, tilde and longer fences, list and callout prefixes, and CRLF. Run against the old service, 10 of its 13 tests fail. The controller tests cover the return value and save ordering.Checked manually in Obsidian with the built plugin: a 40 KB table saves two edits in a row with only the edited rows changed, editing the second block leaves the first untouched, and a cell with
`$`saves literally.🤖 Generated with Claude Code