summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/tests/test_utils.js
diff options
context:
space:
mode:
authorGorash <chm@odoo.com>2019-03-21 12:16:01 +0000
committerGorash <chm@odoo.com>2019-08-06 10:45:04 +0000
commit8e4b8be4e6465204038798db137451c95a8050b6 (patch)
tree7a187a21f13b871a44e65a1294d6e76dd29d7102 /addons/web_editor/static/tests/test_utils.js
parent4e21d6180b909ecd0e9df00c4c66467df4eb77d1 (diff)
[FIX] web_editor: remove virtual corrector/completion keyboard glitch
For the ours need, we can not let the contentEditable behavior. Indeed, this one does not have the same behavior according to the browser. The DOM node could be erase, merge, cut, in them according to the keyboard interactions. The problem is that if we have to manage these behaviors, we have to manage everything. It was already the case in the previous version, however before we created an editor by zone and by a hack we mix the history. In the case of the virtual keyboard of some OS / Phone, the events are different and the autocompletion does not update (bug that prevents modification interactions with javascript). In order to solve these problems, we use another event for the insertion of the characters. However, we must also force the update of the corrector by forcing a blur and a focus. The current version is a temporary version. We are currently working on a version that uses a virtual dom and does not need to do excessive prevent default.
Diffstat (limited to 'addons/web_editor/static/tests/test_utils.js')
-rw-r--r--addons/web_editor/static/tests/test_utils.js35
1 files changed, 34 insertions, 1 deletions
diff --git a/addons/web_editor/static/tests/test_utils.js b/addons/web_editor/static/tests/test_utils.js
index 27ba86b52ff..1ad47212e73 100644
--- a/addons/web_editor/static/tests/test_utils.js
+++ b/addons/web_editor/static/tests/test_utils.js
@@ -494,9 +494,10 @@ var testKeyboard = function ($editable, assert, keyboardTests, addTests) {
keypress.keyCode = keypress.keyCode;
var event = $.Event("keydown", keypress);
$target.trigger(event);
+
if (!event.isDefaultPrevented()) {
if (keypress.key.length === 1) {
- document.execCommand("insertText", 0, keypress.key);
+ textInput($target[0], keypress.key);
} else {
console.warn('Native "' + keypress.key + '" is not supported in test');
}
@@ -759,8 +760,40 @@ var keydown = function (key, $editable, options) {
var $target = $(target.tagName ? target : target.parentNode);
var event = $.Event("keydown", keyPress);
$target.trigger(event);
+
+ if (!event.isDefaultPrevented()) {
+ if (keyPress.key.length === 1) {
+ textInput($target[0], keyPress.key);
+ } else {
+ console.warn('Native "' + keyPress.key + '" is not supported in test');
+ }
+ }
};
+var textInput = function (target, char) {
+ var ev = new CustomEvent('textInput', {
+ bubbles: true,
+ cancelBubble: false,
+ cancelable: true,
+ composed: true,
+ data: char,
+ defaultPrevented: false,
+ detail: 0,
+ eventPhase: 3,
+ isTrusted: true,
+ returnValue: true,
+ sourceCapabilities: null,
+ type: "textInput",
+ which: 0,
+ });
+ ev.data = char;
+ target.dispatchEvent(ev);
+
+ if (!ev.defaultPrevented) {
+ document.execCommand("insertText", 0, ev.data);
+ }
+}
+
return {
wysiwygData: wysiwygData,
createWysiwyg: createWysiwyg,