Skip to content

Conversation

@e111077
Copy link
Collaborator

@e111077 e111077 commented Oct 2, 2025

We were guarding firing the change event against programmatic changes from Lit bindings, but we were not guarding against programmatic changes from document switching which is a new concept in CM6.

This PR marks all of our programmatic changes as programmatic and then checks the transactions for a programmatic change. In practice, user changes shouldn't overlap with these transactions.

Also making tabchange event bubble so that users can still determine when tabs have changed since we do not fire change events for that

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where the code editor was incorrectly firing 'change' events for programmatic document switches. The fix replaces a boolean flag with CodeMirror's annotation system to properly track programmatic changes.

  • Introduces _programmaticChange annotation to mark all programmatic edits
  • Removes the _valueChangingFromOutside boolean flag mechanism
  • Updates event firing logic to check transaction annotations instead of the flag

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/playground-code-editor.ts Replaces boolean flag with annotation system for tracking programmatic changes
src/test/playground-code-editor_test.ts Adds comprehensive tests for document switching and change event behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +164 to +166
const editorInternals = editor as unknown as {
_editorView: EditorView;
};
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing private members through type assertion is fragile and could break if the internal structure changes. Consider exposing a test-only public method or using a more robust testing approach.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ehhhhhh i agree but I'm hoping CM7 aint coming soon

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine for this test, but could you also have fired a keyboard event into the widget? Just asking, no change needed.

@e111077 e111077 requested a review from aomarks October 2, 2025 03:01
@e111077
Copy link
Collaborator Author

e111077 commented Oct 2, 2025

cc: @justinfagnani for review as well

@e111077 e111077 force-pushed the programmatic-changes-cm6 branch from ec15c09 to 168a35c Compare October 2, 2025 18:22
Copy link
Contributor

@justinfagnani justinfagnani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments / questions

Comment on lines +164 to +166
const editorInternals = editor as unknown as {
_editorView: EditorView;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine for this test, but could you also have fired a keyboard event into the widget? Just asking, no change needed.

@e111077 e111077 force-pushed the programmatic-changes-cm6 branch from 168a35c to af5b5be Compare October 2, 2025 19:19
@e111077 e111077 force-pushed the programmatic-changes-cm6 branch from af5b5be to e85767a Compare October 2, 2025 19:50
@e111077
Copy link
Collaborator Author

e111077 commented Oct 2, 2025

Seems fine for this test, but could you also have fired a keyboard event into the widget? Just asking, no change needed.

We maybe could – not quite sure what triggers CM6's editor correctly, but we use that internal editorView to test other things like document changes, caching, and to make sure that the editor is actually showing what .value says

@aomarks aomarks merged commit 5741e3c into main Oct 2, 2025
10 checks passed
@aomarks aomarks deleted the programmatic-changes-cm6 branch October 2, 2025 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants