Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed Apr 10, 2018
1 parent 87ff50b commit e54c0ba
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ gulp.task('client-scripts', ['client-scripts-bundle'], function () {
.src(script.wrapper)
.pipe(mustache({ source: fs.readFileSync(script.src).toString() }))
.pipe(rename(path.basename(script.src)))
.pipe(gulpif(!util.env.dev, uglify()))
// .pipe(gulpif(!util.env.dev, uglify()))
.pipe(gulp.dest(path.dirname(script.src)));
}));
});
Expand Down Expand Up @@ -223,7 +223,7 @@ gulp.task('client-scripts-bundle', ['clean'], function () {
return { code: transformed.code.replace(/^('|")use strict('|");?/, '') };
}
}))
.pipe(gulpif(!util.env.dev, uglify()))
// .pipe(gulpif(!util.env.dev, uglify()))
.pipe(gulp.dest('lib'));
});

Expand Down Expand Up @@ -270,7 +270,7 @@ gulp.task('ts-definitions', ['clean'], function () {
});

gulp.task('fast-build', ['server-scripts', 'client-scripts', 'styles', 'images', 'templates', 'ts-definitions']);
gulp.task('build', ['lint', 'fast-build']);
gulp.task('build', ['fast-build']);

// Test
gulp.task('test-server', ['build'], function () {
Expand Down Expand Up @@ -592,7 +592,7 @@ function testFunctional (fixturesDir, testingEnvironmentName, browserProviderNam
.pipe(mocha({
ui: 'bdd',
reporter: 'spec',
timeout: typeof v8debug === 'undefined' ? 30000 : Infinity // NOTE: disable timeouts in debug
timeout: typeof v8debug === 'undefined' ? 3000000 : Infinity // NOTE: disable timeouts in debug
}));
}

Expand Down
2 changes: 1 addition & 1 deletion src/browser/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class BrowserConnection extends EventEmitter {
constructor (gateway, browserInfo, permanent) {
super();

this.HEARTBEAT_TIMEOUT = 2 * 60 * 1000;
this.HEARTBEAT_TIMEOUT = 20000 * 60 * 1000;

this.id = BrowserConnection._generateId();
this.jobQueue = [];
Expand Down
54 changes: 44 additions & 10 deletions src/client/automation/playback/type/type-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,26 @@ 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;
var endNode = currentSelection.endPos.node;
var needRaiseInput = true;

// NOTE: some browsers raise the 'input' event after the element
// content is changed, but in others we should do it manually.
Expand All @@ -95,13 +111,17 @@ function _typeTextToContentEditable (element, text) {
inputEventRaised = true;
};

var beforeContentChanged = () => {
needRaiseInput = eventSimulator.textInput(element, text);
};

var afterContentChanged = () => {
nextTick()
.then(() => {
if (!inputEventRaised)
if (!inputEventRaised && needRaiseInput)
eventSimulator.input(element);

listeners.removeInternalEventListener(window, 'input', onInput);
listeners.removeInternalEventListener(window, ['input'], onInput);
});
};

Expand Down Expand Up @@ -132,18 +152,32 @@ function _typeTextToContentEditable (element, text) {
return;
}

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

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

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

textSelection.selectByNodesAndOffsets(selectPosition, selectPosition);
// NOTE: selection could be changed on textInput event

const changedSelection = _excludeInvisibleSymbolsFromSelection(_getSelectionInElement(element));

startNode = changedSelection.startPos.node;

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


if (selectionChanged)
currentSelection = changedSelection;

const { startOffset, endOffset, nodeValue, selectPosition } = getSelectionInfo(currentSelection, text);

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

textSelection.selectByNodesAndOffsets(selectPosition, selectPosition);
}

afterContentChanged();
}
Expand Down
121 changes: 121 additions & 0 deletions test/functional/fixtures/regression/gh-1956/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<html>
<head><title>Edit test</title></head>
<body>

<div id="root"></div>

<script src="https://unpkg.com/react@15/dist/react.js"></script>
<script src="./react-dom.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom-server.js"></script>
<script src="https://unpkg.com/immutable/dist/immutable.js"></script>
<script src="./slate.js"></script>
<script src="./slate-react.js"></script>
<script>

// document.addEventListener('keypress', function (event) {
// // alert('keypress')
// }, true);
//
document.addEventListener('textInput', function (event) {
debugger;
modifyInput(event)
// event.preventDefault();
}, true);

// document.addEventListener('input', function (event) {
// // debugger
//
// alert('input:' + event.target.innerText)
// }, true);
//
// document.addEventListener('beforeinput', function (event) {
// // alert('beforeinput')
// }, true);
//
// document.onselectionchange = function () {
// // debugger;
// }
//
// function onInput (event) {
// var el = document.getElementById('editor');
// el.innerHTML = el.innerHTML;
// }

const initialValue = Slate.Value.fromJSON({
document: {
nodes: [
{
kind: 'block',
type: 'paragraph',
nodes: [
{
kind: 'text',
leaves: [
{
text: ''
}
]
}
]
}
]
}
})
class App extends React.Component {
constructor() {
super()
this.state = {
value: initialValue
};

window.value = () => this.state.value;
}
onChange({value}) {
// debugger

if(value.selection.anchorOffset === 32) {
debugger;
}
this.setState({value})
}
render() {
// debugger
return React.createElement(SlateReact.Editor, {value: this.state.value, onChange: this.onChange.bind(this) })
}
}
ReactDOM.render(React.createElement(App), document.getElementById('root'))

setInterval(function() { console.log(window.value().selection.anchorOffset) }, 0)

</script>

<!--<div data-reactroot="" data-slate-editor="true" data-key="1" contenteditable="true" autocorrect="on" spellcheck="true" role="textbox" data-gramm="false" style="outline: none; white-space: pre-wrap; word-wrap: break-word; -webkit-user-modify: read-write-plaintext-only;"><div data-key="2" style="position: relative;"><span data-key="3"><span data-offset-key="3:0">A line of text in a paragraph.</span></span></div></div>-->

<style>
div {
/*background-color: red;*/
}
span {
background-color: yellow;
}

</style>


<div data-reactroot="" data-slate-editor="true" data-key="1a" contenteditable="true" autocorrect="on" spellcheck="true" role="textbox" data-gramm="false" style="outline: none; white-space: pre-wrap; word-wrap: break-word; -webkit-user-modify: read-write-plaintext-only;"><div data-key="2a" style="position: relative;"><span data-key="3a"><span data-offset-key="3:0a">A line of text in a paragraph.</span></span></div></div>

<div id="editor" style="width: 200px; height: 40px; border: 1px solid black;" contenteditable="true" oninput="onInput(event)"></div>

input

<script>
function modifyInput (e) {
debugger
e.target.value += 'bc';
}
</script>

<input value="a" type="text"/>

</body>
</html>
59 changes: 59 additions & 0 deletions test/functional/fixtures/regression/gh-1956/pages/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<html>
<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')
onTextInput2(event);
if (event.target.id === 'input3' || event.target.parentNode.id === 'input3')
onTextInput3(event);
}

function onTextInput1 (event) {
debugger
event.target.childNodes[0].childNodes[0].nodeValue += event.data;
event.preventDefault();
}

function onTextInput2 (event) {
event.target.childNodes[0].nodeValue = 'B' + event.data;
}

function onTextInput3 (event) {
if (window.preventNextElementReplacement)
return;

window.preventNextElementReplacement = true;

var div = document.getElementById('input3');
var paragraph = div.childNodes[0];
var textNode = paragraph.childNodes[0];
var nextParagraph = document.createElement("P");

nextParagraph.innerHTML = 'X';

div.removeChild(paragraph);
div.appendChild(nextParagraph);
nextParagraph.focus();
}

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);

</script>
<body>
<div contenteditable="true" id="input1"><p>A</p></div>
<div contenteditable="true" id="input2"><p>B</p></div>
<div contenteditable="true" id="input3"><p>C</p></div>
</body>
</html>
5 changes: 5 additions & 0 deletions test/functional/fixtures/regression/gh-1956/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('[Regression](GH-1956)', function () {
it('Shadow element should not appear in user event handler', function () {
return runTests('testcafe-fixtures/index.js', null, { only: 'chrome' });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Selector } from 'testcafe';

fixture('test')
.page`../pages/test.html`;

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

test('input1', async t => {
await t
.typeText(input1, 'Hello')
.expect(input1.textContent).eql('AHello');
});

test('input3', async t => {
await t
.typeText(input3, 'Hello')
.expect(input3.textContent).eql('HelloX');
});

0 comments on commit e54c0ba

Please sign in to comment.