Skip to content
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

Inline Link: Set link text to post title when post selected from dropdown #12726

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ class InlineLinkUI extends Component {
}
}

onChangeInputValue( inputValue ) {
this.setState( { inputValue } );
onChangeInputValue( inputValue, post ) {
this.setState( { inputValue, post } );
}

setLinkTarget( opensInNewWindow ) {
Expand All @@ -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,
Expand All @@ -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 ) );
Expand Down