diff --git a/src/main/scala/gitbucket/core/view/helpers.scala b/src/main/scala/gitbucket/core/view/helpers.scala index 730b827..9828128 100644 --- a/src/main/scala/gitbucket/core/view/helpers.scala +++ b/src/main/scala/gitbucket/core/view/helpers.scala @@ -10,6 +10,7 @@ import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.service.{RepositoryService, RequestCache} import gitbucket.core.util.{FileUtil, JGitUtil, StringUtil} +import org.apache.commons.codec.digest.DigestUtils import play.twirl.api.{Html, HtmlFormat} /** @@ -506,4 +507,6 @@ s"$baseUrl${if (baseUrl.contains("?")) "&" else "?"}$queryString" } + def md5(value: String): String = DigestUtils.md5Hex(value) + } diff --git a/src/main/twirl/gitbucket/core/helper/diff.scala.html b/src/main/twirl/gitbucket/core/helper/diff.scala.html index 37b53a6..3869d63 100644 --- a/src/main/twirl/gitbucket/core/helper/diff.scala.html +++ b/src/main/twirl/gitbucket/core/helper/diff.scala.html @@ -8,6 +8,11 @@ showLineNotes: Boolean)(implicit context: gitbucket.core.controller.Context) @import gitbucket.core.view.helpers @import org.eclipse.jgit.diff.DiffEntry.ChangeType + @if(showIndex){
@if(oldCommitId.isEmpty && newCommitId.isDefined) { @@ -59,7 +64,7 @@
} - @diff.oldPath → @diff.newPath + @diff.oldPath → @diff.newPath } @if(diff.changeType == ChangeType.ADD || diff.changeType == ChangeType.MODIFY){ @if(newCommitId.isDefined){ @@ -76,7 +81,7 @@ } - @diff.newPath + @diff.newPath } @if(diff.changeType == ChangeType.DELETE){ @if(oldCommitId.isDefined){ @@ -86,7 +91,7 @@ } - @diff.oldPath + @diff.oldPath } @if(diff.oldMode != diff.newMode){ @diff.oldMode → @diff.newMode @@ -180,6 +185,10 @@ } renderDiffs(); + window.onhashchange = function(){ + updateHighlighting(); + } + $('.toggle-notes').change(function() { if (!$(this).prop('checked')) { $(this).closest('table').find('.not-diff.inline-comment-form').remove(); @@ -188,7 +197,7 @@ }); $('.ignore-whitespace').change(function() { - renderOneDiff($(this).closest("table").find(".diffText"), window.viewType); + renderOneDiff($(this).closest("table").find(".diffText"), window.viewType, $(this).closest("table").find(".file-hash")[0].id); }); function getInlineContainer(where) { @@ -208,7 +217,7 @@ function showCommentForm(commitId, fileName, oldLineNumber, newLineNumber, $tr){ // assemble Ajax url - var url = '@helpers.url(repository)/commit/' + commitId + '/comment/_form?fileName=' + fileName@issueId.map { id => + '&issueId=@id' }; + let url = '@helpers.url(repository)/commit/' + commitId + '/comment/_form?fileName=' + fileName@issueId.map { id => + '&issueId=@id' }; if (!isNaN(oldLineNumber) && oldLineNumber) { url += ('&oldLineNumber=' + oldLineNumber) } @@ -218,7 +227,7 @@ // send Ajax request $.get(url, { dataType : 'html' }, function(responseContent) { // create container - var tmp; + let tmp; if (!isNaN(oldLineNumber) && oldLineNumber) { if (!isNaN(newLineNumber) && newLineNumber) { tmp = getInlineContainer(); @@ -240,16 +249,16 @@ // Add comment button $('.diff-outside').on('click','table.diff .add-comment',function() { - var $this = $(this); - var $tr = $this.closest('tr'); - var $check = $this.closest('table:not(.diff)').find('.toggle-notes'); + const $this = $(this); + const $tr = $this.closest('tr'); + const $check = $this.closest('table:not(.diff)').find('.toggle-notes'); if (!$check.prop('checked')) { $check.prop('checked', true).trigger('change'); } if (!$tr.nextAll(':not(.not-diff):first').prev().hasClass('inline-comment-form')) { - var commitId = $this.closest('.table-bordered').attr('commitId'), - fileName = $this.closest('.table-bordered').attr('fileName'), - oldLineNumber, newLineNumber; + const commitId = $this.closest('.table-bordered').attr('commitId'), + fileName = $this.closest('.table-bordered').attr('fileName'); + let oldLineNumber, newLineNumber; if (window.viewType == 0) { oldLineNumber = $this.parent().prev('.oldline').attr('line-number'); newLineNumber = $this.parent().prev('.newline').attr('line-number'); @@ -268,21 +277,37 @@ // Reply comment $('.diff-outside').on('click', '.reply-comment',function(){ - var $this = $(this); - var $tr = $this.closest('tr'); - var commitId = $this.closest('.table-bordered').attr('commitId'); - var fileName = $this.data('filename'); - var oldLineNumber = $this.data('oldline'); - var newLineNumber = $this.data('newline'); + const $this = $(this); + const $tr = $this.closest('tr'); + const commitId = $this.closest('.table-bordered').attr('commitId'); + const fileName = $this.data('filename'); + const oldLineNumber = $this.data('oldline'); + const newLineNumber = $this.data('newline'); showCommentForm(commitId, fileName, oldLineNumber, newLineNumber, $tr); }); + // Line selection + $('.diff-outside').on('click','table.diff th.line-num',function(e) { + const $this = $(this); + const hash = location.hash; + const baseUrl = location.toString().split("#")[0]; + + if (e.shiftKey == true && hash.match(/#diff-\w+-L\d+(-L\d+)?/)) { + const fragments = hash.split('-'); + window.history.pushState('', '', baseUrl + '#diff-' + fragments[1] + '-' + fragments[2] + '-' + $this[0].id.split('-')[2]); + } else { + window.history.pushState('', '', baseUrl + '#' + $this[0].id); + } + getSelection().empty(); + updateHighlighting(); + }); + function renderOneCommitCommentIntoDiff($v, diff){ //var filename = $v.attr('filename'); - var oldline = $v.attr('oldline'); - var newline = $v.attr('newline'); - var tmp; + const oldline = $v.attr('oldline'); + const newline = $v.attr('newline'); + let tmp; if (typeof oldline !== 'undefined') { if (typeof newline !== 'undefined') { tmp = getInlineContainer(); @@ -312,8 +337,8 @@ } del = 5 - add; } - var ret = $('
'); - for(var i = 0; i < 5; i++){ + const ret = $('
'); + for(let i = 0; i < 5; i++){ if(add){ ret.append(''); add--; @@ -327,13 +352,13 @@ return ret; } - function renderOneDiff(diffText, viewType){ - var table = diffText.closest("table[data-diff-id]"); - var i = table.data("diff-id"); - var ignoreWhiteSpace = table.find('.ignore-whitespace').prop('checked'); - diffUsingJS('oldText-' + i, 'newText-' + i, diffText.attr('id'), viewType, ignoreWhiteSpace); - var add = diffText.find("table").attr("add") * 1; - var del = diffText.find("table").attr("del") * 1; + function renderOneDiff(diffText, viewType, fileHash){ + const table = diffText.closest("table[data-diff-id]"); + const i = table.data("diff-id"); + const ignoreWhiteSpace = table.find('.ignore-whitespace').prop('checked'); + diffUsingJS('oldText-' + i, 'newText-' + i, diffText.attr('id'), viewType, ignoreWhiteSpace, fileHash); + const add = diffText.find("table").attr("add") * 1; + const del = diffText.find("table").attr("del") * 1; table.find(".diffstat").text(add + del + " ").append(renderStatBar(add, del)).attr("title", add + " additions & " + del + " deletions").tooltip(); $('span.diffstat[data-diff-id="' + i + '"]') .html('+' + add + '-' + del + '') @@ -347,7 +372,7 @@ }); } @if(showLineNotes){ - var fileName = table.attr('filename'); + const fileName = table.attr('filename'); $('.inline-comment').each(function(i, v) { if($(this).attr('filename') == fileName){ renderOneCommitCommentIntoDiff($(this), table); @@ -358,13 +383,13 @@ } function renderReplyComment($table){ - var elements = {}; - var filename, newline, oldline; + const elements = {}; + let filename, newline, oldline; $table.find('.comment-box-container .inline-comment').each(function(i, e){ filename = $(e).attr('filename'); newline = $(e).attr('newline'); oldline = $(e).attr('oldline'); - var key = filename + '-' + newline + '-' + oldline; + const key = filename + '-' + newline + '-' + oldline; elements[key] = { element: $(e), filename: filename, @@ -372,18 +397,18 @@ oldline: oldline }; }); - for(var key in elements){ + for(const key in elements){ filename = elements[key]['filename']; oldline = elements[key]['oldline']; //? elements[key]['oldline'] : ''; newline = elements[key]['newline']; //? elements[key]['newline'] : ''; - var $v = $('
') + const $v = $('
') .append($('')); - var tmp; + let tmp; if (typeof oldline !== 'undefined') { if (typeof newline !== 'undefined') { tmp = getInlineContainer(); @@ -399,16 +424,19 @@ } } - function renderDiffs(){ - var i = 0, diffs = $('.diffText'); + function renderDiffs() { + const diffs = $('.diffText'); + let i = 0; function render(){ - if(diffs[i]){ - var $table = renderOneDiff($(diffs[i]), window.viewType); + if (diffs[i]) { + const $table = renderOneDiff($(diffs[i]), window.viewType, $('.file-hash')[i].id); @if(hasWritePermission) { renderReplyComment($table); } i++; setTimeout(render); + } else { + updateHighlighting(); } } render(); @@ -416,7 +444,7 @@ }); function changeDisplaySetting(key, value){ - var url = ''; + let url = ''; window.params[key] = value; for(key in window.params){ if(window.params[key] != ''){ @@ -429,4 +457,47 @@ } location.href = url; } + +let scrolling = false; + +/** + * Highlight lines which are specified by URL hash. + */ +function updateHighlighting(){ + const hash = location.hash; + $('tr.highlight').removeClass('highlight'); + if (hash.match(/#diff-(\w+)-[LR]\d+(-[LR]\d+)?/)) { + const fragments = hash.substr(1).split('-'); + if (fragments.length == 3) { + const tr = $('th#diff-' + fragments[1] + '-' + fragments[2]).closest('tr'); + tr.addClass('highlight'); + if(!scrolling){ + $(window).scrollTop($('th#diff-' + fragments[1] + '-' + fragments[2]).closest('tr').offset().top); + } + } else if (fragments.length > 3) { + let highlight = false; + $('th[id^=diff-' + fragments[1] + '-').each(function(i, th) { + if (th.id.split('-')[2] == fragments[2]) { // start + highlight = true; + $(th.closest('tr')).addClass('highlight'); + } else if (highlight == true) { + if (th.id.split('-')[2] == fragments[3]) { // end + $(th.closest('tr')).addClass('highlight'); + return false; + } else { + $(th.closest('tr')).addClass('highlight'); + } + } + }); + if(!scrolling){ + $(window).scrollTop($('th#diff-' + fragments[1] + '-' + fragments[2]).closest('tr').offset().top); + } + } + } else if (hash != ''){ + if (!scrolling) { + $(window).scrollTop($(hash).offset().top); + } + } + scrolling = true; +} diff --git a/src/main/twirl/gitbucket/core/repo/blob.scala.html b/src/main/twirl/gitbucket/core/repo/blob.scala.html index b3ddd7b..45982df 100644 --- a/src/main/twirl/gitbucket/core/repo/blob.scala.html +++ b/src/main/twirl/gitbucket/core/repo/blob.scala.html @@ -106,17 +106,15 @@ } diff --git a/src/main/webapp/assets/common/css/gitbucket.css b/src/main/webapp/assets/common/css/gitbucket.css index f4420f2..700c111 100644 --- a/src/main/webapp/assets/common/css/gitbucket.css +++ b/src/main/webapp/assets/common/css/gitbucket.css @@ -292,6 +292,7 @@ table.table th.box-header { background-color: #f5f5f5; + padding: 2px; } th.box-header .octicon { @@ -604,8 +605,11 @@ padding: 20px; } -li.highlight { +li.highlight, +table.diff tr.highlight>th.delete, table.diff tr.highlight>th.insert, table.diff tr.highlight>th.equal, +table.diff tr.highlight>td.delete, table.diff tr.highlight>td.insert, table.diff tr.highlight>td.equal { background-color: #ffb; + !important } li.highlight-dark { diff --git a/src/main/webapp/assets/common/js/gitbucket.js b/src/main/webapp/assets/common/js/gitbucket.js index 22779c5..ff508d4 100644 --- a/src/main/webapp/assets/common/js/gitbucket.js +++ b/src/main/webapp/assets/common/js/gitbucket.js @@ -74,21 +74,24 @@ * @param outputId {String} element id of output element * @param viewType {Number} 0: split, 1: unified * @param ignoreSpace {Number} 0: include, 1: ignore + * @param fileHash {SString} hash used for links to line numbers */ -function diffUsingJS(oldTextId, newTextId, outputId, viewType, ignoreSpace) { - var old = $('#' + oldTextId), head = $('#' + newTextId); +function diffUsingJS(oldTextId, newTextId, outputId, viewType, ignoreSpace, fileHash) { + const old = $('#' + oldTextId), head = $('#' + newTextId); + let oldTextValue, headTextValue; old.is("textarea") ? (oldTextValue = old.data('val')) : (oldTextValue = old.attr('data-val')); - head.is("textarea") ? (headTextvalue = head.data('val')) : (headTextValue = head.attr('data-val')); - var render = new JsDiffRender({ + head.is("textarea") ? (headTextValue = head.data('val')) : (headTextValue = head.attr('data-val')); + const render = new JsDiffRender({ oldText : oldTextValue, oldTextName: old.data('file-name'), newText : headTextValue, newTextName: head.data('file-name'), ignoreSpace: ignoreSpace, - contextSize: 4 + contextSize: 4, + fileHash : fileHash }); - var diff = render[viewType == 1 ? "unified" : "split"](); - if(viewType == 1){ + const diff = render[viewType == 1 ? "unified" : "split"](); + if (viewType == 1) { diff.find('tr:last').after($('')); } else { diff.find('tr:last').after($('')); @@ -102,222 +105,224 @@ return val.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~]/g, '\\$&'); } -function JsDiffRender(params){ - var baseTextLines = (params.oldText==="")?[]:params.oldText.split(/\r\n|\r|\n/); - var headTextLines = (params.newText==="")?[]:params.newText.split(/\r\n|\r|\n/); - var sm, ctx; - if(params.ignoreSpace){ - var ignoreSpace = function(a){ return a.replace(/\s+/g,''); }; +function JsDiffRender(params) { + const baseTextLines = (params.oldText==="")?[]:params.oldText.split(/\r\n|\r|\n/); + const headTextLines = (params.newText==="")?[]:params.newText.split(/\r\n|\r|\n/); + let sm, ctx; + if (params.ignoreSpace) { + const ignoreSpace = function(a){ return a.replace(/\s+/g,''); }; sm = new difflib.SequenceMatcher( $.map(baseTextLines, ignoreSpace), $.map(headTextLines, ignoreSpace)); ctx = this.flatten(sm.get_opcodes(), headTextLines, baseTextLines, function(text){ return ignoreSpace(text) === ""; }); - }else{ + } else { sm = new difflib.SequenceMatcher(baseTextLines, headTextLines); ctx = this.flatten(sm.get_opcodes(), headTextLines, baseTextLines, function(){ return false; }); } - var oplines = this.fold(ctx, params.contextSize); + const oplines = this.fold(ctx, params.contextSize); function prettyDom(text, fileName){ - var dom = null; - return function(ln){ - if(dom===null){ - var html = prettyPrintOne( + let dom = null; + return function(ln) { + if(dom === null) { + const html = prettyPrintOne( text.replace(/&/g,'&').replace(//g,'>').replace(/^\n/, '\n\n'), (/\.([^.]*)$/.exec(fileName)||[])[1], true); - var re = /]*id="?L([0-9]+)"?[^>]*>(.*?)<\/li>/gi, h; - dom=[]; - while(h=re.exec(html)){ - dom[h[1]]=h[2]; + const re = /]*id="?L([0-9]+)"?[^>]*>(.*?)<\/li>/gi; + let h; + dom = []; + while (h = re.exec(html)) { + dom[h[1]] = h[2]; } } return dom[ln]; }; } - return this.renders(oplines, prettyDom(params.oldText, params.oldTextName), prettyDom(params.newText, params.newTextName)); + return this.renders(oplines, prettyDom(params.oldText, params.oldTextName), prettyDom(params.newText, params.newTextName), params.fileHash); } $.extend(JsDiffRender.prototype,{ - renders: function(oplines, baseTextDom, headTextDom){ + renders: function(oplines, baseTextDom, headTextDom, fileHash){ return { - split:function(){ - var table = $(''); - table.attr({add:oplines.add, del:oplines.del}); - var tbody = $('').appendTo(table); - for(var i=0;i').html('').appendTo(tbody); - break; - case 'delete': - case 'insert': - case 'equal': - $('').append( - lineNum('old',o.base, o.change), - $('
...
').html(o.base ? baseTextDom(o.base): "").addClass(o.change), - lineNum('new',o.head, o.change), - $('').html(o.head ? headTextDom(o.head): "").addClass(o.change) + split: function(){ + const table = $(''); + table.attr({ add: oplines.add, del: oplines.del }); + const tbody = $('').appendTo(table); + for (let i = 0; i < oplines.length; i++) { + const o = oplines[i]; + switch (o.change) { + case 'skip': + $('').html('').appendTo(tbody); + break; + case 'delete': + case 'insert': + case 'equal': + $('').append( + lineNum('old', o.base, o.change, fileHash), + $('').append( - lineNum('old',o.base, 'delete'), - $('').append( + lineNum('old', o.base, 'delete', fileHash), + $('
...
').html(o.base ? baseTextDom(o.base): "").addClass(o.change), + lineNum('new', o.head, o.change, fileHash), + $('').html(o.head ? headTextDom(o.head): "").addClass(o.change) ).appendTo(tbody); - break; - case 'replace': - var ld = lineDiff(baseTextDom(o.base), headTextDom(o.head)); - $('
').append(ld.base).addClass('delete'), - lineNum('new',o.head, 'insert'), - $('').append(ld.head).addClass('insert') + break; + case 'replace': + const ld = lineDiff(baseTextDom(o.base), headTextDom(o.head)); + $('
').append(ld.base).addClass('delete'), + lineNum('new', o.head, 'insert', fileHash), + $('').append(ld.head).addClass('insert') ).appendTo(tbody); - break; + break; } } return table; }, - unified:function(){ - var table = $(''); - table.attr({add:oplines.add, del:oplines.del}); - var tbody = $('').appendTo(table); - for(var i=0;i').html('')); - break; - case 'delete': - case 'insert': - case 'equal': - tbody.append($('').append( - lineNum('old',o.base, o.change), - lineNum('new',o.head, o.change), - $('').append(lineNum('old', oplines[i].base, 'delete'),'').append('').append(lineNum('old', oplines[i].base, 'delete'),'').append('
').addClass(o.change).html(o.head ? headTextDom(o.head) : baseTextDom(o.base)))); - break; - case 'replace': - var deletes = []; - while(oplines[i] && oplines[i].change == 'replace'){ - if(oplines[i].base && oplines[i].head){ - var ld = lineDiff(baseTextDom(oplines[i].base), headTextDom(oplines[i].head)); - tbody.append($('
',$('').append(ld.base))); - deletes.push($('
',lineNum('new',oplines[i].head, 'insert'),$('').append(ld.head))); - }else if(oplines[i].base){ - tbody.append($('
',$('').html(baseTextDom(oplines[i].base)))); - }else if(oplines[i].head){ - deletes.push($('
',lineNum('new',oplines[i].head, 'insert'),$('').html(headTextDom(oplines[i].head)))); + unified: function(){ + const table = $(''); + table.attr({ add: oplines.add, del: oplines.del }); + const tbody = $('').appendTo(table); + for (let i = 0; i < oplines.length; i++) { + const o = oplines[i]; + switch (o.change) { + case 'skip': + tbody.append($('').html('')); + break; + case 'delete': + case 'insert': + case 'equal': + tbody.append($('').append( + lineNum('old', o.base, o.change, fileHash), + lineNum('new', o.head, o.change, fileHash), + $('').append(lineNum('old', oplines[i].base, 'delete', fileHash), '').append('').append(lineNum('old', oplines[i].base, 'delete', fileHash), '').append('
').addClass(o.change).html(o.head ? headTextDom(o.head) : baseTextDom(o.base)))); + break; + case 'replace': + const deletes = []; + while (oplines[i] && oplines[i].change == 'replace') { + if (oplines[i].base && oplines[i].head) { + const ld = lineDiff(baseTextDom(oplines[i].base), headTextDom(oplines[i].head)); + tbody.append($('
', $('').append(ld.base))); + deletes.push($('
',lineNum('new', oplines[i].head, 'insert', fileHash),$('').append(ld.head))); + } else if(oplines[i].base) { + tbody.append($('
', $('').html(baseTextDom(oplines[i].base)))); + } else if(oplines[i].head) { + deletes.push($('
',lineNum('new', oplines[i].head, 'insert', fileHash), $('').html(headTextDom(oplines[i].head)))); + } + i++; } - i++; - } - tbody.append(deletes); - i--; - break; + tbody.append(deletes); + i--; + break; } } return table; } }; - function lineNum(type, num, klass){ - var cell = $('').addClass(type+'line').addClass(klass); - if(num){ - cell.attr('line-number',num); + function lineNum(type, num, klass, hash) { + const cell = $('').addClass(type + 'line').addClass(klass); + if (num) { + cell.attr('line-number', num); + cell.attr('id', hash + '-' + (type == 'old' ? 'L' : 'R') + num); } return cell; } - function lineDiff(b,n){ - var bc = $('').html(b).children(); - var nc = $('').html(n).children(); - var textE = function(){ return $(this).text(); }; - var sm = new difflib.SequenceMatcher(bc.map(textE), nc.map(textE)); - var op = sm.get_opcodes(); - if(op.length==1 || sm.ratio()<0.5){ - return {base:bc,head:nc}; + function lineDiff(b, n) { + const bc = $('').html(b).children(); + const nc = $('').html(n).children(); + const textE = function(){ return $(this).text(); }; + const sm = new difflib.SequenceMatcher(bc.map(textE), nc.map(textE)); + const op = sm.get_opcodes(); + if (op.length == 1 || sm.ratio() < 0.5) { + return { base:bc, head:nc }; } - var ret = { base : [], head: []}; - for(var i=0;i').append(bc.slice(o[1],o[2]))); - } - if(o[4]!=o[3]){ - ret.head.push($('').append(nc.slice(o[3],o[4]))); - } - break; + const ret = { base : [], head: []}; + for (let i = 0; i < op.length; i++) { + const o = op[i]; + switch (o[0]) { + case 'equal': + ret.base = ret.base.concat(bc.slice(o[1], o[2])); + ret.head = ret.head.concat(nc.slice(o[3], o[4])); + break; + case 'delete': + case 'insert': + case 'replace': + if(o[2] != o[1]){ + ret.base.push($('').append(bc.slice(o[1], o[2]))); + } + if(o[4] != o[3]){ + ret.head.push($('').append(nc.slice(o[3], o[4]))); + } + break; } } return ret; } }, flatten: function(opcodes, headTextLines, baseTextLines, isIgnoreLine){ - var ret = [], add=0, del=0; - for (var idx = 0; idx < opcodes.length; idx++) { - var code = opcodes[idx]; - var change = code[0]; - var b = code[1]; - var n = code[3]; - var rowcnt = Math.max(code[2] - b, code[4] - n); - for (var i = 0; i < rowcnt; i++) { + let ret = [], add = 0, del = 0; + for (let idx = 0; idx < opcodes.length; idx++) { + const code = opcodes[idx]; + const change = code[0]; + let b = code[1]; + let n = code[3]; + const rowcnt = Math.max(code[2] - b, code[4] - n); + for (let i = 0; i < rowcnt; i++) { switch(change){ - case 'insert': - add++; - ret.push({ - change:(isIgnoreLine(headTextLines[n]) ? 'equal' : change), - head: ++n - }); - break; - case 'delete': - del++; - ret.push({ - change: (isIgnoreLine(baseTextLines[b]) ? 'equal' : change), - base: ++b - }); - break; - case 'replace': - add++; - del++; - var r = {change: change}; - if(n contextSize){ + } else { + if (skips.length > contextSize) { ret.push({ - change:'skip', - start:skips[0], - end:skips[skips.length-contextSize] + change: 'skip', + start: skips[0], + end: skips[skips.length-contextSize] }); } ret = ret.concat(skips.splice(- contextSize)); @@ -326,7 +331,7 @@ bskip = 0; } } - if(skips.length > contextSize){ + if (skips.length > contextSize) { ret.push({ change:'skip', start:skips[0], @@ -344,12 +349,12 @@ */ function scrollIntoView(target){ target = $(target); - var $window = $(window); - var docViewTop = $window.scrollTop(); - var docViewBottom = docViewTop + $window.height(); + const $window = $(window); + const docViewTop = $window.scrollTop(); + const docViewBottom = docViewTop + $window.height(); - var elemTop = target.offset().top; - var elemBottom = elemTop + target.height(); + const elemTop = target.offset().top; + const elemBottom = elemTop + target.height(); if(elemBottom > docViewBottom){ $('html, body').scrollTop(elemBottom - $window.height());