Skip to content

Commit

Permalink
fix textInput dispatch in safari
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed May 3, 2018
1 parent bbf3976 commit e42826f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/client/automation/playback/type/type-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import testCafeCore from '../../deps/testcafe-core';
import nextTick from '../../utils/next-tick';

var browserUtils = hammerhead.utils.browser;
var eventSandbox = hammerhead.sandbox.event;
var eventSimulator = hammerhead.eventSandbox.eventSimulator;
var listeners = hammerhead.eventSandbox.listeners;

Expand Down Expand Up @@ -112,23 +113,30 @@ function _excludeInvisibleSymbolsFromSelection (selection) {
let forceInputInSafari;

function simulateTextInput (element, text) {
forceInputInSafari = false;

if (browserUtils.isSafari)
document.addEventListener('textInput', onSafariTextInput);
if (browserUtils.isSafari) {
listeners.addInternalEventListener(window, ['textInput'], onSafariTextInput);
eventSandbox.on(eventSandbox.EVENT_PREVENTED_EVENT, onSafariPreventTextInput);
}

const isInputEventRequired = browserUtils.isFirefox || eventSimulator.textInput(element, text) || forceInputInSafari;

if (browserUtils.isSafari)
document.removeEventListener('textInput', onSafariTextInput);
if (browserUtils.isSafari) {
listeners.removeInternalEventListener(window, ['textInput'], onSafariTextInput);
eventSandbox.off(eventSandbox.EVENT_PREVENTED_EVENT, onSafariPreventTextInput);
}

return isInputEventRequired || browserUtils.isIE11;
}

function onSafariTextInput (e) {
forceInputInSafari = !e.defaultPrevented;

e.preventDefault();

forceInputInSafari = true;
}

function onSafariPreventTextInput (e) {
if (e.type === 'textInput')
forceInputInSafari = false;
}

function _typeTextToContentEditable (element, text) {
Expand Down

0 comments on commit e42826f

Please sign in to comment.