How to execute a StateCommand...?

I want to execute “deleteTrailingWhitespace” (CodeMirror Reference Manual), when the user press Ctrl+S.

I thought the below way, but it doesn’t work.


Could you please give me an advise how to execute “deleteTrailingWhitespace”…?

Thank you.

Import it, and call it with the editor view as only argument.

Thank you so much for your quick response, but sorry for a more low level question.

In my case, I’m using CodeMirror by CDN as following.

<script src="" integrity="..." crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<textarea id='editor'></textarea>
  var editor = CodeMirror.fromTextArea( document.getElementById( 'editor' ), { ... } )

In my situation, is executing “deleteTrailingWhitespace” impossible…?

You seem to be mixing up the version 5 and 6 APIs — the link in the initial post was to the 6.x docs, but fromTextArea doesn’t exist there.

(In general, CodeMirror 6 isn’t really something you’ll want to pull from a CDN, since those tend to duplicate shared dependency packages.)

Thank you for your response…! : )