Skip to content

Commit c5b2f82

Browse files
authored
allow changing diff view wrap option from editor too (#5875)
1 parent 063e683 commit c5b2f82

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/ext/diff/diff_test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,36 @@ module.exports = {
438438
assert.ok(!diffView.otherEditor.destroyed);
439439
diffView.detach();
440440
assert.ok(diffView.otherEditor.destroyed);
441+
},
442+
"test: wrap stays in sync": function() {
443+
editorA.setOption("wrap", "off");
444+
diffView = new InlineDiffView({ editorA, inline: "a" });
445+
446+
assert.equal(diffView.editorB.getOption("wrap"), "off");
447+
assert.equal(diffView.editorA.getOption("wrap"), "off");
448+
449+
editorA.setOption("wrap", "free");
450+
assert.equal(diffView.editorB.getOption("wrap"), "free");
451+
assert.equal(diffView.editorA.getOption("wrap"), "free");
452+
453+
diffView.detach();
454+
455+
456+
editorB.setOption("wrap", 40);
457+
diffView = new InlineDiffView({ editorB, inline: "b" });
458+
459+
assert.equal(diffView.editorB.getOption("wrap"), 40);
460+
assert.equal(diffView.editorA.getOption("wrap"), 40);
461+
462+
editorB.setOption("wrap", "free");
463+
assert.equal(diffView.editorB.getOption("wrap"), "free");
464+
assert.equal(diffView.editorA.getOption("wrap"), "free");
465+
466+
editorB.setOption("wrap", 50);
467+
assert.equal(diffView.editorB.getOption("wrap"), 50);
468+
assert.equal(diffView.editorA.getOption("wrap"), 50);
469+
470+
diffView.detach();
441471
}
442472
};
443473

src/ext/diff/inline_diff_view.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,18 @@ class InlineDiffView extends BaseDiffView {
278278
diffView.sessionB["_emit"]("changeFold", {data: {start: {row: 0}}});
279279
}
280280

281-
onChangeWrapLimit() {
282-
this.sessionB.adjustWrapLimit(this.sessionA.$wrapLimit);
281+
onChangeWrapLimit(e, session) {
282+
this.otherSession.setOption("wrap", session.getOption("wrap"));
283+
this.otherSession.adjustWrapLimit(session.$wrapLimit);
283284
this.scheduleRealign();
284285
}
285286

286287
$attachSessionsEventHandlers() {
287288
this.$attachSessionEventHandlers(this.editorA, this.markerA);
288289
this.$attachSessionEventHandlers(this.editorB, this.markerB);
289-
this.sessionA.on("changeWrapLimit", this.onChangeWrapLimit);
290-
this.sessionA.on("changeWrapMode", this.onChangeWrapLimit);
290+
var session = this.activeEditor.session;
291+
session.on("changeWrapLimit", this.onChangeWrapLimit);
292+
session.on("changeWrapMode", this.onChangeWrapLimit);
291293
}
292294

293295
$attachSessionEventHandlers(editor, marker) {
@@ -301,8 +303,9 @@ class InlineDiffView extends BaseDiffView {
301303
this.$detachSessionHandlers(this.editorA, this.markerA);
302304
this.$detachSessionHandlers(this.editorB, this.markerB);
303305
this.otherSession.bgTokenizer.lines.fill(undefined);
304-
this.sessionA.off("changeWrapLimit", this.onChangeWrapLimit);
305-
this.sessionA.off("changeWrapMode", this.onChangeWrapLimit);
306+
var session = this.activeEditor.session;
307+
session.off("changeWrapLimit", this.onChangeWrapLimit);
308+
session.off("changeWrapMode", this.onChangeWrapLimit);
306309
}
307310

308311
$detachSessionHandlers(editor, marker) {

0 commit comments

Comments
 (0)