Skip to content

Commit 8f17d06

Browse files
committed
add setting for sync horizontal scroll #29
1 parent 4f72a7b commit 8f17d06

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Now using placeholder text to display help message #32
33
* Fixed a bug where diff was updated twice on initial run
44
* Fixed a bug where scroll was not synced on initial run
5+
* Added setting to sync horizontal scrolling #29
56

67
## 0.7.2 - 2016-04-08
78
* Fixed package disabling immediately in 1.7 beta #28

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ To stop diffing, simply close one of the panes *or* use the `Toggle` command.
2626

2727
* **Ignore Whitespace** - Will not diff whitespace when this box is checked.
2828
* **Show Word Diff** - Diffs the words between each line when this box is checked.
29+
* **Sync Horizontal Scroll** - Syncs the horizontal scrolling of the editors.
2930
* **Left Editor Color** - Specifies the highlight color for the left editor.
3031
* **Right Editor Color** - Specifies the highlight color for the right editor.
3132

lib/build-lines.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ module.exports = class DiffViewEditor {
4444
this._editor.setPlaceholderText('Paste what you want to diff here!');
4545

4646
for(var offsetLineNumber of offsetLineNumbers) {
47-
if(offsetLineNumber != 0) {
47+
if(offsetLineNumber == 0) {
48+
// add block decoration before if adding to line 0
49+
this._addOffsetDecoration(offsetLineNumber-1, lineOffsets[offsetLineNumber], 'before');
50+
} else {
4851
// add block decoration after if adding to lines > 0
4952
this._addOffsetDecoration(offsetLineNumber-1, lineOffsets[offsetLineNumber], 'after');
5053
}

lib/config-schema.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ module.exports =
99
description: 'Diffs the words between each line when this box is checked.'
1010
type: 'boolean'
1111
default: true
12+
syncHorizontalScroll:
13+
title: 'Sync Horizontal Scroll'
14+
description: 'Syncs the horizontal scrolling of the editors.'
15+
type: 'boolean'
16+
default: false
1217
leftEditorColor:
1318
title: 'Left Editor Color'
1419
description: 'Specifies the highlight color for the left editor.'

lib/split-diff.coffee

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,7 @@ module.exports = SplitDiff =
114114
@editorSubscriptions.add editors.editor2.onDidDestroy =>
115115
@disable(true)
116116

117-
# update diff on any settings change
118-
@editorSubscriptions.add atom.config.onDidChange 'split-diff.ignoreWhitespace', ({newValue, oldValue}) =>
119-
@updateDiff(editors)
120-
@editorSubscriptions.add atom.config.onDidChange 'split-diff.diffWords', ({newValue, oldValue}) =>
121-
@updateDiff(editors)
122-
@editorSubscriptions.add atom.config.onDidChange 'split-diff.leftEditorColor', ({newValue, oldValue}) =>
123-
@updateDiff(editors)
124-
@editorSubscriptions.add atom.config.onDidChange 'split-diff.rightEditorColor', ({newValue, oldValue}) =>
117+
@editorSubscriptions.add atom.config.onDidChange 'split-diff', () =>
125118
@updateDiff(editors)
126119

127120
# manually update diff if there are already two editors
@@ -156,6 +149,7 @@ module.exports = SplitDiff =
156149

157150
detailMsg = 'Ignore Whitespace: ' + @isWhitespaceIgnored
158151
detailMsg += '\nShow Word Diff: ' + @isWordDiffEnabled
152+
detailMsg += '\nSync Horizontal Scroll: ' + @getConfig('syncHorizontalScroll')
159153
atom.notifications.addInfo('Split Diff Enabled', {detail: detailMsg, dismissable: false})
160154

161155
# called by both diffPanes and the editor subscription to update the diff
@@ -165,6 +159,7 @@ module.exports = SplitDiff =
165159
@clearDiff()
166160
@isWhitespaceIgnored = @getConfig('ignoreWhitespace')
167161
@isWordDiffEnabled = @getConfig('diffWords')
162+
syncHorizontalScroll = @getConfig('syncHorizontalScroll')
168163

169164
SplitDiffCompute = require './split-diff-compute'
170165
computedDiff = SplitDiffCompute.computeDiff(editors.editor1.getText(), editors.editor2.getText(), @isWhitespaceIgnored)
@@ -176,7 +171,7 @@ module.exports = SplitDiff =
176171
if @isWordDiffEnabled
177172
@highlightWordDiff(SplitDiffCompute, @linkedDiffChunks)
178173

179-
@syncScroll = new SyncScroll(editors.editor1, editors.editor2)
174+
@syncScroll = new SyncScroll(editors.editor1, editors.editor2, syncHorizontalScroll)
180175
@syncScroll.syncPositions()
181176

182177
# called by "Disable" command

lib/sync-scroll.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var {CompositeDisposable} = require('atom');
44

55
class SyncScroll {
66

7-
constructor(editor1: TextEditor, editor2: TextEditor) {
7+
constructor(editor1: TextEditor, editor2: TextEditor, syncHorizontalScroll: boolean) {
8+
this._syncHorizontalScroll = syncHorizontalScroll;
89
this._subscriptions = new CompositeDisposable();
910
this._syncInfo = [{
1011
editor: editor1,
@@ -19,6 +20,10 @@ class SyncScroll {
1920
this._syncInfo.forEach((editorInfo, i) => {
2021
// Note that 'onDidChangeScrollTop' isn't technically in the public API.
2122
this._subscriptions.add(editorInfo.editorView.onDidChangeScrollTop(() => this._scrollPositionChanged(i)));
23+
// Note that 'onDidChangeScrollLeft' isn't technically in the public API.
24+
if(this._syncHorizontalScroll) {
25+
this._subscriptions.add(editorInfo.editorView.onDidChangeScrollLeft(() => this._scrollPositionChanged(i)));
26+
}
2227
// bind this so that the editors line up on start of package
2328
this._subscriptions.add(editorInfo.editor.emitter.on('did-change-scroll-top', () => this._scrollPositionChanged(i)));
2429
});
@@ -34,6 +39,9 @@ class SyncScroll {
3439
otherInfo.scrolling = true;
3540
try {
3641
otherInfo.editorView.setScrollTop(thisInfo.editorView.getScrollTop());
42+
if(this._syncHorizontalScroll) {
43+
otherInfo.editorView.setScrollLeft(thisInfo.editorView.getScrollLeft());
44+
}
3745
} catch (e) {
3846
//console.log(e);
3947
}

0 commit comments

Comments
 (0)