-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
Focus the end of the previous block before merging content
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,12 +153,8 @@ export default class Editable extends wp.element.Component { | |
if ( this.props.onMerge && event.keyCode === KEYCODE_BACKSPACE && this.isStartOfEditor() ) { | ||
this.onChange(); | ||
this.props.onMerge( this.editor.getContent() ); | ||
|
||
// If merge causes editor to be removed, stop other callbacks from | ||
// trying to handle the event | ||
if ( this.editor.removed ) { | ||
event.stopImmediatePropagation(); | ||
} | ||
event.preventDefault(); | ||
event.stopImmediatePropagation(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
youknowriad
Author
Contributor
|
||
} | ||
} | ||
|
||
|
@@ -266,8 +262,14 @@ export default class Editable extends wp.element.Component { | |
} | ||
|
||
focus() { | ||
if ( this.props.focus ) { | ||
const { focus } = this.props; | ||
if ( focus ) { | ||
this.editor.focus(); | ||
// Offset = -1 means we should focus the end of the editable | ||
if ( focus.offset === -1 ) { | ||
This comment has been minimized.
Sorry, something went wrong.
aduth
Member
|
||
this.editor.selection.select( this.editor.getBody(), true ); | ||
this.editor.selection.collapse( false ); | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import { connect } from 'react-redux'; | ||
import classnames from 'classnames'; | ||
import { Slot } from 'react-slot-fill'; | ||
import { partial } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -63,7 +64,7 @@ class VisualEditorBlock extends wp.element.Component { | |
} | ||
|
||
mergeWithPrevious() { | ||
const { block, previousBlock, onRemove, onChange } = this.props; | ||
const { block, previousBlock, onRemove, onChange, onFocus } = this.props; | ||
|
||
// Do nothing when it's the first block | ||
if ( ! previousBlock ) { | ||
|
@@ -90,6 +91,7 @@ class VisualEditorBlock extends wp.element.Component { | |
|
||
// Calling the merge to update the attributes and remove the block to be merged | ||
const updatedAttributes = previousBlockSettings.merge( previousBlock.attributes, blockWithTheSameType.attributes ); | ||
onFocus( previousBlock.uid, { offset: -1 } ); | ||
onChange( previousBlock.uid, { | ||
attributes: { | ||
...previousBlock.attributes, | ||
|
@@ -174,7 +176,7 @@ class VisualEditorBlock extends wp.element.Component { | |
attributes={ block.attributes } | ||
setAttributes={ this.setAttributes } | ||
insertBlockAfter={ onInsertAfter } | ||
setFocus={ onFocus } | ||
setFocus={ partial( onFocus, block.uid ) } | ||
This comment has been minimized.
Sorry, something went wrong.
aduth
Member
|
||
mergeWithPrevious={ this.mergeWithPrevious } | ||
/> | ||
</div> | ||
|
@@ -247,10 +249,10 @@ export default connect( | |
} ); | ||
}, | ||
|
||
onFocus( config ) { | ||
onFocus( uid, config ) { | ||
dispatch( { | ||
type: 'UPDATE_FOCUS', | ||
uid: ownProps.uid, | ||
uid, | ||
config | ||
} ); | ||
}, | ||
|
I'm curious about this one. What if a block doesn't handle
onMerge
? Does it make sense in that case to prevent default handlers and stop propagation?