Files
SharpIDE/src/SharpIDE.Photino/Components/CodeViewer.razor
Matt Parker [SSW] b78f30af35 monaco
2025-01-10 20:23:38 +10:00

40 lines
888 B
Plaintext

<style>
#my-editor-id {
height: calc(100vh - 100px);
}
</style>
<StandaloneCodeEditor Id="my-editor-id" ConstructionOptions="@EditorConstructionOptions" />
@code {
[Parameter, EditorRequired]
public string FilePath { get; set; } = null!;
private string? _fileContent;
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
{
return new StandaloneEditorConstructionOptions
{
AutomaticLayout = true,
Language = "csharp",
Theme = "vs-dark",
ScrollBeyondLastLine = false,
FontSize = 18,
Value = _fileContent
};
}
protected override async Task OnInitializedAsync()
{
var fileInfo = new FileInfo(FilePath);
if (!fileInfo.Exists)
{
throw new FileNotFoundException($"File not found: {FilePath}");
}
var fileContent = await File.ReadAllTextAsync(FilePath);
_fileContent = fileContent;
}
}