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.Editor
@@ -9,10 +10,12 @@
[Parameter, EditorRequired]
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)
{
@@ -29,7 +32,8 @@
AutomaticLayout = true,
FontFamily = "Roboto-mono",
FontSize = 16,
Padding = new EditorPaddingOptions() {
Padding = new EditorPaddingOptions()
{
Top = 10
}
};
@@ -37,14 +41,19 @@
private async Task OnDidChangeModelContent()
{
if (_editor == null) return;
var newValue = await _editor.GetValue();
OnChange(newValue);
}
void IDisposable.Dispose()
{
_editor?.Dispose();
_editor = null;
}
}
<StandaloneCodeEditor
@ref="_editor"
Id="@randomId"
ConstructionOptions="EditorConstructionOptions"
OnDidChangeModelContent="OnDidChangeModelContent"
/>
<StandaloneCodeEditor @ref="_editor" Id="@randomId" ConstructionOptions="EditorConstructionOptions"
OnDidChangeModelContent="OnDidChangeModelContent" />