Skip to content

Commit 88f190e

Browse files
committed
Clear block type with meta + enter
1 parent bc46be6 commit 88f190e

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@
7575
"decorate-component-with-props": "^1.0.2",
7676
"draft-js": "^0.9.1",
7777
"draft-js-checkable-list-item": "^2.0.2",
78-
"draftjs-utils": "^0.3.2",
79-
"find-with-regex": "^1.0.2",
80-
"marked": "^0.3.6",
8178
"react": "^15.4.1",
8279
"react-dom": "^15.4.1"
8380
}

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import adjustBlockDepth from './modifiers/adjustBlockDepth';
66
import handleBlockType from './modifiers/handleBlockType';
77
import handleInlineStyle from './modifiers/handleInlineStyle';
88
import handleNewCodeBlock from './modifiers/handleNewCodeBlock';
9-
import handleClearBlockType from './modifiers/handleClearBlockType';
9+
import insertEmptyBlock from './modifiers/insertEmptyBlock';
1010

1111
const createMarkdownShortcutsPlugin = () => ({
1212
blockRenderMap,
1313
handleReturn(ev, { setEditorState, getEditorState }) {
1414
const editorState = getEditorState();
1515
let newEditorState = handleNewCodeBlock(editorState);
16-
if (editorState === newEditorState && ev.ctrlKey) {
17-
newEditorState = handleClearBlockType(editorState);
16+
if (editorState === newEditorState && (ev.ctrlKey || ev.shiftKey || ev.metaKey || ev.altKey)) {
17+
newEditorState = insertEmptyBlock(editorState);
1818
}
1919
if (editorState !== newEditorState) {
2020
setEditorState(newEditorState);

src/modifiers/handleClearBlockType.js renamed to src/modifiers/insertEmptyBlock.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import { RichUtils, genKey, ContentBlock, EditorState } from 'draft-js';
1+
import { genKey, ContentBlock, EditorState } from 'draft-js';
22
import { List } from 'immutable';
33

4-
const handleClearBlockType = (editorState) => {
5-
const currentBlockType = RichUtils.getCurrentBlockType(editorState);
4+
const insertEmptyBlock = (editorState) => {
65
const contentState = editorState.getCurrentContent();
76
const selection = editorState.getSelection();
87
const key = selection.getStartKey();
98
const currentBlock = contentState.getBlockForKey(key);
10-
if (['blockquote', 'code-block'].indexOf(currentBlockType) === -1) {
11-
return editorState;
12-
}
139
const emptyBlockKey = genKey();
1410
const emptyBlock = new ContentBlock({
1511
characterList: List(),
@@ -51,4 +47,4 @@ const handleClearBlockType = (editorState) => {
5147
);
5248
};
5349

54-
export default handleClearBlockType;
50+
export default insertEmptyBlock;

0 commit comments

Comments
 (0)