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

Soft breaks are now properly placed in plain text clipboard data representation by the editor #8048

Merged
merged 1 commit into from
Sep 10, 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
3 changes: 3 additions & 0 deletions packages/ckeditor5-clipboard/src/utils/viewtoplaintext.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default function viewToPlainText( viewItem ) {
} else if ( viewItem.is( 'element', 'img' ) && viewItem.hasAttribute( 'alt' ) ) {
// Special case for images - use alt attribute if it is provided.
text = viewItem.getAttribute( 'alt' );
} else if ( viewItem.is( 'element', 'br' ) ) {
// A soft break should be converted into a single line break (#8045).
text = '\n';
} else {
// Other elements are document fragments, attribute elements or container elements.
// They don't have their own text value, so convert their children.
Expand Down
16 changes: 16 additions & 0 deletions packages/ckeditor5-clipboard/tests/utils/viewtoplaintext.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ describe( 'viewToPlainText()', () => {
);
} );

it( 'should turn a soft break into a single empty line', () => {
testViewToPlainText(
'<container:p>Foo<empty:br />Bar</container:p>',

'Foo\nBar'
);
} );

it( 'should turn multiple soft breaks into empty lines', () => {
testViewToPlainText(
'<container:p>Foo<empty:br /><empty:br />Bar</container:p>',

'Foo\n\nBar'
);
} );

it( 'should output alt attribute of image elements', () => {
testViewToPlainText(
'<container:p>Foo</container:p>' +
Expand Down