supermemo/SuperMemoAssistant

How to make a selection of text appear in the Popup window?

candywal opened this issue · 1 comments

This is how you make the selection work in the popup.

private async void OpenPopup()
    {
      // 1) Acquire the selected text from the HTML component, if any
      var ctrlGroup = Svc.SM.UI.ElementWdw.ControlGroup;
      var htmlCtrl = ctrlGroup?.FocusedControl.AsHtml();
      var htmlDoc = htmlCtrl?.GetDocument();
      var sel = htmlDoc?.selection;
      if (!(sel?.createRange() is IHTMLTxtRange textSel))
        return;

      var selText = textSel.text;

      // 2) Show the popup with the acquired text, if successful
      var popUp = new PopUp()
      {
        TheText = selText
      }; 
      
      await Application.Current.Dispatcher.Invoke(async () =>{
        // your code
    
      var res = await Show.Window().For<PopUp>(popUp);

      });
    }

You also need to install the MsHTML from the Nuget Package Manager

Did we discuss this before ? I can't remember what this was about