Skip to content

fix: skip auto-formatting JSON inputs#64

Open
Moeblack wants to merge 2 commits intonewtextdoc1111:mainfrom
Moeblack:fix/skip-json-autoformat
Open

fix: skip auto-formatting JSON inputs#64
Moeblack wants to merge 2 commits intonewtextdoc1111:mainfrom
Moeblack:fix/skip-json-autoformat

Conversation

@Moeblack
Copy link
Copy Markdown

@Moeblack Moeblack commented Feb 2, 2026

Summary

  • Skip auto-formatting for JSON-like textarea content to avoid corrupting structural commas in JSON.
  • Add a unit test covering JSON input.

Why

Autocomplete-Plus auto-formatting is designed for comma-separated prompt tags. When users paste JSON into a multiline textarea (e.g. used as structured prompt schema), formatting on blur can remove JSON commas and break the JSON.

Test plan

  • npm test

Avoid corrupting JSON textareas by skipping auto-formatter when the content
looks like JSON. Adds a unit test.
@newtextdoc1111 newtextdoc1111 self-assigned this Feb 17, 2026
Copy link
Copy Markdown
Owner

@newtextdoc1111 newtextdoc1111 left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

Upon reviewing the code, I found that scheduling syntax used by comfyui-prompt-control extension is being incorrectly identified as JSON content. I have added two suggestions as inline comments on the source code. I would appreciate it if you could verify whether these changes work correctly in your environment.

Suggestions

  1. Use JSON.parse for JSON content detection
  2. Add unit tests for prompts containing comfyui-prompt-control scheduling syntax

P.S. About the GitHub Action error, I'll fix it after merging this PR.

Comment thread tests/js/auto-formatter.test.js
Comment thread web/js/auto-formatter.js
Comment thread web/js/auto-formatter.js Outdated
Comment thread web/js/auto-formatter.js Outdated
Apply maintainer suggestions to strictly use JSON.parse for JSON detection. Also update the wordCommaPattern to correctly match non-alphanumeric trailing tokens (e.g. comfyui-prompt-control scheduling syntax), ensuring they are correctly auto-formatted. Add tests for scheduling syntax.
@Moeblack
Copy link
Copy Markdown
Author

Thank you for the review and the suggestions.

I have applied the changes to use \JSON.parse\ for JSON detection and added the unit tests for the \comfyui-prompt-control\ scheduling syntax.

During testing, the scheduling syntax tests initially failed because the original \wordCommaPattern\ (/\w+\s*,/g) did not match the closing bracket ]. I updated the regex to /[^\s,]+\s*,/g\ to ensure these tokens are correctly captured. All tests are now passing.

Please let me know if anything else is needed.

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