From d761609e54fbb0500cce983a35ea5956a8e093df Mon Sep 17 00:00:00 2001 From: zhudock Date: Tue, 28 Feb 2017 15:55:52 -0500 Subject: [PATCH] Add wrapdiff option for scrollToDiff next\prev to wrap to start\end of text. resolves #57 --- lib/mergely.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/mergely.js b/lib/mergely.js index 80447c4..0f48af3 100644 --- a/lib/mergely.js +++ b/lib/mergely.js @@ -395,6 +395,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { viewport: false, ignorews: false, ignorecase: false, + wrapdiff: false, fadein: 'fast', editor_width: '650px', editor_height: '400px', @@ -498,10 +499,18 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { scrollToDiff: function(direction) { if (!this.changes.length) return; if (direction == 'next') { - this._current_diff = Math.min(++this._current_diff, this.changes.length - 1); + if (this.settings.wrapdiff && this._current_diff == this.changes.length -1) { + this._current_diff = 0; + } else { + this._current_diff = Math.min(++this._current_diff, this.changes.length - 1); + } } else if (direction == 'prev') { - this._current_diff = Math.max(--this._current_diff, 0); + if (this.settings.wrapdiff && this._current_diff == 0) { + this._current_diff = this.changes.length - 1; + } else { + this._current_diff = Math.max(--this._current_diff, 0); + } } this._scroll_to_change(this.changes[this._current_diff]); this._changed(this.id + '-lhs', this.id + '-rhs');