Skip to content

Commit

Permalink
textdiff settings
Browse files Browse the repository at this point in the history
  • Loading branch information
campersau committed Feb 29, 2020
1 parent 642c9af commit cf9a6bf
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions components/textdiff/textdiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const loadLimit = 100;
class WordWrap {
constructor() {
this.value = ko.observable(false);

this.toggle = () => {
this.value(!this.value());
};
Expand All @@ -33,9 +34,6 @@ class Type {
}

this.value = ko.observable(ungit.config.diffType || textDiff);
this.value.subscribe(() => {
programEvents.dispatch({ event: 'invalidate-diff-and-render' });
});

this.toggle = () => {
this.value(this.value() === textDiff ? sideBySideDiff : textDiff);
Expand All @@ -48,9 +46,7 @@ class Type {
class WhiteSpace {
constructor() {
this.value = ko.observable(ungit.config.ignoreWhiteSpaceDiff);
this.value.subscribe(() => {
programEvents.dispatch({ event: 'invalidate-diff-and-render' });
});

this.toggle = () => {
this.value(!this.value());
};
Expand Down Expand Up @@ -79,16 +75,15 @@ class TextDiffViewModel {
this.htmlSrc = undefined;
this.isParsed = ko.observable(false);

programEvents.add(event => {
if (event.event === "invalidate-diff-and-render" || event.event === "working-tree-changed") {
this.invalidateDiff();
if (this.isShowingDiffs()) this.render();
}
});

this.isShowingDiffs.subscribe(newValue => {
if (newValue) this.render();
});
this.textDiffType.value.subscribe(() => {
if (this.isShowingDiffs()) this.render();
});
this.whiteSpace.value.subscribe(() => {
if (this.isShowingDiffs()) this.invalidateDiff();
});

if (this.isShowingDiffs()) { this.render(); }
}
Expand All @@ -109,6 +104,7 @@ class TextDiffViewModel {

invalidateDiff() {
this.diffJson = null;
if (this.isShowingDiffs()) this.render();
}

getDiffJson() {
Expand All @@ -129,9 +125,9 @@ class TextDiffViewModel {
});
}

render(isInvalidate) {
render() {
return promise.resolve().then(() => {
if (!this.diffJson || isInvalidate) {
if (!this.diffJson) {
return this.getDiffJson();
}
}).then(() => {
Expand Down

0 comments on commit cf9a6bf

Please sign in to comment.