From fc9c17a36eb056a22355e98e87e635c74849dfa7 Mon Sep 17 00:00:00 2001 From: Eric Binnion Date: Sun, 9 Dec 2018 11:52:06 -0600 Subject: [PATCH] Inline Link: Set link text to post title when post selected from dropdown --- packages/format-library/src/link/inline.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/format-library/src/link/inline.js b/packages/format-library/src/link/inline.js index b007076e8c7f2..e2628f82efd3f 100644 --- a/packages/format-library/src/link/inline.js +++ b/packages/format-library/src/link/inline.js @@ -164,8 +164,8 @@ class InlineLinkUI extends Component { } } - onChangeInputValue( inputValue ) { - this.setState( { inputValue } ); + onChangeInputValue( inputValue, post ) { + this.setState( { inputValue, post } ); } setLinkTarget( opensInNewWindow ) { @@ -192,9 +192,10 @@ class InlineLinkUI extends Component { submitLink( event ) { const { isActive, value, onChange, speak } = this.props; - const { inputValue, opensInNewWindow } = this.state; + const { inputValue, opensInNewWindow, post } = this.state; const url = prependHTTP( inputValue ); const selectedText = getTextContent( slice( value ) ); + const format = createLinkFormat( { url, opensInNewWindow, @@ -204,7 +205,8 @@ class InlineLinkUI extends Component { event.preventDefault(); if ( isCollapsed( value ) && ! isActive ) { - const toInsert = applyFormat( create( { text: url } ), format, 0, url.length ); + const linkText = ( post && post.title ) || url; + const toInsert = applyFormat( create( { text: linkText } ), format, 0, linkText.length ); onChange( insert( value, toInsert ) ); } else { onChange( applyFormat( value, format ) );