Skip to content

Commit

Permalink
Fix rebase error
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 22, 2018
1 parent 63fe056 commit a688ac8
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import PositionedAtSelection from './positioned-at-selection';

const stopKeyPropagation = ( event ) => event.stopPropagation();

function getLinkAttributesFromFormat( { attributes: { url = '', target } = {} } = {} ) {
return { url, target };
}

function createLinkFormat( { url, opensInNewWindow } ) {
const format = {
type: 'core/link',
Expand Down Expand Up @@ -56,7 +60,11 @@ const LinkEditor = ( { value, onChangeInputValue, onKeyDown, submitLink, autocom
onKeyDown={ onKeyDown }
onSubmit={ submitLink }
>
<URLInput value={ value } onChange={ onChangeInputValue } />
<URLInput
value={ value }
onChange={ onChangeInputValue }
autocompleteRef={ autocompleteRef }
/>
<IconButton icon="editor-break" label={ __( 'Apply' ) } type="submit" />
</form>
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions */
Expand Down Expand Up @@ -97,7 +105,7 @@ class InlineLinkUI extends Component {
}

static getDerivedStateFromProps( props, state ) {
const { activeAttributes: { url, target } } = props;
const { url, target } = getLinkAttributesFromFormat( props.link );
const opensInNewWindow = target === '_blank';

if ( ! isShowingInput( props, state ) ) {
Expand Down Expand Up @@ -130,12 +138,13 @@ class InlineLinkUI extends Component {
}

setLinkTarget( opensInNewWindow ) {
const { activeAttributes: { url }, value, onChange } = this.props;
const { link, value, onChange } = this.props;

this.setState( { opensInNewWindow } );

// Apply now if URL is not being edited.
if ( ! isShowingInput( this.props, this.state ) ) {
const { url } = getLinkAttributesFromFormat( link );
onChange( applyFormat( value, createLinkFormat( { url, opensInNewWindow } ) ) );
}
}
Expand All @@ -146,14 +155,14 @@ class InlineLinkUI extends Component {
}

submitLink( event ) {
const { isActive, value, onChange, speak } = this.props;
const { link, value, onChange, speak } = this.props;
const { inputValue, opensInNewWindow } = this.state;
const url = prependHTTP( inputValue );
const format = createLinkFormat( { url, opensInNewWindow } );

event.preventDefault();

if ( isCollapsed( value ) && ! isActive ) {
if ( isCollapsed( value ) && link === undefined ) {
const toInsert = applyFormat( create( { text: url } ), format, 0, url.length );
onChange( insert( value, toInsert ) );
} else {
Expand All @@ -162,7 +171,7 @@ class InlineLinkUI extends Component {

this.resetState();

if ( ! isActive ) {
if ( ! link ) {
speak( __( 'Link added.' ), 'assertive' );
}
}
Expand All @@ -186,13 +195,14 @@ class InlineLinkUI extends Component {
}

render() {
const { isActive, activeAttributes: { url }, addingLink, value } = this.props;
const { link, addingLink, value } = this.props;

if ( ! isActive && ! addingLink ) {
if ( ! link && ! addingLink ) {
return null;
}

const { inputValue, opensInNewWindow } = this.state;
const { url } = getLinkAttributesFromFormat( link );
const showInput = isShowingInput( this.props, this.state );

return (
Expand Down

0 comments on commit a688ac8

Please sign in to comment.