Prevent line break on Enter Key

What is the proper way to prevent the “Enter” key from creating a new line (I want to use it to trigger a “submit” button)?

Bind a command to it—keymap.of([{key: "Enter", run: view => { doStuff(); return true }}]) and make sure that keymap has a higher precedence than whatever other bindings for Enter you are including.

1 Like

Perfect, thank you!

Do you have an example of you did that? I tried something like this but the run function never executed

const keyBinding = keymap.of([
	{
		key: "Enter",
		run: (view) => {
			console.log("Enter");
			doStuff();
			return true;
		},
	},
]);
const defaultExtensions = [keyBinding, ELStreamLanguage, baseTheme];```

nevermind, add wrap it with Prec.high solve the problem

1 Like