Capturing Ctrl-S doesn't work, opens browser's save dialog

Hi, thanks for this great library!
In my use case, I want to capture Ctrl-S (or Mod-S) to do a “save”/“compile” action.
It seems that Codemirror 5 had this possibility: CodeMirror 5 User Manual

save Ctrl-S (PC), Cmd-S (Mac)
Not defined by the core library, only referred to in key maps. Intended to provide an easy way for user code to define a save command.

How to do this with v6?
I tried

	key: "Mod-S",
	run({ state }) { console.log(state.doc); on_compile(); return true }

but if I press Ctrl+S, it opens the default save dialog of the browser.
How can I do the equivalent of preventDefault for this case, to make my handler work? :slight_smile:

Similarly, can I also do this for Ctrl-L or F5?

Originally I wanted to use Ctrl-Space, but that is already used with Prec.highest by the autocompletion extension, and even if I put my binding also with Prec.highest before basicSetup in the extensions array, it still doesn’t run my handler for some reason.

Use Mod-s instead (Mod-S will only be matched when shift is held).

1 Like

Ah, thanks!
Btw, what about Ctrl-L and F5, can I capture those and prevent the default browser action? :slight_smile:

Not sure, depends on the browser. Try and see.

Hm, but how can I do event.preventDefault(), how can I get access to the event? :slight_smile: