-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
RichText: selectionChange: bind on focus, unbind on blur #12480
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 |
---|---|---|
|
@@ -93,6 +93,7 @@ export class RichText extends Component { | |
|
||
this.onSetup = this.onSetup.bind( this ); | ||
this.onFocus = this.onFocus.bind( this ); | ||
this.onBlur = this.onBlur.bind( this ); | ||
this.onChange = this.onChange.bind( this ); | ||
this.onDeleteKeyDown = this.onDeleteKeyDown.bind( this ); | ||
this.onKeyDown = this.onKeyDown.bind( this ); | ||
|
@@ -108,7 +109,6 @@ export class RichText extends Component { | |
this.isEmpty = this.isEmpty.bind( this ); | ||
this.valueToFormat = this.valueToFormat.bind( this ); | ||
this.setRef = this.setRef.bind( this ); | ||
this.isActive = this.isActive.bind( this ); | ||
this.valueToEditableHTML = this.valueToEditableHTML.bind( this ); | ||
|
||
this.formatToValue = memize( this.formatToValue.bind( this ), { size: 1 } ); | ||
|
@@ -129,22 +129,10 @@ export class RichText extends Component { | |
this.lastHistoryValue = value; | ||
} | ||
|
||
componentDidMount() { | ||
document.addEventListener( 'selectionchange', this.onSelectionChange ); | ||
} | ||
|
||
componentWillUnmount() { | ||
document.removeEventListener( 'selectionchange', this.onSelectionChange ); | ||
} | ||
|
||
setRef( node ) { | ||
this.editableRef = node; | ||
} | ||
|
||
isActive() { | ||
return this.editableRef === document.activeElement; | ||
} | ||
|
||
/** | ||
* Handles the onSetup event for the TinyMCE component. | ||
* | ||
|
@@ -354,6 +342,12 @@ export class RichText extends Component { | |
if ( unstableOnFocus ) { | ||
unstableOnFocus(); | ||
} | ||
|
||
document.addEventListener( 'selectionchange', this.onSelectionChange ); | ||
} | ||
|
||
onBlur() { | ||
document.removeEventListener( 'selectionchange', this.onSelectionChange ); | ||
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 guess https://codepen.io/aduth/pen/VVqOmq?editors=1111 (In other words, I suspected there could be an issue, but it doesn't appear so) 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. No, it shouldn't, it starts at the |
||
} | ||
|
||
/** | ||
|
@@ -392,11 +386,6 @@ export class RichText extends Component { | |
* Handles the `selectionchange` event: sync the selection to local state. | ||
*/ | ||
onSelectionChange() { | ||
// Ensure it's the active element. This is a global event. | ||
if ( ! this.isActive() ) { | ||
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 think I'd noted it elsewhere, but there's a small difference between Does that sound accurate to you? 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, I think both are checking the 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.
Ah! I am! I still think we should consolidate these, as having multiple concepts of focus here is particularly confusing for me, but it's not relevant to the change proposed here. 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. Yeah, tbh I'm not sure why there's something like 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. My hope was that at some point, we could get rid of the wrapper, at least in the sense of having it be a |
||
return; | ||
} | ||
|
||
const { start, end, formats } = this.createRecord(); | ||
|
||
if ( start !== this.state.start || end !== this.state.end ) { | ||
|
@@ -891,6 +880,7 @@ export class RichText extends Component { | |
onCompositionEnd={ this.onCompositionEnd } | ||
onKeyDown={ this.onKeyDown } | ||
onFocus={ this.onFocus } | ||
onBlur={ this.onBlur } | ||
multilineTag={ this.multilineTag } | ||
multilineWrapperTags={ this.multilineWrapperTags } | ||
setRef={ this.setRef } | ||
|
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.
What of these lines then?
gutenberg/packages/editor/src/components/rich-text/index.js
Lines 394 to 397 in dd331b3
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.
Yeah, we should be able to remove this.