Dont show caption placeholder in reading mode.

Make it easier to escape image selected state
This commit is contained in:
Tom Moor 2017-10-01 10:58:20 -07:00
parent abff5aa331
commit cfc9e6fb6b
2 changed files with 25 additions and 10 deletions

View File

@ -30,6 +30,7 @@ class Image extends Component {
const caption = node.data.get('alt');
const src = node.data.get('src');
const active = state.isFocused && state.selection.hasEdgeIn(node);
const showCaption = !readOnly || caption;
return (
<CenteredImage>
@ -40,15 +41,17 @@ class Image extends Component {
active={active}
loading={loading}
/>
<Caption
type="text"
placeholder="Write a caption"
onChange={this.handleChange}
onClick={this.handleClick}
defaultValue={caption}
contentEditable={false}
disabled={readOnly}
/>
{showCaption &&
<Caption
type="text"
placeholder="Write a caption"
onChange={this.handleChange}
onClick={this.handleClick}
defaultValue={caption}
contentEditable={false}
disabled={readOnly}
tabIndex={-1}
/>}
</CenteredImage>
);
}

View File

@ -215,6 +215,19 @@ export default function MarkdownShortcuts() {
return this.onBackspace(ev, state);
if (endOffset !== startBlock.length) return;
// Hitting enter while an image is selected should jump caret below and
// insert a new paragraph
if (startBlock.type === 'image') {
ev.preventDefault();
return state
.transform()
.collapseToEnd()
.insertBlock('paragraph')
.apply();
}
// Hitting enter in a heading or blockquote will split the node at that
// point and make the new node a paragraph
if (
startBlock.type !== 'heading1' &&
startBlock.type !== 'heading2' &&
@ -228,7 +241,6 @@ export default function MarkdownShortcuts() {
}
ev.preventDefault();
return state.transform().splitBlock().setBlock('paragraph').apply();
},