diff --git a/packages/slate/src/changes/at-range.js b/packages/slate/src/changes/at-range.js index 6762f83f1..dfb7f28ec 100644 --- a/packages/slate/src/changes/at-range.js +++ b/packages/slate/src/changes/at-range.js @@ -296,8 +296,26 @@ Changes.deleteLineBackwardAtRange = (change, range, options) => { const { startKey, startOffset } = range const startBlock = document.getClosestBlock(startKey) const offset = startBlock.getOffset(startKey) - const o = offset + startOffset + const startWithVoidInline = ( + startBlock.nodes.size > 1 && + startBlock.nodes.get(0).text == '' && + startBlock.nodes.get(1).kind == 'inline' + ) + + let o = offset + startOffset + + // If line starts with an void inline node, the text node inside this inline + // node disturbs the offset. Ignore this inline node and delete it afterwards. + if (startWithVoidInline) { + o -= 1 + } + change.deleteBackwardAtRange(range, o, options) + + // Delete the remaining first inline node if needed. + if (startWithVoidInline) { + change.deleteBackward() + } } /** diff --git a/packages/slate/test/changes/at-current-range/delete-line-backward/inline-middle-emoji.js b/packages/slate/test/changes/at-current-range/delete-line-backward/inline-middle-emoji.js new file mode 100644 index 000000000..f3c6f80e5 --- /dev/null +++ b/packages/slate/test/changes/at-current-range/delete-line-backward/inline-middle-emoji.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function (change) { + change.deleteLineBackward() +} + +export const input = ( + + + + one wo📛rd + + + +) + +export const output = ( + + + + + + + +) diff --git a/packages/slate/test/changes/at-current-range/delete-line-backward/inline-multi-voids.js b/packages/slate/test/changes/at-current-range/delete-line-backward/inline-multi-voids.js new file mode 100644 index 000000000..4ab17db47 --- /dev/null +++ b/packages/slate/test/changes/at-current-range/delete-line-backward/inline-multi-voids.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function (change) { + change.deleteLineBackward() +} + +export const input = ( + + + + 😊 + one + 😊 + two + 😀 + three + + + + +) + +export const output = ( + + + + + + + +) diff --git a/packages/slate/test/changes/at-current-range/delete-line-backward/inline-void-first.js b/packages/slate/test/changes/at-current-range/delete-line-backward/inline-void-first.js new file mode 100644 index 000000000..60535175f --- /dev/null +++ b/packages/slate/test/changes/at-current-range/delete-line-backward/inline-void-first.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function (change) { + change.deleteLineBackward() +} + +export const input = ( + + + + 😊one two three + + + +) + +export const output = ( + + + + + + + +) diff --git a/packages/slate/test/changes/at-current-range/delete-line-backward/text-end.js b/packages/slate/test/changes/at-current-range/delete-line-backward/text-end.js new file mode 100644 index 000000000..2398db8ea --- /dev/null +++ b/packages/slate/test/changes/at-current-range/delete-line-backward/text-end.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function (change) { + change.deleteLineBackward() +} + +export const input = ( + + + + one two three + + + +) + +export const output = ( + + + + + + + +) diff --git a/packages/slate/test/changes/at-current-range/delete-line-backward/word-middle.js b/packages/slate/test/changes/at-current-range/delete-line-backward/word-middle.js new file mode 100644 index 000000000..315dfe2ec --- /dev/null +++ b/packages/slate/test/changes/at-current-range/delete-line-backward/word-middle.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function (change) { + change.deleteLineBackward() +} + +export const input = ( + + + + one two three + + + +) + +export const output = ( + + + + ee + + + +)