-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quote Block: Fixing focus transfer between citation and content #5100
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
.wp-block-quote { | ||
margin: 0; | ||
|
||
cite { | ||
display: block; | ||
} | ||
} | ||
|
||
.wp-block-quote:not(.is-large) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -579,7 +579,7 @@ export class RichText extends Component { | |
const beforeElement = nodeListToReact( beforeNodes, createTinyMCEElement ); | ||
const afterElement = nodeListToReact( afterNodes, createTinyMCEElement ); | ||
|
||
this.props.onSplit( beforeElement, afterElement ); | ||
this.restoreContentAndSplit( beforeElement, afterElement ); | ||
} else { | ||
event.preventDefault(); | ||
this.onCreateUndoLevel(); | ||
|
@@ -638,9 +638,10 @@ export class RichText extends Component { | |
|
||
const beforeElement = nodeListToReact( beforeFragment.childNodes, createTinyMCEElement ); | ||
const afterElement = nodeListToReact( filterEmptyNodes( afterFragment.childNodes ), createTinyMCEElement ); | ||
this.props.onSplit( beforeElement, afterElement, ...blocks ); | ||
|
||
this.restoreContentAndSplit( beforeElement, afterElement, blocks ); | ||
} else { | ||
this.props.onSplit( [], [], ...blocks ); | ||
this.restoreContentAndSplit( [], [], blocks ); | ||
} | ||
} | ||
|
||
|
@@ -686,7 +687,7 @@ export class RichText extends Component { | |
// Splitting into two blocks | ||
this.setContent( this.props.value ); | ||
|
||
this.props.onSplit( | ||
this.restoreContentAndSplit( | ||
nodeListToReact( before, createTinyMCEElement ), | ||
nodeListToReact( after, createTinyMCEElement ) | ||
); | ||
|
@@ -740,7 +741,9 @@ export class RichText extends Component { | |
!! this.editor && | ||
this.props.tagName === prevProps.tagName && | ||
this.props.value !== prevProps.value && | ||
this.props.value !== this.savedContent | ||
this.props.value !== this.savedContent && | ||
! isEqual( this.props.value, prevProps.value ) && | ||
! isEqual( this.props.value, this.savedContent ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the real fix. I removed this as part of #4955 but it's necessary to avoid unnecessarily content updates. I don't see any performance loss in adding this and it could even improve performance because we don't use those TinyMCE functions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @youknowriad I feel like we removed and added this a few times I the last year now. :) Maybe worth leaving a comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I was surprised to see these lines again.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call 👍 |
||
) { | ||
this.updateContent(); | ||
} | ||
|
@@ -796,6 +799,19 @@ export class RichText extends Component { | |
} ) ); | ||
} | ||
|
||
/** | ||
* Calling onSplit means we need to abort the change done by TinyMCE. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand this function. In most places where it's used, we're also calling |
||
* we need to call updateContent to restore the initial content before calling onSplit. | ||
* | ||
* @param {Array} before content before the split position | ||
* @param {Array} after content after the split position | ||
* @param {?Array} blocks blocks to insert at the split position | ||
*/ | ||
restoreContentAndSplit( before, after, blocks ) { | ||
this.updateContent(); | ||
this.props.onSplit( before, after, ...blocks ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, now we have (1) |
||
} | ||
|
||
render() { | ||
const { | ||
tagName: Tagname = 'div', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just increases the click area of the citation to the whole line (width: 100%)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of tells me that we shouldn't be using cite for this... :)