Skip to content

Commit

Permalink
fix code diff function
Browse files Browse the repository at this point in the history
  • Loading branch information
chensivan committed Mar 15, 2017
1 parent 34810d5 commit 7066860
Showing 1 changed file with 44 additions and 49 deletions.
93 changes: 44 additions & 49 deletions lib/response/services/response_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ module.exports = function(app) {
var mergeConflictCode = [];
var firstLineOfConflict;
var version;
var deletedLineNumber = [];

function createMarker(answer){

debugger
atom.workspace.open(answer.path).then(function(ed){

editor = ed;
Expand All @@ -50,7 +49,7 @@ module.exports = function(app) {
}

function markerDecoration(answer, editor){

debugger
editorViewMappings[editor] = new TooltipView();

// Decorate example ranges
Expand Down Expand Up @@ -152,6 +151,7 @@ module.exports = function(app) {
}

function loadCodeDiff(){
debugger;
// run through codeDiff array and add bg color depending on the properties of each element
var new_editor = atom.workspace.getActiveTextEditor();
new_editor.setText("");
Expand All @@ -161,68 +161,61 @@ module.exports = function(app) {
var location = {};

_.each(lineMarkers.codeDiff, function(line, index){

debugger
var action = line.added ? 'add' : line.removed ? 'delete' : 'nothingchanged';

//see github version, but we want to have helper version, and requester version
var textThatNeedsToBeInserted = line.value;

var temp;
// if(line.value=="\n"){
// temp = [""];
// }else {
// temp = line.value.split('\n');
// }
var currentfirst = new_editor.getLineCount();

if(action !== 'delete'){
new_editor.insertText(textThatNeedsToBeInserted);
if(line.value=="\n"){
temp = [""];
}else {
temp = line.value.split('\n');
}

new_editor.insertText(textThatNeedsToBeInserted);

// Get the new last line position, adjusted for the end of the previous line.
var currentLastLine = new_editor.getLineCount();
var currentLastLine = new_editor.getLineCount()-1;

if(action !== 'nothingchanged') {
// Create the lineMarker range.
// add color always after \n token
debugger;
var range;
// if(temp[0]==""){
range = new Range([3, 0], [3, 1]);
// }else{
// range = new Range([lastLine-1, 0], [currentLastLine, 10]);
// }
if(temp[0]==""){
range = new Range([lastLine, 0], [currentLastLine, 10]);
}else{
range = new Range([lastLine-1, 0], [currentLastLine, 10]);
}
if(action == 'delete'){
// lineMarkers.deleteMarkers.push(range)
deletedLineNumber.push({
'ra': range,
'content': textThatNeedsToBeInserted
})
action = ''
lineMarkers.deleteMarkers.push(range)
}

location = range.start;
// Create the lineMarker.
var lineMarker = new_editor.markBufferRange(range);
var lineMarker = new_editor.markBufferRange(range, {
invalidate: 'inside',
});
// Decorate the lineMarker.

new_editor.decorateMarker(lineMarker, {type: 'line-number', class: action});
debugger
new_editor.decorateMarker(lineMarker, {type: 'line', class: action});

// Add the lineMarker to our lineMarkers list.

lineMarkers.markers.push(lineMarker);

// if((temp[temp.length-1]!="")&&(index!=lineMarkers.codeDiff.length-1)&&((lineMarkers.codeDiff[index+1].value.split('\n')[0]!=""))){
// new_editor.insertText('\n')
// }
//
// if((temp[temp.length-1]=="")&&(temp.length==1)){
// new_editor.insertText('\n')
// }
if((temp[temp.length-1]!="")&&(index!=lineMarkers.codeDiff.length-1)&&((lineMarkers.codeDiff[index+1].value.split('\n')[0]!=""))){
new_editor.insertText('\n')
}

if((temp[temp.length-1]=="")&&(temp.length==1)){
new_editor.insertText('\n')
}
}

// Update the last line for future diff framgments.
// lastLine = new_editor.getLineCount();
lastLine = new_editor.getLineCount();

});

Expand Down Expand Up @@ -252,6 +245,8 @@ module.exports = function(app) {
}

function checkRemovePane(){
debugger;

atom.workspace.onDidDestroyPane(function(){
// var a = document.querySelector('atom-pane-axis.horizontal.pane-row');
var a = $('atom-pane-axis')
Expand Down Expand Up @@ -402,7 +397,7 @@ module.exports = function(app) {
if(atom.workspace.getActivePane() != atom.workspace.getPanes()[0]){
atom.workspace.activatePreviousPane();
}

debugger
atom.workspace.open(answerInfo.request_path).then(function(editor){
editor.scrollToScreenPosition([0,0],{center:true});
lineMarkers.path = {};
Expand All @@ -415,7 +410,7 @@ module.exports = function(app) {
lineMarkers.currentDev = lineMarkers.path[answerInfo.request_path];
// get answer content
lineMarkers.currentRes = answerInfo.helperCode;

debugger;
var currentDevArray = lineMarkers.currentDev.split("\n");
var currentResArray = lineMarkers.currentRes.split("\n");

Expand All @@ -428,7 +423,7 @@ module.exports = function(app) {
}else{

var answerInfo = getPathAndHelperCode(answers);

debugger
atom.workspace.open(answerInfo.request_path).then(function(editor){
editor.scrollToScreenPosition([0,0],{center:true});
lineMarkers.path = {};
Expand All @@ -439,7 +434,7 @@ module.exports = function(app) {
editor.splitRight({copyActiveItem: false});
// checkRemovePane();
//open the new path and show all the code and annotation

debugger
atom.workspace.open(answerInfo.helper_path)
.then(function(mergeTab){
lineMarkers.currentDev = lineMarkers.path[answerInfo.request_path];
Expand Down Expand Up @@ -468,7 +463,7 @@ module.exports = function(app) {
}
},
showContextInExplanation: function(codeContext, curose_location){

debugger
//remove all decoration
destroyAllMarkers();

Expand Down Expand Up @@ -500,7 +495,7 @@ module.exports = function(app) {
invalidate: 'inside',
});
// Decorate the lineMarker.

debugger
editor.decorateMarker(explanationCodeContext, {
class: 'test-pkg-highlight',
type: 'highlight'
Expand Down Expand Up @@ -539,7 +534,7 @@ module.exports = function(app) {
// marker.marker = mergeTab.markBufferRange(marker.highlights,{
// invalidate: 'never'
// });
//
// debugger
// marker.selection = mergeTab.addSelectionForBufferRange(marker.marker.getBufferRange());
// marker.decoration = mergeTab.decorateMarker(marker.marker, {
// class: 'test-pkg-highlight',
Expand Down Expand Up @@ -642,7 +637,7 @@ module.exports = function(app) {
// invalidate: 'inside',
// });
// // Decorate the lineMarker.
//
// debugger
// editor.decorateMarker(lineMarker, {type: 'line', class: action});
//
// // Add the lineMarker to our lineMarkers list.
Expand Down Expand Up @@ -687,7 +682,7 @@ module.exports = function(app) {
// function addCodeDiff(answer){
//
// return $q(function(res, rej){
//
// debugger
// atom.workspace.open(answer.path).then(function(ed){
// editor = ed;
//
Expand Down Expand Up @@ -749,13 +744,13 @@ module.exports = function(app) {
// });
//
// mergeString = mergeString.join("\n");
//
// debugger
// atom.workspace.open(answer.path).then(function(editor){
// editor.setText(mergeString);
//
// //add all markers
// var range = [];
// ;
// debugger;
// for(var i = 0; i<b.length;i++){
// if(b[i].getProperties().class.substring(0,7)=='request'){
// range.push(b[i].getProperties())
Expand Down Expand Up @@ -836,7 +831,7 @@ module.exports = function(app) {
// lineMarkers.codeDiff = jsdiff.diffJson(currentFirstPart, mergeFirstPart,{newlineIsToken:true})
// .concat(mergeConflictCode)
// .concat(jsdiff.diffJson(currentSecondPart, mergeSecondPart,{newlineIsToken:true}))
// ;
// debugger;
// // console.log(lineMarkers.codeDiff);
// setLineMarker();
//
Expand Down

0 comments on commit 7066860

Please sign in to comment.