From beee3811b861b76d585db05273e4695f1df269cb Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Mon, 20 Aug 2018 13:26:02 +1000 Subject: [PATCH] Fix URL link editing Fixes a bug that prevented the user from selecting a link which has text that looks like a URL and clicking Edit. We accomplish this by distinguishing between editing a link (isEditingLink) and adding a new link (isAddingLink). --- .../rich-text/format-toolbar/index.js | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/editor/src/components/rich-text/format-toolbar/index.js b/packages/editor/src/components/rich-text/format-toolbar/index.js index ea1a0ff185ce6f..3814e2b75678a0 100644 --- a/packages/editor/src/components/rich-text/format-toolbar/index.js +++ b/packages/editor/src/components/rich-text/format-toolbar/index.js @@ -68,6 +68,7 @@ function computeDerivedState( props ) { settingsVisible: false, opensInNewWindow: !! props.formats.link && !! props.formats.link.target, linkValue: '', + isEditingLink: false, }; } @@ -151,8 +152,7 @@ class FormatToolbar extends Component { editLink( event ) { event.preventDefault(); - this.props.onChange( { link: { ...this.props.formats.link, isAdding: true } } ); - this.setState( { linkValue: this.props.formats.link.value } ); + this.setState( { linkValue: this.props.formats.link.value, isEditingLink: true } ); } submitLink( event ) { @@ -165,7 +165,7 @@ class FormatToolbar extends Component { value, } } ); - this.setState( { linkValue: value } ); + this.setState( { linkValue: value, isEditingLink: false } ); if ( ! this.props.formats.link.value ) { this.props.speak( __( 'Link added.' ), 'assertive' ); } @@ -177,7 +177,7 @@ class FormatToolbar extends Component { render() { const { formats, enabledControls = DEFAULT_CONTROLS, customControls = [], selectedNodeId } = this.props; - const { linkValue, settingsVisible, opensInNewWindow } = this.state; + const { linkValue, settingsVisible, opensInNewWindow, isEditingLink } = this.state; const isAddingLink = formats.link && formats.link.isAdding; const toolbarControls = FORMATTING_CONTROLS.concat( customControls ) @@ -202,6 +202,13 @@ class FormatToolbar extends Component { }; } ); + let linkUIToShow = 'none'; + if ( isAddingLink || isEditingLink ) { + linkUIToShow = 'editing'; + } else if ( formats.link ) { + linkUIToShow = 'previewing'; + } + const linkSettings = settingsVisible && (
- { ( isAddingLink || formats.link ) && ( + { linkUIToShow !== 'none' && ( - { isAddingLink && ( - // Disable reason: KeyPress must be suppressed so the block doesn't hide the toolbar - /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ + { linkUIToShow === 'editing' && ( + // Disable reason: KeyPress must be suppressed so the block doesn't hide the toolbar + /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
{ linkSettings }
- /* eslint-enable jsx-a11y/no-noninteractive-element-interactions */ + /* eslint-enable jsx-a11y/no-noninteractive-element-interactions */ ) } - { formats.link && ! isAddingLink && ( - // Disable reason: KeyPress must be suppressed so the block doesn't hide the toolbar - /* eslint-disable jsx-a11y/no-static-element-interactions */ + { linkUIToShow === 'previewing' && ( + // Disable reason: KeyPress must be suppressed so the block doesn't hide the toolbar + /* eslint-disable jsx-a11y/no-static-element-interactions */
{ linkSettings }
- /* eslint-enable jsx-a11y/no-static-element-interactions */ + /* eslint-enable jsx-a11y/no-static-element-interactions */ ) }