Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat(chrome-ext): add buttons to reset and toggle all rules (#2174)

Elijah Potter33e06c9b0f49
diff --git a/packages/chrome-plugin/src/options/Options.svelte b/packages/chrome-plugin/src/options/Options.svelte
index c31be964a..22e9d5fa1 100644
--- a/packages/chrome-plugin/src/options/Options.svelte
+++ b/packages/chrome-plugin/src/options/Options.svelte
@@ -13,6 +13,7 @@ let dialect = $state(Dialect.American);
let defaultEnabled = $state(false);
let activationKey: ActivationKey = $state(ActivationKey.Off);
let userDict = $state('');
+let anyRulesEnabled = $derived(Object.values(lintConfig ?? {}).some((value) => value !== false));
$effect(() => {
ProtocolClient.setLintConfig($state.snapshot(lintConfig));
@@ -97,6 +98,34 @@ export function dictToString(values: string[]): string {
return values.map((v) => v.trim()).join('\n');
}
+function resetRulesToDefaults(): void {
+ const keys = Object.keys(lintConfig ?? {});
+ if (keys.length === 0) return;
+
+ const nextConfig: LintConfig = { ...lintConfig };
+ for (const key of keys) {
+ nextConfig[key] = null;
+ }
+ lintConfig = nextConfig;
+}
+
+function updateAllRules(enabled: boolean): void {
+ const keys = Object.keys(lintConfig ?? {});
+ if (keys.length === 0) {
+ return;
+ }
+
+ const nextConfig: LintConfig = { ...lintConfig };
+ for (const key of keys) {
+ nextConfig[key] = enabled;
+ }
+ lintConfig = nextConfig;
+}
+
+function toggleAllRules(): void {
+ updateAllRules(!anyRulesEnabled);
+}
+
async function exportEnabledDomainsCSV() {
try {
const enabledDomains = await ProtocolClient.getEnabledDomains();
@@ -197,8 +226,18 @@ async function exportEnabledDomainsCSV() {
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500">Rules</h3>
<Input bind:value={searchQuery} placeholder="Search for a rule…" size="sm" class="w-60" />
</div>
+ <div class="flex flex-wrap gap-3">
+ <Button size="sm" color="light" on:click={resetRulesToDefaults}>Reset to Default Rules</Button>
+ <Button size="sm" color="light" on:click={toggleAllRules}>
+ {anyRulesEnabled ? 'Disable All Rules' : 'Enable All Rules'}
+ </Button>
+ </div>
- {#each Object.entries(lintConfig).filter(([key]) => lintDescriptions[key].toLowerCase().includes(searchQueryLower) || key.toLowerCase().includes(searchQueryLower)) as [key, value]}
+ {#each Object.entries(lintConfig).filter(
+ ([key]) =>
+ (lintDescriptions[key] ?? '').toLowerCase().includes(searchQueryLower) ||
+ key.toLowerCase().includes(searchQueryLower)
+ ) as [key, value]}
<div class="space-y-4 max-h-80 overflow-y-auto pr-1">
<!-- rule card sample -->
<div class="rounded-lg border border-gray-200 p-3 shadow-sm">
diff --git a/packages/lint-framework/src/lint/LintFramework.ts b/packages/lint-framework/src/lint/LintFramework.ts
index 34fdf1134..624609a59 100644
--- a/packages/lint-framework/src/lint/LintFramework.ts
+++ b/packages/lint-framework/src/lint/LintFramework.ts
@@ -146,6 +146,19 @@ export default class LintFramework {
}
}
+ /** Get the individual lints produced the last time the text on the screen was scanned. */
+ public getLastLints(): UnpackedLint[] {
+ const lints = [];
+
+ for (const group of this.lastLints) {
+ for (const groupLints of Object.values(group.lints)) {
+ lints.push(...groupLints);
+ }
+ }
+
+ return lints;
+ }
+
private attachTargetListeners(target: Node) {
for (const event of INPUT_EVENTS) {
target.addEventListener(event, this.updateEventCallback);