Skip to content
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

Option to disable soft new line #433

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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ In this editor we use a pure, deterministic function to convert document state t
* `autoFocus`: Setting this to true will automatically focus input into the editor when the component is mounted
* `placeholder`: A string to use as placeholder text for the `RichTextEditor`.
* `readOnly`: A boolean that determines if the `RichTextEditor` should render static html.
* `enableSoftNewLineByDefault`: Set this to `true` if you wish to use soft line breaks when only pressing the return key. By default, if you press the return/enter key it will create a new text block. If you don't set this value to `true`, the user may use one of several [designated keys](https://github.com/facebook/draft-js/blob/cf9be24e8b14419143f1f01aabc68ed1be2f95e4/src/component/utils/isSoftNewlineEvent.js#L16) while pressing the return key to create a soft new line.
* `disableSoftNewLine`: Set this to `true` if you wish to always to a new text block when pressing the return key. Otherwise, the user may use one of several [designated keys](https://github.com/facebook/draft-js/blob/cf9be24e8b14419143f1f01aabc68ed1be2f95e4/src/component/utils/isSoftNewlineEvent.js#L16) while pressing the return key to create a soft new line.

### EditorValue Class
In Draft.js `EditorState` contains not only the document contents but the entire state of the editor including cursor position and selection. This is helpful for many reasons including undo/redo. To make things easier for you, we have wrapped the state of the editor in an `EditorValue` instance with helpful methods to convert to/from a HTML or Markdown. An instance of this class should be passed to `RichTextEditor` in the `value` prop.
Expand Down
4 changes: 4 additions & 0 deletions src/RichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Props = {
editorStyle?: Object;
toolbarStyle?: Object;
onBlur?: (event: Object) => void;
disableSoftNewLine?: boolean;
};

export default class RichTextEditor extends Component {
Expand Down Expand Up @@ -197,6 +198,9 @@ export default class RichTextEditor extends Component {

// `shift + return` should insert a soft newline.
_handleReturnSoftNewline(event: Object): boolean {
if (this.props.disableSoftNewLine) {
return false;
}
let editorState = this.props.value.getEditorState();
if (isSoftNewlineEvent(event)) {
let selection = editorState.getSelection();
Expand Down