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

[RNMobile] Fix undo/redo history when inserting a link configured to open in a new tab #50460

Merged
merged 14 commits into from
May 24, 2023
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
1 change: 1 addition & 0 deletions packages/format-library/src/link/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const link = {
attributes: {
url: 'href',
target: 'target',
rel: 'rel',
},
edit: withSpokenMessages(
class LinkEdit extends Component {
Expand Down
1 change: 1 addition & 0 deletions packages/format-library/src/link/modal.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const ModalLinkUI = ( { isVisible, ...restProps } ) => {
hideHeader
onClose={ restProps.onClose }
hasNavigation
testID="link-settings-modal"
>
<BottomSheet.NavigationContainer animate main>
<BottomSheet.NavigationScreen name={ screens.settings }>
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ For each user feature we should also add a importance categorization label to i
- [*] Fix crash when trying to convert to regular blocks an undefined/deleted reusable block [#50475]
- [**] Tapping on nested text blocks gets focus directly instead of having to tap multiple times depeding on the nesting levels. [#50108]
- [*] Use host app namespace in reusable block message [#50478]
- [**] Configuring a link to open in a new tab no longer results in a partial loss of edit history (undo and redo) [#50460]

## 1.94.0
- [*] Split pasted content between title and body. [#37169]
Expand Down
60 changes: 60 additions & 0 deletions test/native/integration/editor-history.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
*/
import {
addBlock,
dismissModal,
getBlock,
typeInRichText,
fireEvent,
getEditorHtml,
initializeEditor,
setupCoreBlocks,
selectRangeInRichText,
within,
} from 'test/helpers';

Expand Down Expand Up @@ -173,4 +175,62 @@ describe( 'Editor History', () => {
<!-- /wp:paragraph -->"
` );
} );

it( 'should preserve editor history when a link has been added and configured to open in a new tab', async () => {
// Arrange
const initialHtml = `
<!-- wp:paragraph --><p>A <a href="http://wordpress.org">quick</a> brown fox jumps over the lazy dog.</p><!-- /wp:paragraph -->
`;
const screen = await initializeEditor( {
initialHtml,
} );

// Act
const paragraphBlock = getBlock( screen, 'Paragraph' );
fireEvent.press( paragraphBlock );

const paragraphTextInput =
within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
selectRangeInRichText( paragraphTextInput, 2, 7 );
fireEvent.press( screen.getByLabelText( 'Link' ) );

const newTabButton = screen.getByText( 'Open in new tab' );
fireEvent.press( newTabButton );

dismissModal( screen.getByTestId( 'link-settings-modal' ) );

typeInRichText(
paragraphTextInput,
' A quick brown fox jumps over the lazy dog.'
);

// Assert
expect( getEditorHtml() ).toMatchInlineSnapshot( `
"<!-- wp:paragraph -->
<p>A <a href="http://wordpress.org" target="_blank" rel="noreferrer noopener">quick</a> brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog.</p>
<!-- /wp:paragraph -->"
` );

// Act
fireEvent.press( screen.getByLabelText( 'Undo' ) );
fireEvent.press( screen.getByLabelText( 'Undo' ) );

// Assert
expect( getEditorHtml() ).toMatchInlineSnapshot( `
"<!-- wp:paragraph -->
<p>A <a href="http://wordpress.org">quick</a> brown fox jumps over the lazy dog.</p>
<!-- /wp:paragraph -->"
` );

// Act
fireEvent.press( screen.getByLabelText( 'Redo' ) );
fireEvent.press( screen.getByLabelText( 'Redo' ) );

// Assert
expect( getEditorHtml() ).toMatchInlineSnapshot( `
"<!-- wp:paragraph -->
<p>A <a href="http://wordpress.org" target="_blank" rel="noreferrer noopener">quick</a> brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog.</p>
<!-- /wp:paragraph -->"
` );
} );
} );