serdarciplak / BlazorMonaco

Blazor component for Microsoft's Monaco Editor which powers Visual Studio Code.
https://serdarciplak.github.io/BlazorMonaco/
MIT License
454 stars 98 forks source link

Change ConstructionOptions #77

Closed pcsolutioncz closed 1 year ago

pcsolutioncz commented 1 year ago

Hi, is it possible to change ConstructionOptions in Blazor after event? I need to change the language in the editor.

Example:

<StandaloneCodeEditor @ref="FragmentCode" Id="Code" ConstructionOptions="EditorOptions" />
@code
{
    private void ChangeLanguage (string lang)
    {
       // Change EditorOptions here.
    }
    private StandaloneEditorConstructionOptions EditorOptions(StandaloneCodeEditor editor)
    {
        return new StandaloneEditorConstructionOptions
        {
            AutomaticLayout = true,
            Language = "html"
        };
    }
}

Thank you David

serdarciplak commented 1 year ago

Hi @pcsolutioncz ConstructionOptions are only for the initial values. You can use the UpdateOptions method of the editor instance to update any options you may need after the initialization.

pcsolutioncz commented 1 year ago

Hi, thank you for the hint, but I can't see a method for changing language in EditorUpdateOptions. Can you send me an example? Thank you David

serdarciplak commented 1 year ago

Hi. You can use the BlazorMonaco.Global.SetModelLanguage() method with the model instance of your editor.

Global.SetModelLanguage(editor.GetModel(), "javascript");

BTW, as BlazorMonaco is just a wrapper for the Monaco Editor JS library, you can use its documentation for reference.