Skip to content

Commit

Permalink
fix: catch error in diffView
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Mar 22, 2023
1 parent c5a2cbf commit cbff377
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions src/ui/diff/diffView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,38 @@ export default class DiffView extends ItemView {
async refresh(): Promise<void> {
if (this.state?.file && !this.gettingDiff && this.plugin.gitManager) {
this.gettingDiff = true;
let diff = await this.plugin.gitManager.getDiffString(
this.state.file,
this.state.staged,
this.state.hash
);
this.contentEl.empty();
if (!diff) {
const content = await this.app.vault.adapter.read(
this.plugin.gitManager.getVaultPath(this.state.file)
try {
let diff = await this.plugin.gitManager.getDiffString(
this.state.file,
this.state.staged,
this.state.hash
);
const header = `--- /dev/null
this.contentEl.empty();
if (!diff) {
const content = await this.app.vault.adapter.read(
this.plugin.gitManager.getVaultPath(this.state.file)
);
const header = `--- /dev/null
+++ ${this.state.file}
@@ -0,0 +1,${content.split("\n").length} @@`;

diff = [
...header.split("\n"),
...content.split("\n").map((line) => `+${line}`),
].join("\n");
}
diff = [
...header.split("\n"),
...content.split("\n").map((line) => `+${line}`),
].join("\n");
}

const diffEl = this.parser
.parseFromString(html(diff), "text/html")
.querySelector(".d2h-file-diff");
this.contentEl.append(diffEl!);
// const div = this.contentEl.createDiv({ cls: 'diff-err' });
// div.createSpan({ text: '⚠️', cls: 'diff-err-sign' });
// div.createEl('br');
// div.createSpan({ text: 'No changes to ' + this.state.file });
this.gettingDiff = false;
const diffEl = this.parser
.parseFromString(html(diff), "text/html")
.querySelector(".d2h-file-diff");
this.contentEl.append(diffEl!);
// const div = this.contentEl.createDiv({ cls: 'diff-err' });
// div.createSpan({ text: '⚠️', cls: 'diff-err-sign' });
// div.createEl('br');
// div.createSpan({ text: 'No changes to ' + this.state.file });
} finally {
this.gettingDiff = false;
}
}
}
}

0 comments on commit cbff377

Please sign in to comment.