diff options
author | matthewsotoudeh <matthewsot@outlook.com> | 2016-01-24 00:31:13 -0800 |
---|---|---|
committer | matthewsotoudeh <matthewsot@outlook.com> | 2016-01-24 00:31:13 -0800 |
commit | 3e9f2f33d8a764a4dc05be4f4de7bf38e6148641 (patch) | |
tree | cfb9cf9616bd825904aa4ed07f8ade3871473ee5 | |
parent | de889788fbf5fb1232dbf0d252e0aa729246095c (diff) |
tests on TextSpan are working
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | dist/core.js | 4 | ||||
-rw-r--r-- | gulpfile.js | 21 | ||||
-rw-r--r-- | src/Document/Nodes/TextSpan.js | 4 |
4 files changed, 26 insertions, 9 deletions
@@ -1,6 +1,10 @@ -# ecrit - a better text editor +# ecrit: a better text editor High-performance editor with a custom writing surface, a la Google Kix +#ecrit-core: the text & transformation layer +This repository contains the "backend" Javascript library to handle underlying text storage and manipulation across multiple concurrent users. +It does not include any code to actually display or interact with that text. + ### What? Ecrit will be a Javascript editor that doesn't use any native HTML editing surfaces, like textarea or input. You will be able to turn any div into an editor, and it will use some form of operational transformation to keep everything in check. diff --git a/dist/core.js b/dist/core.js index 49c202e..d8413f0 100644 --- a/dist/core.js +++ b/dist/core.js @@ -344,7 +344,7 @@ ecrit.TextSpan.prototype._undo = function (transformation) { ecrit.TextSpan.prototype.applyTransformation = function (transformation, clone) { if (clone !== false) { - transformation = JSON.parse(JSON.stringify(transformation)); + transformation = new ecrit.Transformation(JSON.parse(JSON.stringify(transformation))); } var reference = this.history.withTimestamp(transformation.lastApplied); @@ -358,7 +358,7 @@ ecrit.TextSpan.prototype.applyTransformation = function (transformation, clone) this.history.splice(this.history.indexOf(U[i]), 1); this._undo(U[i]); } - + var E = this.history.betweenTimestamps(transformation.lastApplied, transformation.timestamp); var D = 0; for (var i = 0; i < E.length; i++) { diff --git a/gulpfile.js b/gulpfile.js index a51bb86..36ad254 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -56,9 +56,22 @@ gulp.task('test', function () { "affectsId": "p-id-1", "timestamp": (new Date()).getTime(), "action": "insertNode", - "node": new sandbox.ecrit.TextSpan(para, "ts-id-1"), + "node": new sandbox.ecrit.TextSpan(para, "ts-id-1", { text: "test text" }), "lastApplied": -1 }); + + assert(doc.getChildNodeById("ts-id-1").text === "test text", "TextSpan text"); + + doc.getChildNodeById("ts-id-1").applyTransformation(new sandbox.ecrit.Transformation({ + remove: false, + action: "insertText", + text: "abc", + index: 0, + timestamp: 300, + lastApplied: -1 + })); + + assert(doc.getChildNodeById("ts-id-1").text === "abctest text", "TextSpan test text"); }); gulp.task('simple-test', function () { @@ -136,7 +149,7 @@ gulp.task('simple-test', function () { }); gulp.task('watch', function () { - gulp.watch("src/**/*", function(v) { - gulp.start('default'); - }); + gulp.watch("src/**/*", function(v) { + gulp.start('default'); + }); });
\ No newline at end of file diff --git a/src/Document/Nodes/TextSpan.js b/src/Document/Nodes/TextSpan.js index 7653280..ce00808 100644 --- a/src/Document/Nodes/TextSpan.js +++ b/src/Document/Nodes/TextSpan.js @@ -30,7 +30,7 @@ ecrit.TextSpan.prototype._undo = function (transformation) { ecrit.TextSpan.prototype.applyTransformation = function (transformation, clone) { if (clone !== false) { - transformation = JSON.parse(JSON.stringify(transformation)); + transformation = new ecrit.Transformation(JSON.parse(JSON.stringify(transformation))); } var reference = this.history.withTimestamp(transformation.lastApplied); @@ -44,7 +44,7 @@ ecrit.TextSpan.prototype.applyTransformation = function (transformation, clone) this.history.splice(this.history.indexOf(U[i]), 1); this._undo(U[i]); } - + var E = this.history.betweenTimestamps(transformation.lastApplied, transformation.timestamp); var D = 0; for (var i = 0; i < E.length; i++) { |