Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CodeEditor): format text only on valid input #4028

Merged
merged 4 commits into from
Mar 18, 2025

Conversation

sfeng-coveo
Copy link
Contributor

Proposed Changes

Currently, the CodeEditor uses the default formatting provided by the Monaco Editor. For json language, the editor inherently relies on vscode-json-languageservice, which does a best-effort formatting of the text regardless whether the JSON is valid or not.

However, in the scenario where the JSON is invalid, we've observed UI issues caused by the formatting, where the mouse pointer is relocated to the end of the text:

13-46-51.mp4

Thus we want to disable the best-effort formatting. This is done by overriding the default formatter with a simple JSON.stringify(JSON.parse(model.getValue()), null, tabSize), which will fail in invalid scenarios and thus does nothing.

Potential Breaking Changes

None since change is behavioral.

Acceptance Criteria

  • The proposed changes are covered by unit tests
  • The potential breaking changes are clearly identified
  • README.md is adjusted to reflect the proposed changes (if relevant)

@sfeng-coveo sfeng-coveo requested a review from a team as a code owner March 17, 2025 17:55
@sfeng-coveo sfeng-coveo requested review from GermainBergeron and gdostie and removed request for a team March 17, 2025 17:55
Copy link

@sfeng-coveo sfeng-coveo changed the title fix(CodeEditor): Override default JSON formatting provider fix(CodeEditor): format text only on valid input Mar 17, 2025
Copy link
Member

@GermainBergeron GermainBergeron left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, it works very well!

@GermainBergeron GermainBergeron merged commit cbc1880 into master Mar 18, 2025
7 checks passed
@GermainBergeron GermainBergeron deleted the fix/code-editor-json-formatting branch March 18, 2025 16:15
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.

2 participants