Skip to content

fix: code fence boundary detection treats closing fences as opening fences#750

Merged
xiaolai merged 1 commit intomainfrom
fix/audit-696
Apr 8, 2026
Merged

fix: code fence boundary detection treats closing fences as opening fences#750
xiaolai merged 1 commit intomainfrom
fix/audit-696

Conversation

@xiaolai
Copy link
Copy Markdown
Owner

@xiaolai xiaolai commented Apr 8, 2026

Closes #696

Summary

  • Added parity-based open/close fence discrimination to getCodeFenceBounds() in sourceSelectOccurrence.ts
  • The backward scan now counts all fence lines above the found line — if the count is odd, the line is a closing fence and the cursor is not inside a code block
  • Added 2 regression tests covering the between-blocks scenario

Test plan

  • New tests pass: pnpm vitest run src/plugins/codemirror/sourceSelectOccurrence.test.ts (14/14)
  • Full gate: pnpm check:all passes (1 pre-existing flaky failure in sourcePeekEditor.test.ts unrelated to this change)

🤖 Generated with Claude Code

…ences in sourceSelectOccurrence (Closes #696)

Add parity-based open/close discrimination to getCodeFenceBounds().
The backward scan now counts all fence lines above the found line —
if the count is odd, the found line is a closing fence and the cursor
is not inside a code block.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xiaolai xiaolai added the audit Codebase audit finding label Apr 8, 2026
@xiaolai
Copy link
Copy Markdown
Owner Author

xiaolai commented Apr 8, 2026

VERIFIED — The audit finding is resolved. The parity check correctly distinguishes closing fences from opening fences by counting prior fence lines (even = opener, odd = closer), which prevents phantom fence boundaries when the cursor is between two code blocks — exactly the root cause described in #696.

@xiaolai xiaolai enabled auto-merge (squash) April 8, 2026 15:13
@xiaolai xiaolai merged commit 52f7db8 into main Apr 8, 2026
8 checks passed
@xiaolai xiaolai deleted the fix/audit-696 branch April 8, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit Codebase audit finding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[audit] codemirror: code fence boundary detection treats closing fences as opening fences in sourceSelectOccurrence

1 participant