Skip to content

Commit

Permalink
ASTDiff: (GUI) Monaco diff scroll for non action associated subtrees (F…
Browse files Browse the repository at this point in the history
…ixes tsantalis#726)
  • Loading branch information
pouryafard75 committed May 29, 2024
1 parent f0df2e4 commit 824acbc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
13 changes: 12 additions & 1 deletion src/main/java/gui/webdiff/MonacoDiffView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.gumtreediff.actions.Diff;
import com.github.gumtreediff.actions.TreeClassifier;
import com.github.gumtreediff.matchers.MappingStore;
import com.github.gumtreediff.tree.Tree;
import org.refactoringminer.astDiff.models.ASTDiff;
import org.refactoringminer.astDiff.actions.classifier.ExtendedTreeClassifier;
Expand Down Expand Up @@ -136,7 +137,6 @@ private String getRightJsConfig() {
}
appendRange(b, t, tag, null);
}

}
b.append("]").append(",");
b.append("}");
Expand Down Expand Up @@ -164,6 +164,8 @@ private String getRightJsConfig() {

private String getMappingsJsConfig() {
if (diff instanceof ASTDiff) {
ASTDiff astDiff = (ASTDiff) diff;
MappingStore monoMappingStore = astDiff.getAllMappings().getMonoMappingStore();
ExtendedTreeClassifier c = (ExtendedTreeClassifier) diff.createRootNodesClassifier();
StringBuilder b = new StringBuilder();
b.append("[");
Expand All @@ -172,6 +174,15 @@ private String getMappingsJsConfig() {
Tree d = ((ASTDiff)diff).getAllMappings().getDsts(t).iterator().next();
b.append(String.format("[%s, %s, %s, %s], ", t.getPos(), t.getEndPos(), d.getPos(), d.getEndPos()));
}
else {
if (monoMappingStore.isSrcMapped(t)) {
b.append(String.format("[%s, %s, %s, %s], ",
t.getPos(),
t.getEndPos(),
monoMappingStore.getDstForSrc(t).getPos(),
monoMappingStore.getDstForSrc(t).getEndPos()));
}
}
}
b.append("]").append(",");
return b.toString();
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/web/dist/monaco.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ require(['vs/editor/editor.main'], function() {
leftEditor.onMouseDown((event) => {
if (event.target.range) {
const allDecorations = leftEditor.getModel().getDecorationsInRange(event.target.range, leftEditor.id, true)
.filter(decoration => decoration.options.className == "updated" || decoration.options.className == "moved");
// .filter(decoration => decoration.options.className == "updated" || decoration.options.className == "moved");
if (allDecorations.length >= 1) {
let activatedRange = allDecorations[0].range;
if (allDecorations.length > 1) {
Expand All @@ -121,7 +121,9 @@ require(['vs/editor/editor.main'], function() {
}
}
const mapping = config.mappings.find(mapping => mapping[0].equalsRange(activatedRange))
rightEditor.revealRangeInCenter(mapping[1]);
if (mapping)
if (mapping.length > 1)
rightEditor.revealRangeInCenter(mapping[1]);
}
}
});
Expand All @@ -136,7 +138,7 @@ require(['vs/editor/editor.main'], function() {
rightEditor.onMouseDown((event) => {
if (event.target.range) {
const allDecorations = rightEditor.getModel().getDecorationsInRange(event.target.range, rightEditor.id, true)
.filter(decoration => decoration.options.className == "updated" || decoration.options.className == "moved");
// .filter(decoration => decoration.options.className == "updated" || decoration.options.className == "moved");
if (allDecorations.length >= 1) {
let activatedRange = allDecorations[0].range;
if (allDecorations.length > 1) {
Expand All @@ -146,7 +148,9 @@ require(['vs/editor/editor.main'], function() {
}
}
const mapping = config.mappings.find(mapping => mapping[1].equalsRange(activatedRange))
leftEditor.revealRangeInCenter(mapping[0]);
if (mapping)
if (mapping.length > 1)
leftEditor.revealRangeInCenter(mapping[0]);
}
}
});
Expand Down

0 comments on commit 824acbc

Please sign in to comment.