Skip to content

Shift-Tab for removing indentation #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ class Editor extends React.Component {
const { editorState } = this.state;
if (!CodeUtils.hasSelectionInBlock(editorState)) return 'not-handled';

this.onChange(CodeUtils.onTab(evt, editorState));
return 'handled';
const newState = CodeUtils.onTab(evt, editorState);
if (newState) {
this.handleChange(newState);
return 'handled';
}

return 'not-handled';
}

render() {
Expand Down
6 changes: 1 addition & 5 deletions lib/handleReturn.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
var Draft = require('draft-js');
var insertNewLine = require('./utils/insertNewLine');

/**
* We split code blocks only if user pressed Cmd+Enter
*
* @param {SyntheticKeyboardEvent} event
* @param {SyntheticKeyboardEvent} e
* @param {Draft.EditorState} editorState
* @return {Draft.EditorState}
*/
function handleReturn(e, editorState) {
var contentState = editorState.getCurrentContent();
var selection = editorState.getSelection();

return insertNewLine(editorState);
}

Expand Down
7 changes: 6 additions & 1 deletion lib/onTab.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
var Draft = require('draft-js');
var getIndentation = require('./utils/getIndentation');
var removeIndent = require('./utils/removeIndent');

// TODO: tab should complete indentation instead of just inserting one

/**
* Handle pressing tab in the editor
*
* @param {SyntheticKeyboardEvent} event
* @param {SyntheticKeyboardEvent} e
* @param {Draft.EditorState} editorState
* @return {Draft.EditorState}
*/
function onTab(e, editorState) {
e.preventDefault();

if (e.shiftKey) {
return removeIndent(editorState);
}

var contentState = editorState.getCurrentContent();
var selection = editorState.getSelection();
var startKey = selection.getStartKey();
Expand Down
1 change: 0 additions & 1 deletion lib/utils/insertNewLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var getIndentForLine = require('./getIndentForLine');
/**
* Insert a new line with right inden
*
* @param {SyntheticKeyboardEvent} event
* @param {Draft.EditorState} editorState
* @return {Draft.EditorState}
*/
Expand Down