Skip to content
This repository was archived by the owner on Sep 8, 2018. It is now read-only.

Commit 89e9539

Browse files
committed
Add config option wrapAroundOnMoveToDiff
default true When set to false, it doesn't wrap around to first/last diff on move-to-next/previous-diff
1 parent ad83133 commit 89e9539

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

Diff for: lib/git-diff-view.coffee

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class GitDiffView
5252
firstDiffLineNumber = Math.min(newStart - 1, firstDiffLineNumber)
5353

5454
# Wrap around to the first diff in the file
55-
nextDiffLineNumber = firstDiffLineNumber unless nextDiffLineNumber?
55+
if atom.config.get('git-diff.wrapAroundOnMoveToDiff') and not nextDiffLineNumber?
56+
nextDiffLineNumber = firstDiffLineNumber
5657

5758
@moveToLineNumber(nextDiffLineNumber)
5859

@@ -73,7 +74,8 @@ class GitDiffView
7374
lastDiffLineNumber = Math.max(newStart - 1, lastDiffLineNumber)
7475

7576
# Wrap around to the last diff in the file
76-
previousDiffLineNumber = lastDiffLineNumber if previousDiffLineNumber is -1
77+
if atom.config.get('git-diff.wrapAroundOnMoveToDiff') and previousDiffLineNumber is -1
78+
previousDiffLineNumber = lastDiffLineNumber
7779

7880
@moveToLineNumber(previousDiffLineNumber)
7981

Diff for: package.json

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
"type": "boolean",
2222
"default": false,
2323
"description": "Show colored icons for added (`+`), modified (`·`) and removed (`-`) lines in the editor's gutter, instead of colored markers (`|`)."
24+
},
25+
"wrapAroundOnMoveToDiff": {
26+
"type": "boolean",
27+
"default": true,
28+
"description": "Wraps around to the first/last diff in the file when moving to next/previous diff."
2429
}
2530
}
2631
}

Diff for: spec/git-diff-spec.coffee

+23
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,29 @@ describe "GitDiff package", ->
121121
atom.commands.dispatch(editorView, 'git-diff:move-to-previous-diff')
122122
expect(editor.getCursorBufferPosition()).toEqual [4, 4]
123123

124+
describe "when the wrapAroundOnMoveToDiff config option is false", ->
125+
beforeEach ->
126+
atom.config.set 'git-diff.wrapAroundOnMoveToDiff', false
127+
128+
it "does not wraps around to the first/last diff in the file", ->
129+
editor.insertText('a')
130+
editor.setCursorBufferPosition([5])
131+
editor.deleteLine()
132+
advanceClock(editor.getBuffer().stoppedChangingDelay)
133+
134+
editor.setCursorBufferPosition([0])
135+
atom.commands.dispatch(editorView, 'git-diff:move-to-next-diff')
136+
expect(editor.getCursorBufferPosition()).toEqual [4, 4]
137+
138+
atom.commands.dispatch(editorView, 'git-diff:move-to-next-diff')
139+
expect(editor.getCursorBufferPosition()).toEqual [4, 4]
140+
141+
atom.commands.dispatch(editorView, 'git-diff:move-to-previous-diff')
142+
expect(editor.getCursorBufferPosition()).toEqual [0, 0]
143+
144+
atom.commands.dispatch(editorView, 'git-diff:move-to-previous-diff')
145+
expect(editor.getCursorBufferPosition()).toEqual [0, 0]
146+
124147
describe "when the showIconsInEditorGutter config option is true", ->
125148
beforeEach ->
126149
atom.config.set 'git-diff.showIconsInEditorGutter', true

0 commit comments

Comments
 (0)