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.

editor.execCommand("deleteTrailingWhitespace");

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="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.min.js" integrity="..." crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<textarea id='editor'></textarea>
<script>
  var editor = CodeMirror.fromTextArea( document.getElementById( 'editor' ), { ... } )
</script>

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…! : )