I'm trying to develop a custom notepad editor. Currently I'm using the MudText component of MudBlazor for this.
The behaviour I'm seeking is that when a user hits ENTER on their keyboard, I want to check the contents of the selected line and run some custom logic in the KeyPress event.
- If current line contains text then create new line/paragraph as normal.
- If current line contains no text then prevent text from being added to the editor and popup a menu at that location instead. Here is some code I was playing with. But could not work it out after that. Any help appreciated.
@code{ string sampleText = "wwswswLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";}<MudTextField T="string" Label="Multiline" KeyDownPreventDefault="_preventDefault" Variant="Variant.Text" Text="@sampleText" Lines="50" AutoGrow="true" Immediate="true" OnKeyDown="@HandleKeyDown" />@code { bool _preventDefault; protected void HandleKeyDown(KeyboardEventArgs e) { _preventDefault = e.Key == "Enter" && ...? }}