Skip to content

Commit

Permalink
feat: 支持嵌套列表 (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind authored and margox committed May 20, 2019
1 parent 9b69291 commit e10a0fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit e10a0fd

Please # to comment.