[FIX] web_editor: shift paste of vs code content looses indentation
Before this commit: when performing a shift paste of copied VS Code content, the indentation was lost. After this commit: Now, when you perform a shift paste of copied VS Code content, the indentation is preserved Task-2884491 closes odoo/odoo#136867 X-original-commit: 1641bb50aa30ac64340eb261b26d4706944299ba Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
@@ -4811,7 +4811,16 @@ export class OdooEditor extends EventTarget {
|
||||
const textFragments = splitAroundUrl[i].split(/\r?\n/);
|
||||
let textIndex = 1;
|
||||
for (const textFragment of textFragments) {
|
||||
this._applyCommand('insert', textFragment);
|
||||
// Replace consecutive spaces by alternating nbsp.
|
||||
const modifiedTextFragment = textFragment.replace(/( {2,})/g, match => {
|
||||
let alertnateValue = false;
|
||||
return match.replace(/ /g, () => {
|
||||
alertnateValue = !alertnateValue;
|
||||
const replaceContent = alertnateValue ? '\u00A0' : ' ';
|
||||
return replaceContent;
|
||||
});
|
||||
});
|
||||
this._applyCommand('insert', modifiedTextFragment);
|
||||
if (textIndex < textFragments.length) {
|
||||
// Break line by inserting new paragraph and
|
||||
// remove current paragraph's bottom margin.
|
||||
|
||||
@@ -275,7 +275,7 @@ describe('Paste', () => {
|
||||
stepFunction: async editor => {
|
||||
await pasteText(editor, 'x y');
|
||||
},
|
||||
contentAfter: '<p>abx y[]cd</p>',
|
||||
contentAfter: '<p>abx y[]cd</p>',
|
||||
});
|
||||
});
|
||||
it('should paste a text in a span', async () => {
|
||||
@@ -335,7 +335,7 @@ describe('Paste', () => {
|
||||
stepFunction: async editor => {
|
||||
await pasteText(editor, 'x y');
|
||||
},
|
||||
contentAfter: '<p>ax y[]d</p>',
|
||||
contentAfter: '<p>ax y[]d</p>',
|
||||
});
|
||||
});
|
||||
it('should paste a text in a span', async () => {
|
||||
|
||||
Reference in New Issue
Block a user