[FIX] web_editor: properly paste newlines on Windows

Windows uses /r/n as newlines and the split parameter was not taking
that into account, thus inserting the /r character.

task-2742071

closes odoo/odoo#96422

X-original-commit: 90e565f811523968c297f0254f4aa7046c4e710e
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
David Monjoie
2022-07-25 16:33:53 +02:00
parent 263bef0737
commit a5046ab1da
2 changed files with 21 additions and 1 deletions
@@ -3277,7 +3277,7 @@ export class OdooEditor extends EventTarget {
}
}
} else if (splitAroundUrl[i] !== '') {
const textFragments = splitAroundUrl[i].split('\n');
const textFragments = splitAroundUrl[i].split(/\r?\n/);
let textIndex = 1;
for (const textFragment of textFragments) {
this.execCommand('insertText', textFragment);
@@ -157,6 +157,26 @@ describe('Copy and paste', () => {
contentAfter: '<p>a<span>bx[]c</span>d</p>',
});
});
// TODO: We might want to have it consider \n as paragraph breaks
// instead of linebreaks but that would be an opinionated choice.
it('should paste text and understand \n newlines', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>[]<br/></p>',
stepFunction: async editor => {
await pasteText(editor, 'a\nb\nc\nd');
},
contentAfter: '<p>a<br>b<br>c<br>d[]<br></p>',
});
});
it('should paste text and understand \r\n newlines', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>[]<br/></p>',
stepFunction: async editor => {
await pasteText(editor, 'a\r\nb\r\nc\r\nd');
},
contentAfter: '<p>a<br>b<br>c<br>d[]<br></p>',
});
});
});
describe('range not collapsed', async () => {
it('should paste a text in a p', async () => {