Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit b34da34

Browse files
committed
Create new code block on space after ```
1 parent 2a9e3e2 commit b34da34

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ function checkCharacterForState(config, editorState, character) {
109109
) {
110110
newEditorState = handleLink(editorState, character);
111111
}
112+
if (
113+
newEditorState === editorState &&
114+
config.features.block.includes("CODE")
115+
) {
116+
const contentState = editorState.getCurrentContent();
117+
const selection = editorState.getSelection();
118+
const key = selection.getStartKey();
119+
const currentBlock = contentState.getBlockForKey(key);
120+
const text = currentBlock.getText();
121+
const type = currentBlock.getType();
122+
if (type !== "code-block" && CODE_BLOCK_REGEX.test(text))
123+
newEditorState = handleNewCodeBlock(editorState);
124+
}
112125
if (editorState === newEditorState) {
113126
newEditorState = handleInlineStyle(
114127
config.features.inline,

0 commit comments

Comments
 (0)