Skip to content

Commit

Permalink
123
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed Apr 10, 2018
1 parent e54c0ba commit b55ba99
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
36 changes: 9 additions & 27 deletions src/client/automation/playback/type/type-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,6 @@ function _excludeInvisibleSymbolsFromSelection (selection) {
return selection;
}

var getSelectionInfo = (selection, text) => {
const startNode = selection.startPos.node;
const startOffset = selection.startPos.offset;
const endOffset = selection.endPos.offset;
const nodeValue = startNode.nodeValue;
const selectPosition = { node: startNode, offset: startOffset + text.length };

return {
startOffset,
endOffset,
nodeValue,
selectPosition
};
};

function _typeTextToContentEditable (element, text) {
var currentSelection = _getSelectionInElement(element);
var startNode = currentSelection.startPos.node;
Expand Down Expand Up @@ -152,27 +137,24 @@ function _typeTextToContentEditable (element, text) {
return;
}

currentSelection = _excludeInvisibleSymbolsFromSelection(currentSelection);
currentSelection = _excludeInvisibleSymbolsFromSelection(currentSelection);
startNode = currentSelection.startPos.node;
var prevStartNode = startNode;

beforeContentChanged();

if (needRaiseInput) {

// NOTE: selection could be changed on textInput event

const changedSelection = _excludeInvisibleSymbolsFromSelection(_getSelectionInElement(element));
const selectionChangedOnTextInput = !domUtils.isTheSameNode(currentSelection.startPos.node, changedSelection.startPos.node);

startNode = changedSelection.startPos.node;

const selectionChanged = !domUtils.isTheSameNode(prevStartNode, startNode);


if (selectionChanged)
if (selectionChangedOnTextInput) {
currentSelection = changedSelection;
startNode = currentSelection.startPos.node;
}

const { startOffset, endOffset, nodeValue, selectPosition } = getSelectionInfo(currentSelection, text);
const startOffset = currentSelection.startPos.offset;
const endOffset = currentSelection.endPos.offset;
const nodeValue = startNode.nodeValue;
const selectPosition = { node: startNode, offset: startOffset + text.length };

startNode.nodeValue = nodeValue.substring(0, startOffset) + text + nodeValue.substring(endOffset, nodeValue.length);

Expand Down
5 changes: 0 additions & 5 deletions test/functional/fixtures/regression/gh-1956/pages/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<head><title>Edit test</title></head>
<script type="text/javascript">
function onTextInput (event) {
debugger
if (event.target.id === 'input1')
onTextInput1(event);
if (event.target.id === 'input2')
Expand All @@ -12,7 +11,6 @@
}

function onTextInput1 (event) {
debugger
event.target.childNodes[0].childNodes[0].nodeValue += event.data;
event.preventDefault();
}
Expand Down Expand Up @@ -42,11 +40,8 @@
function onInput (event) {
if (event.target.id === 'input1')
throw new Error('Input on `input1` should be prevented');

debugger
}

document.addEventListener('textinput', onTextInput, true); // IE way
document.addEventListener('textInput', onTextInput, true); // Chrome way
document.addEventListener('input', onInput, true);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Selector } from 'testcafe';

fixture('test')
.page`../pages/test.html`;
.page `http://localhost:3000/fixtures/regression/gh-1956/pages/test.html`;

const input1 = Selector('#input1');
const input3 = Selector('#input3');
Expand Down

0 comments on commit b55ba99

Please sign in to comment.