Skip to content

Commit

Permalink
Feature: ability to insert an empty line between elements #33
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Apr 8, 2018
1 parent bc0230d commit d73604a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
49 changes: 45 additions & 4 deletions src/editor/contentState/arrowCtrl.js
Expand Up @@ -119,7 +119,7 @@ const arrowCtrl = ContentState => {
(event.key === EVENT_KEYS.ArrowLeft && isCursorAtBegin(cm) && preBlock)
) {
activeBlock = preBlock
if (preBlock.type === 'pre') {
if (/^(?:pre|th|td)$/.test(preBlock.type)) {
activeBlock = this.createBlock('p')
activeBlock.temp = true
this.insertBefore(activeBlock, anchorBlock)
Expand All @@ -134,7 +134,7 @@ const arrowCtrl = ContentState => {
) {
if (nextBlock) {
activeBlock = nextBlock
if (nextBlock.type === 'pre') {
if (/^(?:pre|th|td)$/.test(nextBlock.type)) {
activeBlock = this.createBlock('p')
activeBlock.temp = true
this.insertAfter(activeBlock, anchorBlock)
Expand All @@ -161,7 +161,46 @@ const arrowCtrl = ContentState => {
}
}

this.render()
return this.render()
}
} else if (/th|td/.test(block.type)) {
let activeBlock
const anchorBlock = this.getParent(this.getParent(this.getParent(this.getParent(block))))

if (
(block.type === 'th' && preBlock && /^(?:pre|td)$/.test(preBlock.type) && event.key === EVENT_KEYS.ArrowUp) ||
(block.type === 'th' && preBlock && /^(?:pre|td)$/.test(preBlock.type) && event.key === EVENT_KEYS.ArrowLeft && left === 0)
) {
activeBlock = this.createBlock('p')
activeBlock.temp = true
this.insertBefore(activeBlock, anchorBlock)
}

if (
(block.type === 'td' && nextBlock && /^(?:pre|th)$/.test(nextBlock.type) && event.key === EVENT_KEYS.ArrowDown) ||
(block.type === 'td' && nextBlock && /^(?:pre|th)$/.test(nextBlock.type) && event.key === EVENT_KEYS.ArrowRight && right === 0)
) {
activeBlock = this.createBlock('p')
activeBlock.temp = true
this.insertAfter(activeBlock, anchorBlock)
}

if (activeBlock) {
event.preventDefault()
const offset = 0
const key = activeBlock.key
this.cursor = {
start: {
key,
offset
},
end: {
key,
offset
}
}

return this.render()
}
} else if (
(preBlock && preBlock.type === 'pre' && event.key === EVENT_KEYS.ArrowUp) ||
Expand All @@ -188,7 +227,9 @@ const arrowCtrl = ContentState => {
end: { key, offset }
}
return this.render()
} else if (
}

if (
(event.key === EVENT_KEYS.ArrowUp) ||
(event.key === EVENT_KEYS.ArrowLeft && start.offset === 0)
) {
Expand Down
5 changes: 2 additions & 3 deletions src/editor/contentState/updateCtrl.js
Expand Up @@ -339,8 +339,7 @@ const updateCtrl = ContentState => {
'*': '*',
'_': '_',
'"': '"',
"'": "'",
'`': '`'
"'": "'"
}
if (start.key === end.key && start.offset === end.offset && event.type === 'input' && BRACKET_HASH[event.data]) {
const { offset } = start
Expand All @@ -350,7 +349,7 @@ const updateCtrl = ContentState => {
const inputChar = text.charAt(+offset - 1)
/* eslint-disable no-useless-escape */
if (
(autoPairQuote && /["'`]{1}/.test(inputChar)) ||
(autoPairQuote && /["']{1}/.test(inputChar)) ||
(autoPairBracket && /[\{\[\(]{1}/.test(inputChar)) ||
(autoPairMarkdownSyntax && /[*_]{1}/.test(inputChar))
) {
Expand Down

0 comments on commit d73604a

Please sign in to comment.