lk-code / winui.monaco-editor

The Monaco Editor for WinUI 3
MIT License
12 stars 4 forks source link

EditorContent property doesn't update with the editor content #7

Closed LightJack05 closed 11 months ago

LightJack05 commented 11 months ago

Hi,

first of all love this project. Currently trying to implement it in mine: https://github.com/LightJack05/Pyrux/tree/monaco-editor

However, the EditorContent property you implemented in Monaco/MonacoEditor.xaml.cs doesn't update with the editor content when I edit it within the editor control. Most likely the MS implementation assumes that it will not be updated externally, but only through the property itself (the call to SetValue()).

I did try to implement a GetContentAsync Method, and it seems to basically do the trick, but I'm just too unfamiliar with developing custom WinUI controls, and the webview this is based on. 😅

public async Task<string> GetContentAsync()
{
    string command = $"editor.getValue();";

    string contentAsJsRepresentation = await this.MonacoEditorWebView
        .ExecuteScriptAsync(command);
    string content = contentAsJsRepresentation.Substring(1, contentAsJsRepresentation.Length-2);

    return content;
}

Hope you can fix this, or if it's on me, tell me what I'm doing wrong. 😉