From 3f0f55ff38fd57ea71d33924990d098e5844b418 Mon Sep 17 00:00:00 2001 From: Dundercover Date: Fri, 9 Nov 2018 17:29:22 +0100 Subject: [PATCH] Do not show placeholder when document contains multiple text nodes (#2403) --- packages/slate-react/src/plugins/react.js | 3 +- .../multiple-blocks-with-single-empty-text.js | 46 +++++++++++++++++ .../placeholder/single-block-with-inline.js | 49 +++++++++++++++++++ .../single-block-with-single-empty-text.js | 37 ++++++++++++++ 4 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 packages/slate-react/test/rendering/fixtures/placeholder/multiple-blocks-with-single-empty-text.js create mode 100644 packages/slate-react/test/rendering/fixtures/placeholder/single-block-with-inline.js create mode 100644 packages/slate-react/test/rendering/fixtures/placeholder/single-block-with-single-empty-text.js diff --git a/packages/slate-react/src/plugins/react.js b/packages/slate-react/src/plugins/react.js index a66410ecf..56440bffc 100644 --- a/packages/slate-react/src/plugins/react.js +++ b/packages/slate-react/src/plugins/react.js @@ -120,7 +120,8 @@ function ReactPlugin(options = {}) { when: (editor, node) => node.object === 'document' && node.text === '' && - node.nodes.size === 1, + node.nodes.size === 1 && + node.getTexts().size === 1, }) ) } diff --git a/packages/slate-react/test/rendering/fixtures/placeholder/multiple-blocks-with-single-empty-text.js b/packages/slate-react/test/rendering/fixtures/placeholder/multiple-blocks-with-single-empty-text.js new file mode 100644 index 000000000..ce388d001 --- /dev/null +++ b/packages/slate-react/test/rendering/fixtures/placeholder/multiple-blocks-with-single-empty-text.js @@ -0,0 +1,46 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const props = { + placeholder: 'placeholder text', +} + +export const value = ( + + + + + + + + + + +) + +export const output = ` +
+
+ + + +
+
+
+
+
+
+ + + +
+
+
+
+
+
+` + .split('\n') + .map(l => l.trim()) + .join('') diff --git a/packages/slate-react/test/rendering/fixtures/placeholder/single-block-with-inline.js b/packages/slate-react/test/rendering/fixtures/placeholder/single-block-with-inline.js new file mode 100644 index 000000000..cbd65ed85 --- /dev/null +++ b/packages/slate-react/test/rendering/fixtures/placeholder/single-block-with-inline.js @@ -0,0 +1,49 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const props = { + placeholder: 'placeholder text', +} + +export const value = ( + + + + + + + + + + +) + +export const output = ` +
+
+ + + + + + + + + + + + + + + +
+
+
+
+
+
+` + .split('\n') + .map(l => l.trim()) + .join('') diff --git a/packages/slate-react/test/rendering/fixtures/placeholder/single-block-with-single-empty-text.js b/packages/slate-react/test/rendering/fixtures/placeholder/single-block-with-single-empty-text.js new file mode 100644 index 000000000..5ca925227 --- /dev/null +++ b/packages/slate-react/test/rendering/fixtures/placeholder/single-block-with-single-empty-text.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const props = { + placeholder: 'placeholder text', +} + +export const value = ( + + + + + + + +) + +export const output = ` +
+
+ + + + placeholder text + + +
+
+
+
+
+
+` + .split('\n') + .map(l => l.trim()) + .join('')