Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: 支持嵌套列表 #485

Merged
merged 1 commit into from
May 20, 2019
Merged
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
10 changes: 10 additions & 0 deletions playground/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class Demo extends React.Component {
console.log(this.state.editorState.toHTML())
}

logRAW = () => {
console.log(this.state.editorState.toRAW())
}

render() {

const { readOnly, editorState } = this.state
Expand All @@ -50,6 +54,12 @@ class Demo extends React.Component {
<div className="demo" id="demo">
<BraftEditor
extendControls={[{
key: 'log-raw',
type: 'button',
text: 'Log RAW',
// disabled: true,
onClick: this.logRAW,
}, {
key: 'log-html',
type: 'button',
text: 'Log HTML',
Expand Down
11 changes: 10 additions & 1 deletion src/configs/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ export const keyCommandHandlers = (command, editorState, editor) => {
}

if (command === 'tab') {

const blockType = ContentUtils.getSelectionBlockType(editorState)

if (blockType === 'code-block') {
editor.setValue(ContentUtils.insertText(editorState, ' '.repeat(editor.editorProps.codeTabIndents)))
return 'handled'
} else if (blockType === 'ordered-list-item' || blockType === 'unordered-list-item') {
const newEditorState = RichUtils.onTab(
event,
editorState,
4,
)
if (newEditorState !== editorState) {
editor.setValue(newEditorState)
}
return 'handled'
} else if (blockType !== 'atomic' && allowIndent && cursorIsAtFirst) {
editor.setValue(ContentUtils.increaseSelectionIndent(editorState))
return 'handled'
Expand Down