Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

Commit 25b292a

Browse files
author
DEWITTE Pierre-Alban
committed
[DEV] Improve math undo redo
1 parent d263c91 commit 25b292a

File tree

5 files changed

+59
-9
lines changed

5 files changed

+59
-9
lines changed

dist/myscript.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12666,7 +12666,7 @@ MyScript = {
1266612666
MathRenderer.prototype.drawRecognitionResult = function (components, recognitionResult) {
1266712667
this.clear();
1266812668
if (recognitionResult) {
12669-
var notScratchOutComponents = _removeMathScratchOut(components, recognitionResult.getScratchOutResults());
12669+
var notScratchOutComponents = _filterScratchOut(components, recognitionResult.getScratchOutResults());
1267012670
this.drawComponents(notScratchOutComponents);
1267112671
} else {
1267212672
this.drawComponents(components);
@@ -12683,7 +12683,9 @@ MyScript = {
1268312683
for (var i in components) {
1268412684
var component = components[i];
1268512685
if (component instanceof scope.AbstractComponent) {
12686-
scope.AbstractRenderer.prototype.drawComponent.call(this, component); // super
12686+
if(!component.scratchedStroke){
12687+
scope.AbstractRenderer.prototype.drawComponent.call(this, component); // super
12688+
}
1268712689
} else {
1268812690
throw new Error('not implemented');
1268912691
}
@@ -12725,6 +12727,29 @@ MyScript = {
1272512727
return cloneComponents;
1272612728
};
1272712729

12730+
/**
12731+
* Return non-scratched out components
12732+
*
12733+
* @private
12734+
* @param components
12735+
* @param scratchOutResults
12736+
* @returns {*}
12737+
*/
12738+
var _filterScratchOut = function (components, scratchOutResults) {
12739+
if (!scratchOutResults || scratchOutResults.length === 0) {
12740+
return components;
12741+
}
12742+
for (var k in scratchOutResults) {
12743+
for (var n in scratchOutResults[k].getErasedInkRanges()) {
12744+
components[scratchOutResults[k].getErasedInkRanges()[n].getComponent()].scratchedStroke = true;
12745+
}
12746+
for (var p in scratchOutResults[k].getInkRanges()) {
12747+
components[scratchOutResults[k].getInkRanges()[p].getComponent()].scratchedStroke = true;;
12748+
}
12749+
}
12750+
return components;
12751+
};
12752+
1272812753
// Export
1272912754
scope.MathRenderer = MathRenderer;
1273012755
})(MyScript);

dist/myscript.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/myscript.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/myscript.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rendering/mathRenderer.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
MathRenderer.prototype.drawRecognitionResult = function (components, recognitionResult) {
3434
this.clear();
3535
if (recognitionResult) {
36-
var notScratchOutComponents = _removeMathScratchOut(components, recognitionResult.getScratchOutResults());
36+
var notScratchOutComponents = _filterScratchOut(components, recognitionResult.getScratchOutResults());
3737
this.drawComponents(notScratchOutComponents);
3838
} else {
3939
this.drawComponents(components);
@@ -50,7 +50,9 @@
5050
for (var i in components) {
5151
var component = components[i];
5252
if (component instanceof scope.AbstractComponent) {
53-
scope.AbstractRenderer.prototype.drawComponent.call(this, component); // super
53+
if(!component.scratchedStroke){
54+
scope.AbstractRenderer.prototype.drawComponent.call(this, component); // super
55+
}
5456
} else {
5557
throw new Error('not implemented');
5658
}
@@ -92,6 +94,29 @@
9294
return cloneComponents;
9395
};
9496

97+
/**
98+
* Return non-scratched out components
99+
*
100+
* @private
101+
* @param components
102+
* @param scratchOutResults
103+
* @returns {*}
104+
*/
105+
var _filterScratchOut = function (components, scratchOutResults) {
106+
if (!scratchOutResults || scratchOutResults.length === 0) {
107+
return components;
108+
}
109+
for (var k in scratchOutResults) {
110+
for (var n in scratchOutResults[k].getErasedInkRanges()) {
111+
components[scratchOutResults[k].getErasedInkRanges()[n].getComponent()].scratchedStroke = true;
112+
}
113+
for (var p in scratchOutResults[k].getInkRanges()) {
114+
components[scratchOutResults[k].getInkRanges()[p].getComponent()].scratchedStroke = true;;
115+
}
116+
}
117+
return components;
118+
};
119+
95120
// Export
96121
scope.MathRenderer = MathRenderer;
97122
})(MyScript);

0 commit comments

Comments
 (0)