[FIX] web_editor: fix rollback on pasting using ctrl+shift+v
Before this commit: When pasting using CTRL+SHIFT+V, if the textFragment includes linebreak(\n), each textFragment is divided, and each seperated fragment is inserted using `insert` command, followed by `oEnter` command. However, when `oEnter` is UNBREAKABLE, the inserted text is ROLLBACKED. After this commit: We now check whether the anchorNode's closestBlock is UNBREAKABLE. If so use `oShiftEnter` command; otherwise, use `oEnter` command which avoids ROLLBACK. task-3563785 closes odoo/odoo#151911 X-original-commit: f1e35ca82cf72ffb21c586d9bf1714bb388fe257 Signed-off-by: Geelen Sébastien (sge) <sge@odoo.com>
This commit is contained in:
@@ -79,6 +79,7 @@ import {
|
||||
getFontSizeDisplayValue,
|
||||
rightLeafOnlyNotBlockPath,
|
||||
lastLeaf,
|
||||
isUnbreakable,
|
||||
} from './utils/utils.js';
|
||||
import { editorCommands } from './commands/commands.js';
|
||||
import { Powerbox } from './powerbox/Powerbox.js';
|
||||
@@ -4983,10 +4984,11 @@ export class OdooEditor extends EventTarget {
|
||||
// Break line by inserting new paragraph and
|
||||
// remove current paragraph's bottom margin.
|
||||
const p = closestElement(sel.anchorNode, 'p');
|
||||
if (this._applyCommand('oEnter') === UNBREAKABLE_ROLLBACK_CODE) {
|
||||
if (isUnbreakable(closestBlock(sel.anchorNode))) {
|
||||
this._applyCommand('oShiftEnter');
|
||||
} else if (p) {
|
||||
p.style.marginBottom = '0px';
|
||||
} else {
|
||||
this._applyCommand('oEnter');
|
||||
p && (p.style.marginBottom = '0px');
|
||||
}
|
||||
}
|
||||
textIndex++;
|
||||
|
||||
@@ -406,6 +406,24 @@ describe('Paste', () => {
|
||||
'<p>d[]<br></p>',
|
||||
});
|
||||
});
|
||||
it('should paste text and understand \\n newlines within UNBREAKABLE node', async () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<div>[]<br></div>',
|
||||
stepFunction: async editor => {
|
||||
await pasteText(editor, 'a\nb\nc\nd');
|
||||
},
|
||||
contentAfter: '<div>a<br>b<br>c<br>d[]<br></div>',
|
||||
});
|
||||
});
|
||||
it('should paste text and understand \\n newlines within UNBREAKABLE node(2)', async () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<div><span style="font-size: 9px;">a[]</span></div>',
|
||||
stepFunction: async editor => {
|
||||
await pasteText(editor, 'b\nc\nd');
|
||||
},
|
||||
contentAfter: '<div><span style="font-size: 9px;">ab<br>c<br>d[]<br></span></div>',
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('range not collapsed', async () => {
|
||||
it('should paste a text in a p', async () => {
|
||||
|
||||
Reference in New Issue
Block a user