Added STRG+S support for editor and better saving
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
@using BlazorMonaco
|
||||
@using Moonlight.App.Services
|
||||
@using Moonlight.App.Services.Interop
|
||||
@using Moonlight.App.Services.Sessions
|
||||
@using Moonlight.Shared.Components.Partials
|
||||
|
||||
@inject SmartTranslateService TranslationService
|
||||
@inject KeyListenerService KeyListenerService
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
<div class="card bg-black rounded">
|
||||
<div class="card-body">
|
||||
<MonacoEditor CssClass="h-100" @ref="Editor" Id="vseditor" ConstructionOptions="(x) => EditorOptions"/>
|
||||
@@ -65,6 +70,16 @@
|
||||
},
|
||||
AutoIndent = true
|
||||
};
|
||||
|
||||
KeyListenerService.KeyPressed += KeyPressed;
|
||||
}
|
||||
|
||||
private async void KeyPressed(object? sender, string e)
|
||||
{
|
||||
if (e == "saveShortcut")
|
||||
{
|
||||
await Submit();
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
@@ -111,4 +126,10 @@
|
||||
{
|
||||
return await Editor.GetValue();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Editor.Dispose();
|
||||
KeyListenerService.KeyPressed -= KeyPressed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
InitialData="@EditorInitialData"
|
||||
Language="@EditorLanguage"
|
||||
OnCancel="() => Cancel()"
|
||||
OnSubmit="(_) => Cancel(true)"
|
||||
OnSubmit="(_) => Save()"
|
||||
HideControls="false">
|
||||
</FileEditor>
|
||||
}
|
||||
@@ -254,6 +254,13 @@ else
|
||||
await InvokeAsync(StateHasChanged);
|
||||
return false;
|
||||
}
|
||||
|
||||
private async void Save()
|
||||
{
|
||||
var data = await Editor.GetData();
|
||||
await Access.Write(EditingFile, data);
|
||||
await ToastService.Success(SmartTranslateService.Translate("Successfully saved file"));
|
||||
}
|
||||
|
||||
private async void Cancel(bool save = false)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user