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

Link Format: collapse selection to end after insert #17126

Merged
merged 2 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
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
22 changes: 12 additions & 10 deletions packages/e2e-tests/specs/editor/various/links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ describe( 'Links', () => {

// Click on the Submit button
await page.keyboard.press( 'Enter' );

// Reselect the link.
await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' );
};

it( 'can be edited', async () => {
Expand Down Expand Up @@ -490,13 +493,6 @@ describe( 'Links', () => {
await waitForAutoFocus();
await page.keyboard.type( 'w.org' );

// Insert the link
await page.keyboard.press( 'Enter' );

// Navigate back to the popover
await pressKeyWithModifier( 'primary', 'k' );
await waitForAutoFocus();

// Navigate to and toggle the "Open in new tab" checkbox.
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );
Expand All @@ -508,7 +504,8 @@ describe( 'Links', () => {

// Close dialog. Expect that "Open in new tab" would have been applied
// immediately.
await page.keyboard.press( 'Escape' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Enter' );

expect( await getEditedPostContent() ).toMatchSnapshot();

Expand All @@ -519,9 +516,10 @@ describe( 'Links', () => {
//
// See: https://github.com/WordPress/gutenberg/pull/15573

// Collapse selection.
// Move caret back into the link.
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'ArrowLeft' );

// Edit link.
await pressKeyWithModifier( 'primary', 'k' );
await waitForAutoFocus();
Expand All @@ -532,6 +530,10 @@ describe( 'Links', () => {
await page.keyboard.press( 'Enter' );

// Navigate back to the popover
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowLeft' );

// Navigate back to inputs to verify appears as changed.
await pressKeyWithModifier( 'primary', 'k' );
await waitForAutoFocus();

Expand Down
5 changes: 4 additions & 1 deletion packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ function InlineLinkUI( {
);
onChange( insert( value, toInsert ) );
} else {
onChange( applyFormat( value, format ) );
const newValue = applyFormat( value, format );
newValue.start = newValue.end;
newValue.activeFormats = [];
onChange( newValue );
}

// Focus should only be shifted back to the formatted segment when the
Expand Down