Skip to content

Switching directly between code blocks leaves inactive blocks unhighlighted in edit mode #7

Closed

Description

@BinaryOutlook

Clicking directly from one syntax-highlighted code block into another leaves the previous block in edit mode without highlighting. Repeating this across blocks can leave several inactive blocks plain-colored until an ordinary paragraph is clicked.

Validated on main at d50e1fd1ad080fadf416098a582fe0a277d1ad43 (package version 0.2.1), 2026-09-16 UTC. Environment: macOS 26.5.2, arm64.

Reproduction

Open this synthetic Markdown in visual mode:

```java
public class Example {
    String value = "hello";
}
```

Between

```javascript
const untouched = 2;
```

After
  1. Observe syntax colors in both blocks.
  2. Click inside the Java block. Its colors disappear as it enters edit mode.
  3. Click directly inside the JavaScript block, without clicking a paragraph first.
  4. Observe the Java block after leaving it.
  5. Click After and compare again.

Expected under the current display/edit model: the newly active block enters edit mode and the previous block returns to highlighted display mode.

Observed:

Action First block Second block
Initial preview Highlighted; display Highlighted; display
Click first code block Plain; edit Highlighted; display
Click directly into second code block Plain; still edit Plain; edit
Click an ordinary paragraph Highlighted; display Highlighted; display

Reproduced in 18 combinations: Java/JavaScript/Python as the first language; Things/GitHub/Night themes; first block at top level or inside a blockquote. No typing was needed. Text remained unchanged, and no JavaScript exceptions occurred. Highlight counts for Java were 4 → 0 → 4 on ordinary paragraph exit, but remained 0 after directly selecting the next block.

Cause and narrow fix direction

The code's display-to-edit click handler calls stopPropagation(). This prevents the enclosing editor's click-outside cleanup from restoring the previous block. In the tested DOM, document.activeElement stays on the outer editor during both code clicks, so the per-code focusout fallback does not restore the previous block either.

When activating a regular code block, explicitly restore other inactive regular code blocks with the existing enterDisplayMode() transition. Review the scope carefully instead of broadly removing event-propagation guards. Regression coverage should include direct clicks across multiple blocks, paragraph exit, keyboard navigation, selection/caret behavior, trailing blank lines, copying, undo/redo, and math/Mermaid interactions.

Scope distinction

Plain text while a block is actively edited is documented current behavior, and existing tests require highlight spans to be absent. Retaining syntax colors during active typing would be a separate enhancement with selection, composition, and undo requirements. This issue concerns restoration of inactive blocks.

Related but distinct: #1 concerns recognizing indented fences; #4 concerns inherited white text and contrast. Fixing either does not repair this edit/display transition.

Validation boundary

Tested production webview HTML/CSS/JavaScript in Chromium using real pointer clicks. VS Code messaging was mocked; the installed extension was not exercised. All reproduction content is synthetic. No product source was changed.

Activity

  1. added
    bug
    on Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions