Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

MudText - on ENTER key, determine contents of selected line then act accordingly

$
0
0

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.

  1. If current line contains text then create new line/paragraph as normal.
  2. 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" && ...?    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles