Skip to content

Commit 9291674

Browse files
Merge pull request #1015 from Automattic/obsidian-debounce
feat(obsidian): add debounce setting
2 parents 871965c + af81143 commit 9291674

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/obsidian-plugin/src/HarperSettingTab.ts

+16
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ export class HarperSettingTab extends PluginSettingTab {
5454
});
5555
});
5656

57+
new Setting(containerEl)
58+
.setName('Delay')
59+
.setDesc(
60+
'Set the delay (in milliseconds) before Harper checks your work after you make a change. Set to -1 for no delay.',
61+
)
62+
.addSlider((slider) => {
63+
slider
64+
.setDynamicTooltip()
65+
.setLimits(-1, 10000, 50)
66+
.setValue(this.settings.delay ?? -1)
67+
.onChange(async (value) => {
68+
this.settings.delay = value;
69+
await this.plugin.initializeFromSettings(this.settings);
70+
});
71+
});
72+
5773
new Setting(containerEl).setName('The Danger Zone').addButton((button) => {
5874
button
5975
.setButtonText('Forget Ignored Suggestions')

packages/obsidian-plugin/src/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,27 @@ function suggestionToLabel(sug: Suggestion) {
2424
}
2525
}
2626

27+
const DEFAULT_DELAY = -1;
28+
2729
export type Settings = {
2830
ignoredLints?: string;
2931
useWebWorker: boolean;
3032
dialect?: Dialect;
3133
lintSettings: LintConfig;
3234
userDictionary?: string[];
35+
delay?: number;
3336
};
3437

3538
export default class HarperPlugin extends Plugin {
3639
private harper: Linter;
3740
private editorExtensions: Extension[];
41+
private delay: number;
3842

3943
constructor(app: App, manifest: PluginManifest) {
4044
super(app, manifest);
4145
this.harper = new WorkerLinter({ binary: binaryInlined });
4246
this.editorExtensions = [];
47+
this.delay = DEFAULT_DELAY;
4348
}
4449

4550
public async initializeFromSettings(settings: Settings | null) {
@@ -73,6 +78,8 @@ export default class HarperPlugin extends Plugin {
7378
await this.harper.setLintConfig(settings.lintSettings);
7479
this.harper.setup();
7580

81+
this.delay = settings.delay ?? DEFAULT_DELAY;
82+
7683
// Reinitialize it.
7784
if (this.hasEditorLinter()) {
7885
this.disableEditorLinter();
@@ -96,6 +103,7 @@ export default class HarperPlugin extends Plugin {
96103
lintSettings: await this.harper.getLintConfig(),
97104
userDictionary: await this.harper.exportWords(),
98105
dialect: await this.harper.getDialect(),
106+
delay: this.delay,
99107
};
100108
}
101109

@@ -259,7 +267,7 @@ export default class HarperPlugin extends Plugin {
259267
});
260268
},
261269
{
262-
delay: -1,
270+
delay: this.delay,
263271
},
264272
);
265273
}

0 commit comments

Comments
 (0)