-
Hi, I am trying to use this awesome package within a chat messages. By default lexical seems to treat shift+enter differently than enter. This in a text input feels unusual since usually you would use shift+enter for a newline and enter for sending the message. However in lexical shift+enter will cause that not a new paragraph is created leading to weirdness when trying to add formatting to the text. Is there any way to make shift+enter behave like enter (Especially with RichTextPlugin and the MarkdownShortcutPlugin)? Bonus question would be how I could properly handle "onEnter" for the editor to make it send the message. For reference https://github.com/MTRNord/cetirizine/blob/4765cb4f2017b24360080848b0ad65aa7d3f4665/src/components/input/chat/input.tsx#L132 is the baseline Editor I currently have here. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Seems like this does the trick. Copied from the richtext plugin :) editor.registerCommand<KeyboardEvent | null>(
KEY_ENTER_COMMAND,
(event) => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
if (event !== null) {
// If we have beforeinput, then we can avoid blocking
// the default behavior. This ensures that the iOS can
// intercept that we're actually inserting a paragraph,
// and autocomplete, autocapitalize etc work as intended.
// This can also cause a strange performance issue in
// Safari, where there is a noticeable pause due to
// preventing the key down of enter.
if (
(IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) &&
CAN_USE_BEFORE_INPUT
) {
return false;
}
event.preventDefault();
if (event.shiftKey) {
return editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);
}
}
sendMessage();
return editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);
},
COMMAND_PRIORITY_CRITICAL,
) |
Beta Was this translation helpful? Give feedback.
Seems like this does the trick. Copied from the richtext plugin :)