supermemo / SuperMemoAssistant.Plugins.EditorPlusPlus

https://www.supermemo.wiki/sma/
MIT License
0 stars 0 forks source link

Paste clipboard as plain-text #2

Open jordancurve opened 4 years ago

jordancurve commented 4 years ago

Chrome and Office have built-in keyboard shortcuts for pasting plain text. It would be convenient if SuperMemo did as well.

alexis- commented 4 years ago

I assume a common scenario you have in mind is copying html content and pasting in plain text into SuperMemo ?

jordancurve commented 4 years ago

Yes.

alexis- commented 4 years ago

Will make it in same plugin as supermemo/SuperMemoAssistant.Plugins.EditorPlusPlus#1 "SuperMemoAssistant.Plugins.EditorPlusPlus" ?

alexis- commented 4 years ago

See supermemo/SuperMemoAssistant#37

alexis- commented 4 years ago

8 Add to advanced pasting

bjsi commented 4 years ago

made a simple attempt at this here: https://github.com/bjsi/SuperMemoAssistant.Plugins.EditorPlusPlus/tree/add-plain-text-paste

alexis- commented 4 years ago

Can you describe your implementation ? How does it work ? (from a user perspective mostly, but also tech if there are interesting bits)

bjsi commented 4 years ago

Basically open an "advanced paste" window with radio dials. Select plain text paste and hit enter. Get text from user's clipboard, remove all HTML tags with HTMLAgilityPack. Finally replace the currently selected text with the filtered clipboard text. For that I used this snippet I took from one of your plugins.

private void PasteText(string text)
{
    IControlHtml ctrlHtml = Svc.SM.UI.ElementWdw.ControlGroup.FocusedControl.AsHtml();

    if (ctrlHtml != null)
    {
      var htmlDoc = ctrlHtml.GetDocument();
      var htmlSelObj = htmlDoc?.selection;

      if (htmlSelObj?.createRange() is IHTMLTxtRange textSel)
        textSel.text = text;
    }
}
alexis- commented 4 years ago

Sounds good. Will your send a PR ?