diff --git a/demos/demo1/tmp.html b/demos/demo1/tmp.html index b1abeb8..293e922 100644 --- a/demos/demo1/tmp.html +++ b/demos/demo1/tmp.html @@ -8,57 +8,79 @@
-
-one -two -three -- -- -- -- -- -- -- -- - // instantiate the editors in an internal data structure that will store a little info about the diffs and - // editor content - this.editors = { - left: { - ace: ace.edit(this.options.left.id), - markers: [], - lineLengths: []s - }, - right: { - ace: ace.edit(this.options.right.id), - markers: [], - lineLengths: [] - } - }; +
{ + "name": "ace-diff", + "version": "0.1.0", + "date": "Mar 7th, 2015", + + + "description": "A diff/merging wrapper for Ace Editor built on google-diff-match-patch", + "main": "dist/ace-diff.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/benkeen/ace-diff.git" + }, + "keywords": [ + "ace", + "dif", + "merging", + "ace editor", + "syntax highlighting" + ], + "author": "Ben Keen", + "license": "MIT", + "bugs": { + "url": "https://github.com/benkeen/ace-diff/issues" + }, + "homepage": "https://github.com/benkeen/ace-diff", + "devDependencies": { + "grunt": "^0.4.5", + "grunt-contrib-uglify": "^0.8.0", + "grunt-contrib-clean": "~0.5.0", + "grunt-contrib-watch": "~0.5.3", + "grunt-contrib-jshint": "^0.10.0" } -}));
+} +
-
-one -two -three -- -- - // instantiate the editors in an internal data structure that will store a little info about the diffs and - // editor content - this.editors = { - left: { - ace: ace.edit(this.options.left.id), - markers: [], - lineLengths: [] - }, - right: { - ace: ace.edit(this.options.right.id), - markers: [], - lineLengths: [] - } - }; +
{ + "name": "ace-diff", + "version": "0.1.0", + "date": "Mar 7th, 2015", + "description": "A diff/merging wrapper for Ace Editor built on google-diff-match-patch", + "main": "dist/ace-diff.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/benkeen/ace-diff.git" + }, + "keywords": [ + "ace", + "dif", + "merging", + "ace editor", + "syntax highlighting" + ], + "author": "Ben Keen", + "license": "MIT", + "bugs": { + "url": "https://github.com/benkeen/ace-diff/issues" + }, + "homepage": "https://github.com/benkeen/ace-diff", + "devDependencies": { + "grunt": "^0.4.5", + "grunt-contrib-uglify": "^0.8.0", + "grunt-contrib-clean": "~0.5.0", + "grunt-contrib-watch": "~0.5.3", + "grunt-contrib-jshint": "^0.10.0" } -}));
+} +
diff --git a/dist/ace-diff.js b/dist/ace-diff.js index ce52745..09aeae8 100644 --- a/dist/ace-diff.js +++ b/dist/ace-diff.js @@ -298,7 +298,7 @@ } - + // this code is so terrible, the human race hasn't invented a word to properly encapsulate it function lockScrolling(acediff, sourceEditor, scroll) { // find the middle line in the source editor @@ -334,48 +334,67 @@ var targetDiffInPixels = targetDiffHeight * acediff.lineHeight; var sourceDiffInPixels = (sourceDiffEnd - sourceDiffStart) * acediff.lineHeight; targetScrollHeight = parseInt(scroll) + (targetOffset * acediff.lineHeight) + (ratio * targetDiffInPixels) - (ratio * sourceDiffInPixels); - } + } else { - // additional adjustments for the top/end when a user scrolls an editor that has less space than the other. These always - // override the above logic + // additional adjustments for the top/end when a user scrolls an editor that has less space than the other. These always + // override the above logic - // TOP - if (scroll < halfEditorHeight) { - scroll = scroll > 0 ? scroll : 0; - var targetOffsetHeight = targetOffset * acediff.lineHeight; - var ratio = scroll / halfEditorHeight; - targetScrollHeight = (targetOffsetHeight + halfEditorHeight) * ratio; - } + var totalSourceEditorHeight = getTotalHeight(acediff, sourceEditor); + + // TOP + if (scroll < halfEditorHeight) { + scroll = scroll > 0 ? scroll : 0; + var targetOffsetHeight = targetOffset * acediff.lineHeight; + var ratio = scroll / halfEditorHeight; + targetScrollHeight = (targetOffsetHeight + halfEditorHeight) * ratio; + } + + // BOTTOM + else if (scroll + (3 * halfEditorHeight) > totalSourceEditorHeight) { + + // we don't want to ALWAYS apply this logic. Only if the other side won't scroll fully into view with the current editor + var exactPixelLine = totalSourceEditorHeight - halfEditorHeight; + var line2 = Math.floor(exactPixelLine / acediff.lineHeight); + var remainingPixels = exactPixelLine % acediff.lineHeight; - // BOTTOM - var totalSourceEditorHeight = getTotalHeight(acediff, sourceEditor); - if (scroll + 3 * halfEditorHeight > totalSourceEditorHeight) { - var line2 = Math.floor((totalSourceEditorHeight - halfEditorHeight) / acediff.lineHeight); - var bottomOffsets = getScrollOffsets(acediff, line2); + var bottomOffsets = getScrollOffsets(acediff, line2); + var totalTargetEditorHeight = getTotalHeight(acediff, targetEditor); - var totalTargetEditorHeight = getTotalHeight(acediff, targetEditor); - var diffsInPx = (bottomOffsets.totalInserts - bottomOffsets.totalDeletes) * acediff.lineHeight; - var leftBottomLine = totalTargetEditorHeight - (halfEditorHeight + diffsInPx); + var diffsInPx; + if (sourceEditor === C.EDITOR_RIGHT) { + diffsInPx = (bottomOffsets.totalInserts - bottomOffsets.totalDeletes) * acediff.lineHeight; + } else { + diffsInPx = (bottomOffsets.totalDeletes - bottomOffsets.totalInserts) * acediff.lineHeight; + } - // ratio of right editor scroll - var ratio = (totalSourceEditorHeight - (scroll + (2 * halfEditorHeight))) / halfEditorHeight; - ratio = ratio > 1 ? 1 : ratio; - ratio = ratio < 0 ? 0 : ratio; + var targetBottomLine = totalTargetEditorHeight - (halfEditorHeight + diffsInPx); - // now multiple REMAINING height in left editor with ratio - var targetEditorRemainingHeight = totalTargetEditorHeight - leftBottomLine; + // ratio of right editor scroll + var ratio = (totalSourceEditorHeight - (scroll + (2 * halfEditorHeight))) / halfEditorHeight; + ratio = ratio > 1 ? 1 : ratio; + ratio = ratio < 0 ? 0 : ratio; - // the previous var is the total height from the top of the line. Now compute the scroll height for that line - targetScrollHeight = (leftBottomLine - acediff.editors.editorHeight + (targetEditorRemainingHeight * (1 - ratio))); + // now multiple REMAINING height in other editor with ratio + var targetEditorRemainingHeight = totalTargetEditorHeight - targetBottomLine; + + var remainingSourceEditorHeight = totalSourceEditorHeight - (scroll + acediff.editors.editorHeight); + var targetEditorInst = (targetEditor === C.EDITOR_LEFT) ? acediff.editors.left : acediff.editors.right; + var remainingTargetEditorHeight = totalTargetEditorHeight - (targetEditorInst.ace.getSession().getScrollTop() + acediff.editors.editorHeight); + + if (remainingTargetEditorHeight > remainingSourceEditorHeight) { + //console.log("."); + //targetScrollHeight = (targetBottomLine - acediff.editors.editorHeight + (targetEditorRemainingHeight * (1 - ratio))); + } + } } - // final bounds checking [TODO shouldn't be necessary] - var scrollPlusHeight = scroll + acediff.editors.editorHeight; + // final bounds checking [TODO shouldn't be necessary...] + /*var scrollPlusHeight = scroll + acediff.editors.editorHeight; if (scroll <= 0) { targetScrollHeight = 0; } else if (scrollPlusHeight >= getTotalHeight(acediff, sourceEditor)) { targetScrollHeight = getTotalHeight(acediff, targetEditor) + acediff.editors.editorHeight; - } + }*/ return targetScrollHeight; } @@ -874,6 +893,7 @@ } + // TODO. This doesn't work on Safari or IE function clearGutter(gutter) { gutter.innerHTML = ''; //for (var i=0; i