MCPcopy Create free account
hub / github.com/SamyPesse/draft-js-code / onTab

Function onTab

lib/onTab.js:13–43  ·  view source on GitHub ↗

* Handle pressing tab in the editor * * @param {SyntheticKeyboardEvent} event * @param {Draft.EditorState} editorState * @return {Draft.EditorState}

(e, editorState)

Source from the content-addressed store, hash-verified

11 * @return {Draft.EditorState}
12 */
13function onTab(e, editorState) {
14 e.preventDefault();
15
16 var contentState = editorState.getCurrentContent();
17 var selection = editorState.getSelection();
18 var startKey = selection.getStartKey();
19 var currentBlock = contentState.getBlockForKey(startKey);
20
21 var indentation = getIndentation(currentBlock.getText());
22 var newContentState;
23
24 if (selection.isCollapsed()) {
25 newContentState = Draft.Modifier.insertText(
26 contentState,
27 selection,
28 indentation
29 );
30 } else {
31 newContentState = Draft.Modifier.replaceText(
32 contentState,
33 selection,
34 indentation
35 );
36 }
37
38 return Draft.EditorState.push(
39 editorState,
40 newContentState,
41 'insert-characters'
42 );
43}
44
45module.exports = onTab;

Callers 1

onTab.test.jsFile · 0.85

Calls 1

getIndentationFunction · 0.85

Tested by

no test coverage detected