##// END OF EJS Templates
js: updated mergely to 3.4.1
marcink -
r347:99b6d323 default
parent child Browse files
Show More
@@ -1,4 +1,3 b''
1
2 1 /* required */
3 2 .mergely-column textarea { width: 80px; height: 200px; }
4 3 .mergely-column { float: left; }
@@ -12,17 +11,19 b''
12 11 .mergely-column { border: 1px solid #ccc; }
13 12 .mergely-active { border: 1px solid #a3d1ff; }
14 13
15 .mergely.a.rhs.start { border-top: 1px solid #ddffdd; }
16 .mergely.a.lhs.start.end,
17 .mergely.a.rhs.end { border-bottom: 1px solid #ddffdd; }
18 .mergely.a.rhs { background-color: #ddffdd; }
19 .mergely.a.lhs.start.end.first { border-bottom: 0; border-top: 1px solid #ddffdd; }
14 .mergely.a,.mergely.d,.mergely.c { color: #000; }
20 15
21 .mergely.d.lhs { background-color: #edc0c0; }
16 .mergely.a.rhs.start { border-top: 1px solid #a3d1ff; }
17 .mergely.a.lhs.start.end,
18 .mergely.a.rhs.end { border-bottom: 1px solid #a3d1ff; }
19 .mergely.a.rhs { background-color: #ddeeff; }
20 .mergely.a.lhs.start.end.first { border-bottom: 0; border-top: 1px solid #a3d1ff; }
21
22 .mergely.d.lhs { background-color: #ffe9e9; }
22 23 .mergely.d.lhs.end,
23 .mergely.d.rhs.start.end { border-bottom: 1px solid #ffdddd; }
24 .mergely.d.rhs.start.end.first { border-bottom: 0; border-top: 1px solid #ffdddd; }
25 .mergely.d.lhs.start { border-top: 1px solid #ffdddd; }
24 .mergely.d.rhs.start.end { border-bottom: 1px solid #f8e8e8; }
25 .mergely.d.rhs.start.end.first { border-bottom: 0; border-top: 1px solid #f8e8e8; }
26 .mergely.d.lhs.start { border-top: 1px solid #f8e8e8; }
26 27
27 28 .mergely.c.lhs,
28 29 .mergely.c.rhs { background-color: #fafafa; }
@@ -31,11 +32,19 b''
31 32 .mergely.c.lhs.end,
32 33 .mergely.c.rhs.end { border-bottom: 1px solid #a3a3a3; }
33 34
34 .mergely.ch.a.rhs { background-color: #ddffdd; }
35 .mergely.ch.d.lhs { background-color: #ffdddd; }
36
35 .mergely.ch.a.rhs { background-color: #ddeeff; }
36 .mergely.ch.d.lhs { background-color: #ffe9e9; text-decoration: line-through; color: red !important; }
37 37
38 38 .mergely-margin #compare-lhs-margin,
39 39 .mergely-margin #compare-rhs-margin {
40 40 cursor: pointer
41 41 }
42
43 .mergely.current.start { border-top: 1px solid #000 !important; }
44 .mergely.current.end { border-bottom: 1px solid #000 !important; }
45 .mergely.current.lhs.a.start.end,
46 .mergely.current.rhs.d.start.end { border-top: 0 !important; }
47 .mergely.current.CodeMirror-linenumber { color: #F9F9F9; font-weight: bold; background-color: #777; }
48
49 .CodeMirror-linenumber { cursor: pointer; }
50 .CodeMirror-code { color: #717171; } No newline at end of file
@@ -297,15 +297,15 b' jQuery.extend(Mgly.diff.prototype, {'
297 297 },
298 298 _optimize: function(ctx) {
299 299 var start = 0, end = 0;
300 while (start < ctx.length) {
301 while ((start < ctx.length) && (ctx.modified[start] == undefined || ctx.modified[start] == false)) {
300 while (start < ctx.codes.length) {
301 while ((start < ctx.codes.length) && (ctx.modified[start] == undefined || ctx.modified[start] == false)) {
302 302 start++;
303 303 }
304 304 end = start;
305 while ((end < ctx.length) && (ctx.modified[end] == true)) {
305 while ((end < ctx.codes.length) && (ctx.modified[end] == true)) {
306 306 end++;
307 307 }
308 if ((end < ctx.length) && (ctx.ctx[start] == ctx.codes[end])) {
308 if ((end < ctx.codes.length) && (ctx.codes[start] == ctx.codes[end])) {
309 309 ctx.modified[start] = false;
310 310 ctx.modified[end] = true;
311 311 }
@@ -438,8 +438,7 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
438 438 if (this.resized) this.resized();
439 439 },
440 440 _debug: '', //scroll,draw,calc,diff,markup,change
441 resized: function() { },
442 finished: function () { }
441 resized: function() { }
443 442 };
444 443 var cmsettings = {
445 444 mode: 'text/plain',
@@ -497,7 +496,7 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
497 496 if (direction == 'next') {
498 497 this._current_diff = Math.min(++this._current_diff, this.changes.length - 1);
499 498 }
500 else {
499 else if (direction == 'prev') {
501 500 this._current_diff = Math.max(--this._current_diff, 0);
502 501 }
503 502 this._scroll_to_change(this.changes[this._current_diff]);
@@ -540,10 +539,10 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
540 539 if (this.settings.hasOwnProperty('sidebar')) {
541 540 // dynamically enable sidebars
542 541 if (this.settings.sidebar) {
543 jQuery(this.element).find('.mergely-margin').css({display: 'block'});
542 this.element.find('.mergely-margin').css({display: 'block'});
544 543 }
545 544 else {
546 jQuery(this.element).find('.mergely-margin').css({display: 'none'});
545 this.element.find('.mergely-margin').css({display: 'none'});
547 546 }
548 547 }
549 548 var le, re;
@@ -690,12 +689,12 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
690 689 jQuery('<style type="text/css">' + cmstyle + '</style>').appendTo('head');
691 690
692 691 //bind
693 var rhstx = jQuery('#' + this.id + '-rhs').get(0);
692 var rhstx = this.element.find('#' + this.id + '-rhs').get(0);
694 693 if (!rhstx) {
695 694 console.error('rhs textarea not defined - Mergely not initialized properly');
696 695 return;
697 696 }
698 var lhstx = jQuery('#' + this.id + '-lhs').get(0);
697 var lhstx = this.element.find('#' + this.id + '-lhs').get(0);
699 698 if (!rhstx) {
700 699 console.error('lhs textarea not defined - Mergely not initialized properly');
701 700 return;
@@ -728,6 +727,38 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
728 727 );
729 728 sz(true);
730 729 }
730
731 // scrollToDiff() from gutter
732 function gutterClicked(side, line, ev) {
733 // The "Merge left/right" buttons are also located in the gutter.
734 // Don't interfere with them:
735 if (ev.target && (jQuery(ev.target).closest('.merge-button').length > 0)) {
736 return;
737 }
738
739 // See if the user clicked the line number of a difference:
740 var i, change;
741 for (i = 0; i < this.changes.length; i++) {
742 change = this.changes[i];
743 if (line >= change[side+'-line-from'] && line <= change[side+'-line-to']) {
744 this._current_diff = i;
745 // I really don't like this here - something about gutterClick does not
746 // like mutating editor here. Need to trigger the scroll to diff from
747 // a timeout.
748 setTimeout(function() { this.scrollToDiff(); }.bind(this), 10);
749 break;
750 }
751 }
752 }
753
754 this.editor[this.id + '-lhs'].on('gutterClick', function(cm, n, gutterClass, ev) {
755 gutterClicked.call(this, 'lhs', n, ev);
756 }.bind(this));
757
758 this.editor[this.id + '-rhs'].on('gutterClick', function(cm, n, gutterClass, ev) {
759 gutterClicked.call(this, 'rhs', n, ev);
760 }.bind(this));
761
731 762 //bind
732 763 var setv;
733 764 if (this.settings.lhs) {
@@ -745,23 +776,10 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
745 776 var self = this;
746 777 var led = self.editor[self.id+'-lhs'];
747 778 var red = self.editor[self.id+'-rhs'];
748
749 var yref = led.getScrollerElement().offsetHeight * 0.5; // center between >0 and 1/2
750
751 779 // set cursors
752 780 led.setCursor(Math.max(change["lhs-line-from"],0), 0); // use led.getCursor().ch ?
753 781 red.setCursor(Math.max(change["rhs-line-from"],0), 0);
754
755 // using directly CodeMirror breaks canvas alignment
756 // var ly = led.charCoords({line: Math.max(change["lhs-line-from"],0), ch: 0}, "local").top;
757
758 // calculate scroll offset for current change. Warning: returns relative y position so we scroll to 0 first.
759 led.scrollTo(null, 0);
760 red.scrollTo(null, 0);
761 self._calculate_offsets(self.id+'-lhs', self.id+'-rhs', [change]);
762 led.scrollTo(null, Math.max(change["lhs-y-start"]-yref, 0));
763 red.scrollTo(null, Math.max(change["rhs-y-start"]-yref, 0));
764 // right pane should simply follows
782 led.scrollIntoView({line: change["lhs-line-to"]});
765 783 },
766 784
767 785 _scrolling: function(editor_name) {
@@ -922,13 +940,11 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
922 940 this.trace('change', 'diff time', timer.stop());
923 941 this.changes = Mgly.DiffParser(d.normal_form());
924 942 this.trace('change', 'parse time', timer.stop());
925
926 943 if (this._current_diff === undefined && this.changes.length) {
927 944 // go to first difference on start-up
928 945 this._current_diff = 0;
929 946 this._scroll_to_change(this.changes[0]);
930 947 }
931
932 948 this.trace('change', 'scroll_to_change time', timer.stop());
933 949 this._calculate_offsets(editor_name1, editor_name2, this.changes);
934 950 this.trace('change', 'offsets time', timer.stop());
@@ -992,7 +1008,7 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
992 1008
993 1009 // this is the distance from the top of the screen to the top of the
994 1010 // content of the first codemirror editor
995 var topnode = jQuery('#' + this.id + ' .CodeMirror-measure').first();
1011 var topnode = this.element.find('.CodeMirror-measure').first();
996 1012 var top_offset = topnode.offset().top - 4;
997 1013 if(!top_offset) return false;
998 1014
@@ -1121,11 +1137,12 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
1121 1137 return changes;
1122 1138 },
1123 1139 _markup_changes: function (editor_name1, editor_name2, changes) {
1124 jQuery('.merge-button').remove(); // clear
1140 this.element.find('.merge-button').remove(); //clear
1125 1141
1126 1142 var self = this;
1127 1143 var led = this.editor[editor_name1];
1128 1144 var red = this.editor[editor_name2];
1145 var current_diff = this._current_diff;
1129 1146
1130 1147 var timer = new Mgly.Timer();
1131 1148 led.operation(function() {
@@ -1140,6 +1157,12 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
1140 1157 led.addLineClass(llf, 'background', 'start');
1141 1158 led.addLineClass(llt, 'background', 'end');
1142 1159
1160 if (current_diff == i) {
1161 if (llf != llt) {
1162 led.addLineClass(llf, 'background', 'current');
1163 }
1164 led.addLineClass(llt, 'background', 'current');
1165 }
1143 1166 if (llf == 0 && llt == 0 && rlf == 0) {
1144 1167 led.addLineClass(llf, 'background', clazz.join(' '));
1145 1168 led.addLineClass(llf, 'background', 'first');
@@ -1186,6 +1209,12 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
1186 1209 red.addLineClass(rlf, 'background', 'start');
1187 1210 red.addLineClass(rlt, 'background', 'end');
1188 1211
1212 if (current_diff == i) {
1213 if (rlf != rlt) {
1214 red.addLineClass(rlf, 'background', 'current');
1215 }
1216 red.addLineClass(rlt, 'background', 'current');
1217 }
1189 1218 if (rlf == 0 && rlt == 0 && llf == 0) {
1190 1219 red.addLineClass(rlf, 'background', clazz.join(' '));
1191 1220 red.addLineClass(rlf, 'background', 'first');
@@ -1286,11 +1315,12 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
1286 1315 self.chfns[self.id + '-rhs'].push(m[0].markText(m[1], m[2], m[3]));
1287 1316 }
1288 1317 });
1318
1289 1319 this.trace('change', 'LCS markup time', timer.stop());
1290 1320
1291 1321 // merge buttons
1292 1322 var ed = {lhs:led, rhs:red};
1293 jQuery('.merge-button').on('click', function(ev){
1323 this.element.find('.merge-button').on('click', function(ev){
1294 1324 // side of mouseenter
1295 1325 var side = 'rhs';
1296 1326 var oside = 'lhs';
@@ -1314,6 +1344,35 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
1314 1344 self._merge_change(change, side, oside);
1315 1345 return false;
1316 1346 });
1347
1348 // gutter markup
1349 var lhsLineNumbers = $('#mergely-lhs ~ .CodeMirror').find('.CodeMirror-linenumber');
1350 var rhsLineNumbers = $('#mergely-rhs ~ .CodeMirror').find('.CodeMirror-linenumber');
1351 rhsLineNumbers.removeClass('mergely current');
1352 lhsLineNumbers.removeClass('mergely current');
1353 for (var i = 0; i < changes.length; ++i) {
1354 if (current_diff == i && change.op !== 'd') {
1355 var change = changes[i];
1356 var j, jf = change['rhs-line-from'], jt = change['rhs-line-to'] + 1;
1357 for (j = jf; j < jt; j++) {
1358 var n = (j + 1).toString();
1359 rhsLineNumbers
1360 .filter(function(i, node) { return $(node).text() === n; })
1361 .addClass('mergely current');
1362 }
1363 }
1364 if (current_diff == i && change.op !== 'a') {
1365 var change = changes[i];
1366 jf = change['lhs-line-from'], jt = change['lhs-line-to'] + 1;
1367 for (j = jf; j < jt; j++) {
1368 var n = (j + 1).toString();
1369 lhsLineNumbers
1370 .filter(function(i, node) { return $(node).text() === n; })
1371 .addClass('mergely current');
1372 }
1373 }
1374 }
1375
1317 1376 this.trace('change', 'markup buttons time', timer.stop());
1318 1377 },
1319 1378 _merge_change : function(change, side, oside) {
@@ -1373,8 +1432,8 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
1373 1432 var gutter_height = jQuery(this.editor[editor_name1].getScrollerElement()).children(':first-child').height();
1374 1433 var dcanvas = document.getElementById(editor_name1 + '-' + editor_name2 + '-canvas');
1375 1434 if (dcanvas == undefined) throw 'Failed to find: ' + editor_name1 + '-' + editor_name2 + '-canvas';
1376 var clhs = jQuery('#' + this.id + '-lhs-margin');
1377 var crhs = jQuery('#' + this.id + '-rhs-margin');
1435 var clhs = this.element.find('#' + this.id + '-lhs-margin');
1436 var crhs = this.element.find('#' + this.id + '-rhs-margin');
1378 1437 return {
1379 1438 visible_page_height: visible_page_height,
1380 1439 gutter_height: gutter_height,
@@ -1405,7 +1464,7 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
1405 1464 this.trace('draw', 'lhs-scroller-top', ex.lhs_scroller.scrollTop());
1406 1465 this.trace('draw', 'rhs-scroller-top', ex.rhs_scroller.scrollTop());
1407 1466
1408 jQuery.each(jQuery.find('#' + this.id + ' canvas'), function () {
1467 jQuery.each(this.element.find('canvas'), function () {
1409 1468 jQuery(this).get(0).height = ex.visible_page_height;
1410 1469 });
1411 1470
@@ -1427,6 +1486,10 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
1427 1486 var vp = this._get_viewport(editor_name1, editor_name2);
1428 1487 for (var i = 0; i < changes.length; ++i) {
1429 1488 var change = changes[i];
1489 var fill = this.settings.fgcolor[change['op']];
1490 if (this._current_diff==i) {
1491 fill = '#000';
1492 }
1430 1493
1431 1494 this.trace('draw', change);
1432 1495 // margin indicators
@@ -1437,14 +1500,14 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
1437 1500 this.trace('draw', 'marker calculated', lhs_y_start, lhs_y_end, rhs_y_start, rhs_y_end);
1438 1501
1439 1502 ctx_lhs.beginPath();
1440 ctx_lhs.fillStyle = this.settings.fgcolor[(this._current_diff==i?'c':'')+change['op']];
1503 ctx_lhs.fillStyle = fill;
1441 1504 ctx_lhs.strokeStyle = '#000';
1442 1505 ctx_lhs.lineWidth = 0.5;
1443 1506 ctx_lhs.fillRect(1.5, lhs_y_start, 4.5, Math.max(lhs_y_end - lhs_y_start, 5));
1444 1507 ctx_lhs.strokeRect(1.5, lhs_y_start, 4.5, Math.max(lhs_y_end - lhs_y_start, 5));
1445 1508
1446 1509 ctx_rhs.beginPath();
1447 ctx_rhs.fillStyle = this.settings.fgcolor[(this._current_diff==i?'c':'')+change['op']];
1510 ctx_rhs.fillStyle = fill;
1448 1511 ctx_rhs.strokeStyle = '#000';
1449 1512 ctx_rhs.lineWidth = 0.5;
1450 1513 ctx_rhs.fillRect(1.5, rhs_y_start, 4.5, Math.max(rhs_y_end - rhs_y_start, 5));
@@ -1463,7 +1526,7 b' jQuery.extend(Mgly.CodeMirrorDiffView.pr'
1463 1526
1464 1527 // draw left box
1465 1528 ctx.beginPath();
1466 ctx.strokeStyle = this.settings.fgcolor[(this._current_diff==i?'c':'')+change['op']];
1529 ctx.strokeStyle = fill;
1467 1530 ctx.lineWidth = (this._current_diff==i) ? 1.5 : 1;
1468 1531
1469 1532 var rectWidth = this.draw_lhs_width;
General Comments 0
You need to be logged in to leave comments. Login now