BlazorMonaco icon indicating copy to clipboard operation
BlazorMonaco copied to clipboard

JSON Formatting Ignores TabSize in StandaloneEditorConstructionOptions

Open HungTonQuantalytix opened this issue 8 months ago • 0 comments

Description

I'm encountering an issue with JSON formatting in BlazorMonaco. I have defined the StandaloneEditorConstructionOptions as follows:

private StandaloneEditorConstructionOptions ConfigureMonacoEditor(StandaloneCodeEditor editor)
{
    return new StandaloneEditorConstructionOptions
    {
        Language = "json",
        Value = Value,//default value
        TabSize = 8, // Set TabSize to 8
        //other config
        };
}
<StandaloneCodeEditor @ref="codeEditor"
                      ConstructionOptions="ConfigureMonacoEditor"/>
<button onclick="@Format">Format</button>
public async Task Format()
    {
        await codeEditor.Trigger("editor", "editor.action.formatDocument");
    }

I also have a button that formats the content inside the editor. My expectation is that when I click this button, the JSON content inside the editor should be formatted using the TabSize = 8 configuration.

Issue

  • If I initialize the editor without a default Value, formatting works correctly with TabSize = 8.
  • However, if I initialize the editor with a default Value (e.g., a JSON string that was previously formatted with TabSize = 2), I changed the value in editor and then when I trigger the format command, the editor still formats using TabSize = 2 instead of TabSize = 8.

Expected Behavior

  • The formatting should always respect the TabSize defined in StandaloneEditorConstructionOptions, even if the initial Value already has a different formatting style.

Data

{
  "fields": [
    "Loan.Active"
  ],
  "loanFolders": [
    "My Pipeline",
    "Prospects"
  ]
}

Question

  • Is there a way to ensure that JSON formatting respects the configured TabSize = 8, regardless of the initial content?
  • Do I need to explicitly set some additional editor options or call a specific API to enforce this setting?

HungTonQuantalytix avatar Mar 13 '25 11:03 HungTonQuantalytix