Skip to content

Commit

Permalink
Merge pull request #29 from SamyPesse/on-tab
Browse files Browse the repository at this point in the history
Rename handleTab to onTab
  • Loading branch information
mxstbr committed Oct 23, 2017
2 parents ace811e + f6f122e commit 9e973b2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Returns true if user is editing a code block. You should call this method to enc

Handle key command for code blocks, returns a new `EditorState` or `null`.

##### `CodeUtils.handleTab(e, editorState)`
##### `CodeUtils.onTab(e, editorState)`

Handle user pressing tab, to insert indentation, it returns a new `EditorState`.

Expand Down Expand Up @@ -99,11 +99,11 @@ class Editor extends React.Component {
return 'handled';
}

handleTab = (evt) => {
onTab = (evt) => {
const { editorState } = this.state;
if (!CodeUtils.hasSelectionInBlock(editorState)) return 'not-handled';

this.onChange(CodeUtils.handleTab(evt, editorState));
this.onChange(CodeUtils.onTab(evt, editorState));
return 'handled';
}

Expand All @@ -115,7 +115,7 @@ class Editor extends React.Component {
keyBindingFn={this.keyBindingFn}
handleKeyCommand={this.handleKeyCommand}
handleReturn={this.handleReturn}
onTab={this.handleTab}
onTab={this.onTab}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class PrismEditorExample extends React.Component {
return;
}

this.onChange(CodeUtils.handleTab(e, editorState));
this.onChange(CodeUtils.onTab(e, editorState));
}

_onReturn(e) {
Expand Down
10 changes: 5 additions & 5 deletions lib/__tests__/handle-tab.test.js → lib/__tests__/onTab.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { EditorState, ContentState, SelectionState } = require('draft-js');
const handleTab = require('../handleTab');
const onTab = require('../onTab');

const toPlainText = editorState =>
editorState.getCurrentContent().getPlainText();
Expand All @@ -14,7 +14,7 @@ it('should insert a tab', () => {
const evt = { preventDefault: jest.fn() };
const initialText = '';
const before = createWithText(initialText);
const after = handleTab(evt, before);
const after = onTab(evt, before);

expect(toPlainText(before)).toEqual(initialText);
expect(toPlainText(after)).toEqual(tabs(1));
Expand All @@ -25,15 +25,15 @@ it('should prevent the default event behavior', () => {
const evt = { preventDefault };
const before = EditorState.createEmpty();

handleTab(evt, before);
onTab(evt, before);
expect(preventDefault).toHaveBeenCalled();
});

it('should add a tab to an existing tab', () => {
const evt = { preventDefault: jest.fn() };
const initialText = tabs(1);
const before = createWithText(initialText);
const after = handleTab(evt, before);
const after = onTab(evt, before);

expect(toPlainText(before)).toEqual(initialText);
expect(toPlainText(after)).toEqual(initialText + tabs(1));
Expand All @@ -57,7 +57,7 @@ it('should replace selected content with the tab', () => {
selection: selectInitialtext.set('focusOffset', initialText.length)
});

const after = handleTab(evt, before);
const after = onTab(evt, before);
expect(toPlainText(before)).toEqual(initialText);
expect(toPlainText(after)).toEqual(tabs(1));
});
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module.exports = {
hasSelectionInBlock: require('./hasSelectionInBlock'),
handleKeyCommand: require('./handleKeyCommand'),
handleReturn: require('./handleReturn'),
handleTab: require('./handleTab')
onTab: require('./onTab')
};
4 changes: 2 additions & 2 deletions lib/handleTab.js → lib/onTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var getIndentation = require('./utils/getIndentation');
* @param {Draft.EditorState} editorState
* @return {Draft.EditorState}
*/
function handleTab(e, editorState) {
function onTab(e, editorState) {
e.preventDefault();

var contentState = editorState.getCurrentContent();
Expand Down Expand Up @@ -42,4 +42,4 @@ function handleTab(e, editorState) {
);
}

module.exports = handleTab;
module.exports = onTab;

0 comments on commit 9e973b2

Please sign in to comment.