[FIX] web_editor: do not normalize on preserveCursor
When preserving the selection, we typically want our selection to remain as close as possible to what it was before. But `preserveCursor` called `setSelection` with its default `normalize` argument, which would change the selection in sometimes unexpected ways. Part-of: odoo/odoo#141303
This commit is contained in:
committed by
Sébastien Geelen (sge)
parent
0f4914a157
commit
34ff41f797
@@ -890,7 +890,7 @@ export function preserveCursor(document) {
|
||||
replace = replace || new Map();
|
||||
cursorPos[0] = replace.get(cursorPos[0]) || cursorPos[0];
|
||||
cursorPos[2] = replace.get(cursorPos[2]) || cursorPos[2];
|
||||
return setSelection(...cursorPos);
|
||||
return setSelection(...cursorPos, false);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -59,9 +59,9 @@ describe('applyColor', () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<p>[<br></p><p><br></p><p>]<br></p>',
|
||||
stepFunction: setColor('rgb(255, 0, 0)', 'color'),
|
||||
contentAfterEdit: '<p><font data-oe-zws-empty-inline="" style="color: rgb(255, 0, 0);">[\u200B</font></p>' +
|
||||
contentAfterEdit: '<p>[<font data-oe-zws-empty-inline="" style="color: rgb(255, 0, 0);">\u200B</font></p>' +
|
||||
'<p><font data-oe-zws-empty-inline="" style="color: rgb(255, 0, 0);">\u200B</font></p>' +
|
||||
'<p><font data-oe-zws-empty-inline="" style="color: rgb(255, 0, 0);">]\u200B</font></p>',
|
||||
'<p>]<font data-oe-zws-empty-inline="" style="color: rgb(255, 0, 0);">\u200B</font></p>',
|
||||
contentAfter: '<p>[</p><p></p><p>]</p>',
|
||||
});
|
||||
});
|
||||
@@ -69,9 +69,9 @@ describe('applyColor', () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<p>[<br></p><p><br></p><p>]<br></p>',
|
||||
stepFunction: setColor('rgb(255, 0, 0)', 'backgroundColor'),
|
||||
contentAfterEdit: '<p><font data-oe-zws-empty-inline="" style="background-color: rgb(255, 0, 0);">[\u200B</font></p>' +
|
||||
contentAfterEdit: '<p>[<font data-oe-zws-empty-inline="" style="background-color: rgb(255, 0, 0);">\u200B</font></p>' +
|
||||
'<p><font data-oe-zws-empty-inline="" style="background-color: rgb(255, 0, 0);">\u200B</font></p>' +
|
||||
'<p><font data-oe-zws-empty-inline="" style="background-color: rgb(255, 0, 0);">]\u200B</font></p>',
|
||||
'<p>]<font data-oe-zws-empty-inline="" style="background-color: rgb(255, 0, 0);">\u200B</font></p>',
|
||||
contentAfter: '<p>[</p><p></p><p>]</p>',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -581,7 +581,7 @@ describe('Format', () => {
|
||||
contentAfter: `<p style="text-decoration: line-through;">a[b]c</p>`,
|
||||
});
|
||||
});
|
||||
it('should insert new character inside strikethrough at first position', async () => {
|
||||
it('should insert before strikethrough', async () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: `<p>d[a${s('bc]<br><br>')}</p>`,
|
||||
stepFunction: async editor => {
|
||||
@@ -641,7 +641,6 @@ describe('Format', () => {
|
||||
});
|
||||
});
|
||||
it('should remove underline, write, restore underline, write, remove underline again, write (collapsed, strikeThrough)', async () => {
|
||||
const uselessS = s(u('\u200B', 'first'), 'first'); // TODO: clean
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: `<p>ab${u(s(`cd[]ef`))}</p>`,
|
||||
stepFunction: async editor => {
|
||||
@@ -652,7 +651,7 @@ describe('Format', () => {
|
||||
await editor.execCommand('underline');
|
||||
await editor.execCommand('insert', 'C');
|
||||
},
|
||||
contentAfterEdit: `<p>ab${u(s(`cd`))}${s(`A${u(`B`, 'first')}C[]\u200B`, 'first')}${uselessS}${u(s(`ef`))}</p>`,
|
||||
contentAfterEdit: `<p>ab${u(s(`cd`))}${s(`A${u(`B`, 'first')}C[]\u200B`, 'first')}${u(s(`ef`))}</p>`,
|
||||
});
|
||||
});
|
||||
it('should remove only underline decoration on a span', async () => {
|
||||
|
||||
@@ -530,7 +530,7 @@ describe('Link', () => {
|
||||
stepFunction: async editor => {
|
||||
await unlink(editor);
|
||||
},
|
||||
contentAfter: '<p>a<a href="exist">bc[</a>d]e</p>',
|
||||
contentAfter: '<p>a<a href="exist">bc</a>[d]e</p>',
|
||||
});
|
||||
// BACKWARD
|
||||
await testEditor(BasicEditor, {
|
||||
@@ -538,7 +538,7 @@ describe('Link', () => {
|
||||
stepFunction: async editor => {
|
||||
await unlink(editor);
|
||||
},
|
||||
contentAfter: '<p>a<a href="exist">bc]</a>d[e</p>',
|
||||
contentAfter: '<p>a<a href="exist">bc</a>]d[e</p>',
|
||||
});
|
||||
});
|
||||
it('should remove the link in the selected range in the middle of a link', async () => {
|
||||
@@ -548,7 +548,7 @@ describe('Link', () => {
|
||||
stepFunction: async editor => {
|
||||
await unlink(editor);
|
||||
},
|
||||
contentAfter: '<p>a<a href="exist">b[</a>c]<a href="exist">d</a>e</p>',
|
||||
contentAfter: '<p>a<a href="exist">b</a>[c]<a href="exist">d</a>e</p>',
|
||||
});
|
||||
// BACKWARD
|
||||
await testEditor(BasicEditor, {
|
||||
@@ -556,7 +556,7 @@ describe('Link', () => {
|
||||
stepFunction: async editor => {
|
||||
await unlink(editor);
|
||||
},
|
||||
contentAfter: '<p>a<a href="exist">b]</a>c[<a href="exist">d</a>e</p>',
|
||||
contentAfter: '<p>a<a href="exist">b</a>]c[<a href="exist">d</a>e</p>',
|
||||
});
|
||||
});
|
||||
it('should remove the link in the selected range at the start of a link', async () => {
|
||||
@@ -584,7 +584,7 @@ describe('Link', () => {
|
||||
stepFunction: async editor => {
|
||||
await unlink(editor);
|
||||
},
|
||||
contentAfter: '<p>a<a href="exist">bc[</a>de]f</p>',
|
||||
contentAfter: '<p>a<a href="exist">bc</a>[de]f</p>',
|
||||
});
|
||||
// BACKWARD
|
||||
await testEditor(BasicEditor, {
|
||||
@@ -592,7 +592,7 @@ describe('Link', () => {
|
||||
stepFunction: async editor => {
|
||||
await unlink(editor);
|
||||
},
|
||||
contentAfter: '<p>a<a href="exist">bc]</a>de[f</p>',
|
||||
contentAfter: '<p>a<a href="exist">bc</a>]de[f</p>',
|
||||
});
|
||||
});
|
||||
it('should remove the link in the selected range overlapping the start of a link', async () => {
|
||||
|
||||
Reference in New Issue
Block a user