attempting to fix monaco

This commit is contained in:
2024-09-04 14:20:30 -06:00
parent 1f43c6305d
commit 3c86d3be88

View File

@@ -1,4 +1,5 @@
@* @rendermode @(new InteractiveServerRenderMode(prerender: false)) *@
@implements IDisposable
@using BlazorMonaco @using BlazorMonaco
@using BlazorMonaco.Editor @using BlazorMonaco.Editor
@@ -9,10 +10,12 @@
[Parameter, EditorRequired] [Parameter, EditorRequired]
public Action<string> OnChange { get; set; } = default!; public Action<string> OnChange { get; set; } = default!;
private string randomId = "monaco-editor-" + BitConverter.ToString(new byte[16].Select(b => (byte)new Random().Next(256)).ToArray()).Replace("-", "");
private string randomId = "monaco-editor-" + BitConverter.ToString(new byte[16].Select(b => (byte)new
Random().Next(256)).ToArray()).Replace("-", "");
private StandaloneCodeEditor _editor = null!; private StandaloneCodeEditor? _editor = null;
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor) private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
{ {
@@ -29,7 +32,8 @@
AutomaticLayout = true, AutomaticLayout = true,
FontFamily = "Roboto-mono", FontFamily = "Roboto-mono",
FontSize = 16, FontSize = 16,
Padding = new EditorPaddingOptions() { Padding = new EditorPaddingOptions()
{
Top = 10 Top = 10
} }
}; };
@@ -37,14 +41,19 @@
private async Task OnDidChangeModelContent() private async Task OnDidChangeModelContent()
{ {
if (_editor == null) return;
var newValue = await _editor.GetValue(); var newValue = await _editor.GetValue();
OnChange(newValue); OnChange(newValue);
} }
void IDisposable.Dispose()
{
_editor?.Dispose();
_editor = null;
}
} }
<StandaloneCodeEditor
@ref="_editor" <StandaloneCodeEditor @ref="_editor" Id="@randomId" ConstructionOptions="EditorConstructionOptions"
Id="@randomId" OnDidChangeModelContent="OnDidChangeModelContent" />
ConstructionOptions="EditorConstructionOptions"
OnDidChangeModelContent="OnDidChangeModelContent"
/>