Skip to content

Commit

Permalink
feat: add setting
Browse files Browse the repository at this point in the history
  • Loading branch information
kometenstaub committed Mar 13, 2022
1 parent 65bd657 commit 3459fc9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/diff_view.ts
@@ -1,4 +1,4 @@
import { html } from 'diff2html';
import { Diff2HtmlConfig, html } from 'diff2html';
import { App, Modal, Notice, TFile } from 'obsidian';
import type { gHResult, vList } from './interfaces';
import type OpenSyncHistoryPlugin from './main';
Expand All @@ -23,6 +23,7 @@ export default class DiffView extends Modal {
versions: gHResult;
leftHistory: HTMLElement[];
rightHistory: HTMLElement[];
htmlConfig: Diff2HtmlConfig;

constructor(
private plugin: OpenSyncHistoryPlugin,
Expand All @@ -46,6 +47,10 @@ export default class DiffView extends Modal {
this.leftHistory = [null];
//@ts-expect-error
this.rightHistory = [null];
this.htmlConfig = {
diffStyle: this.plugin.settings.diffStyle,
matchWordsThreshold: this.plugin.settings.matchWordsThreshold,
};
// @ts-ignore
this.syncHistoryContentContainer = this.contentEl.createDiv({
cls: ['sync-history-content-container', 'diff'],
Expand Down Expand Up @@ -92,9 +97,7 @@ export default class DiffView extends Modal {
);

// create HTML from diff
const diff = html(uDiff, {
diffStyle: this.plugin.settings.diffStyle,
});
const diff = html(uDiff, this.htmlConfig);

// create both history lists
this.leftHistory = this.createHistory(this.contentEl);
Expand Down Expand Up @@ -247,9 +250,7 @@ export default class DiffView extends Modal {
}
*/
);
const diff = html(uDiff, {
diffStyle: this.plugin.settings.diffStyle,
});
const diff = html(uDiff, this.htmlConfig);
this.syncHistoryContentContainer.innerHTML = diff;
} else {
// formerly active right version
Expand Down Expand Up @@ -289,9 +290,7 @@ export default class DiffView extends Modal {
}
*/
);
const diff = html(uDiff, {
diffStyle: this.plugin.settings.diffStyle,
});
const diff = html(uDiff, this.htmlConfig);
this.syncHistoryContentContainer.innerHTML = diff;
}
});
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
@@ -1,6 +1,7 @@
export interface OpenSyncHistorySettings {
//context: string;
diffStyle: 'word' | 'char';
matchWordsThreshold: number;
colorBlind: boolean;
}

Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Expand Up @@ -7,6 +7,7 @@ import DiffView from './diff_view';
const DEFAULT_SETTINGS: OpenSyncHistorySettings = {
//context: '3',
diffStyle: 'word',
matchWordsThreshold: 0.25,
colorBlind: false,
};

Expand Down
19 changes: 19 additions & 0 deletions src/settings.ts
Expand Up @@ -53,6 +53,25 @@ export default class OpenSyncHistorySettingTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName('Match words threshold')
.setDesc('Similarity threshold for word matching, default is 0.25')
.addText((text) => {
text.setPlaceholder('0.25')
.setValue(settings.matchWordsThreshold.toString())
.onChange(async (value) => {
const newValue = value.trim();
const num = Number.parseFloat(newValue);
if (Number.isNumber(num) && 0 <= num && num <= 1) {
settings.matchWordsThreshold =
Number.parseFloat(newValue);
await this.plugin.saveSettings();
} else {
new Notice('Please enter a float between 0 and 1.');
}
});
});

new Setting(containerEl)
.setName('Colour blindness')
.setDesc('Enable colour-blind mode')
Expand Down

0 comments on commit 3459fc9

Please sign in to comment.