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

Commit

Permalink
Merge pull request #55 from withspectrum/new-code-block-on-space
Browse files Browse the repository at this point in the history
Create new code block on space
  • Loading branch information
mxstbr authored Apr 15, 2018
2 parents 2a9e3e2 + 96ac1a7 commit 938fdb8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/__test__/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,27 @@ describe("draft-js-markdown-plugin", () => {
expect(subject()).toBe("not-handled");
});
});
it("handles new code block on space", () => {
createMarkdownPlugin.__Rewire__("handleNewCodeBlock", modifierSpy); // eslint-disable-line no-underscore-dangle
currentRawContentState = {
entityMap: {},
blocks: [
{
key: "item1",
text: "```",
type: "unstyled",
depth: 0,
inlineStyleRanges: [],
entityRanges: [],
data: {},
},
],
};
character = " ";
expect(subject()).toBe("handled");
expect(modifierSpy).toHaveBeenCalledTimes(1);
expect(store.setEditorState).toHaveBeenCalledWith(newEditorState);
});
});
describe("handlePastedText", () => {
let pastedText;
Expand Down
13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ function checkCharacterForState(config, editorState, character) {
) {
newEditorState = handleLink(editorState, character);
}
if (
newEditorState === editorState &&
config.features.block.includes("CODE")
) {
const contentState = editorState.getCurrentContent();
const selection = editorState.getSelection();
const key = selection.getStartKey();
const currentBlock = contentState.getBlockForKey(key);
const text = currentBlock.getText();
const type = currentBlock.getType();
if (type !== "code-block" && CODE_BLOCK_REGEX.test(text))
newEditorState = handleNewCodeBlock(editorState);
}
if (editorState === newEditorState) {
newEditorState = handleInlineStyle(
config.features.inline,
Expand Down

0 comments on commit 938fdb8

Please sign in to comment.