[FIX] web_editor: fix insertText test util for multiple characters
task-2858621 X-original-commit: 308a039d96e709bc0ef27ba77af20abfde881ea3 Part-of: odoo/odoo#97297
This commit is contained in:
@@ -459,14 +459,23 @@ export async function createLink(editor, content) {
|
||||
}
|
||||
|
||||
export async function insertText(editor, text) {
|
||||
// We create and dispatch an event to mock the insert Text.
|
||||
// Unfortunatly those Event are flagged `isTrusted: false`.
|
||||
// So we have no choice and need to detect them inside the Editor.
|
||||
// But it's the closest to real Browser we can go.
|
||||
triggerEvent(editor.editable, 'input', {
|
||||
inputType: 'insertText',
|
||||
data: text,
|
||||
});
|
||||
// Create and dispatch events to mock text insertion. Unfortunatly, the
|
||||
// events will be flagged `isTrusted: false` by the browser, requiring
|
||||
// the editor to detect them since they would not trigger the default
|
||||
// browser behavior otherwise.
|
||||
for (const char of text) {
|
||||
// KeyDownEvent is required to trigger deleteRange.
|
||||
triggerEvent(editor.editable, 'keydown', { key: char });
|
||||
// KeyPressEvent is not required but is triggered like in the browser.
|
||||
triggerEvent(editor.editable, 'keypress', { key: char });
|
||||
// InputEvent is required to simulate the insert text.
|
||||
triggerEvent(editor.editable, 'input', {
|
||||
inputType: 'insertText',
|
||||
data: char,
|
||||
});
|
||||
// KeyUpEvent is not required but is triggered like the browser would.
|
||||
triggerEvent(editor.editable, 'keyup', { key: char });
|
||||
}
|
||||
}
|
||||
|
||||
export function undo(editor) {
|
||||
|
||||
Reference in New Issue
Block a user