fix: no need to auto pair when * is to open a list item

This commit is contained in:
Jocs 2018-04-19 16:16:14 +08:00
parent 193b62023e
commit 2597c316ed
2 changed files with 12 additions and 9 deletions

View File

@ -340,7 +340,7 @@ const updateCtrl = ContentState => {
} }
return return
} }
// auto pair
if (block && block.text !== text) { if (block && block.text !== text) {
const BRACKET_HASH = { const BRACKET_HASH = {
'{': '}', '{': '}',
@ -351,21 +351,26 @@ const updateCtrl = ContentState => {
'"': '"', '"': '"',
"'": "'" "'": "'"
} }
if (start.key === end.key && start.offset === end.offset && event.type === 'input' && BRACKET_HASH[event.data]) { if (start.key === end.key && start.offset === end.offset && event.type === 'input') {
const { offset } = start const { offset } = start
const { const { autoPairBracket, autoPairMarkdownSyntax, autoPairQuote } = this
autoPairBracket, autoPairMarkdownSyntax, autoPairQuote
} = this
const inputChar = text.charAt(+offset - 1) const inputChar = text.charAt(+offset - 1)
const preInputChar = text.charAt(+offset - 2)
const postInputChar = text.charAt(+offset)
/* eslint-disable no-useless-escape */ /* eslint-disable no-useless-escape */
if ( if (
(autoPairQuote && /["']{1}/.test(inputChar)) || (autoPairQuote && /["']{1}/.test(inputChar)) ||
(autoPairBracket && /[\{\[\(]{1}/.test(inputChar)) || (autoPairBracket && /[\{\[\(]{1}/.test(inputChar)) ||
(autoPairMarkdownSyntax && /[*_]{1}/.test(inputChar)) (autoPairMarkdownSyntax && /[*_]{1}/.test(inputChar))
) { ) {
text = text.substring(0, offset) + BRACKET_HASH[inputChar] + text.substring(offset) text = BRACKET_HASH[event.data]
? text.substring(0, offset) + BRACKET_HASH[inputChar] + text.substring(offset)
: text
} }
/* eslint-ensable no-useless-escape */ /* eslint-ensable no-useless-escape */
if (/\s/.test(event.data) && preInputChar === '*' && postInputChar === '*') {
text = text.substring(0, offset) + text.substring(offset + 1)
}
} }
block.text = text block.text = text
} }

View File

@ -1,7 +1,5 @@
import fileIcons from '../fileIcons' import fileIcons from '../fileIcons'
import { import { CLASS_OR_ID } from '../config'
CLASS_OR_ID
} from '../config'
import './index.css' import './index.css'