Add typing test in the code app

pull/1/head
yflory 6 years ago
parent 015449832c
commit 13d6579861

@ -9,6 +9,7 @@ define([
'/common/common-hash.js', '/common/common-hash.js',
'/common/modes.js', '/common/modes.js',
'/common/visible.js', '/common/visible.js',
'/common/TypingTests.js',
'/customize/messages.js', '/customize/messages.js',
'cm/lib/codemirror', 'cm/lib/codemirror',
@ -51,6 +52,7 @@ define([
Hash, Hash,
Modes, Modes,
Visible, Visible,
TypingTest,
Messages, Messages,
CMeditor) CMeditor)
{ {
@ -345,6 +347,12 @@ define([
editor.on('change', framework.localChange); editor.on('change', framework.localChange);
framework.start(); framework.start();
window.easyTest = function () {
var test = TypingTest.testCode(editor);
return test;
};
}; };
var getThumbnailContainer = function () { var getThumbnailContainer = function () {

@ -56,7 +56,7 @@ define(function () {
}; };
}; };
var testInput2 = function (editor) { var testPad = function (editor, onLocal) {
var i = 0, var i = 0,
input = " The quick red fox jumps over the lazy brown dog.", input = " The quick red fox jumps over the lazy brown dog.",
l = input.length, l = input.length,
@ -67,6 +67,26 @@ define(function () {
interval = setRandomizedInterval(function () { interval = setRandomizedInterval(function () {
editor.insertText(input.charAt(i)); editor.insertText(input.charAt(i));
onLocal();
i = (i + 1) % l;
}, 200, 50);
return {
cancel: cancel
};
};
var testCode = function (editor) {
var i = 0,
input = " The quick red fox jumps over the lazy brown dog.",
l = input.length,
interval;
var cancel = function () {
if (interval) { interval.cancel(); }
};
interval = setRandomizedInterval(function () {
editor.replaceSelection(input.charAt(i));
i = (i + 1) % l; i = (i + 1) % l;
}, 200, 50); }, 200, 50);
@ -77,7 +97,8 @@ define(function () {
return { return {
testInput: testInput, testInput: testInput,
testInput2: testInput2, testPad: testPad,
testCode: testCode,
setRandomizedInterval: setRandomizedInterval setRandomizedInterval: setRandomizedInterval
}; };
}); });

@ -685,6 +685,7 @@ define([
]; ];
}); });
/* hitting enter makes a new line, but places the cursor inside /* hitting enter makes a new line, but places the cursor inside
of the <br> instead of the <p>. This makes it such that you of the <br> instead of the <p>. This makes it such that you
cannot type until you click, which is rather unnacceptable. cannot type until you click, which is rather unnacceptable.
@ -715,7 +716,7 @@ define([
cursor.update(); cursor.update();
//var start = cursor.Range.start; //var start = cursor.Range.start;
//var test = TypingTest.testInput(inner, start.el, start.offset, framework.localChange); //var test = TypingTest.testInput(inner, start.el, start.offset, framework.localChange);
var test = TypingTest.testInput2(editor); var test = TypingTest.testPad(editor, framework.localChange);
framework.localChange(); framework.localChange();
return test; return test;
}; };

Loading…
Cancel
Save