Skip to content

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

Removed items from `english_words.txt` + added underlines

Elijah Potterf1d1533fae1e
diff --git a/english_words.txt b/english_words.txt
index e115bcd95..d8ff6690b 100644
--- a/english_words.txt
+++ b/english_words.txt
@@ -132725,7 +132725,6 @@ hallmarking
hallmarks
hallmoot
hallmote
-hallo
halloa
halloaed
halloaing
diff --git a/web/src/lib/Highlights.svelte b/web/src/lib/Highlights.svelte
index 4aebe12df..3741a127b 100644
--- a/web/src/lib/Highlights.svelte
+++ b/web/src/lib/Highlights.svelte
@@ -1,6 +1,7 @@
<script lang="ts">
import type { Lint, Token, TokenKind } from '$lib/analysis';
- import { parseText, contentToString } from '$lib/analysis';
+ import { parseText, contentToString, lintText } from '$lib/analysis';
+
export let content: string;
let tokens: Token[] = [];
@@ -36,7 +37,4 @@
{/if}
{/each}
</div>
- <div class="whitespace-pre-line p-0 m-0 indent-0" style="grid-row: 1; grid-column: 1">
- {content}
- </div>
</div>
diff --git a/web/src/lib/Underlines.svelte b/web/src/lib/Underlines.svelte
new file mode 100644
index 000000000..5967da2f8
--- /dev/null
+++ b/web/src/lib/Underlines.svelte
@@ -0,0 +1,67 @@
+<script lang="ts">
+ import type { Lint, Token, TokenKind } from '$lib/analysis';
+ import { contentToString, lintText, spanContent } from '$lib/analysis';
+
+ export let content: string;
+
+ let lints: Lint[] = [];
+ $: lintText(content).then((newLints) => (lints = newLints));
+
+ function reOrgString(text: string): (string | undefined)[] {
+ if (text.trim().length == 0) {
+ return [''];
+ }
+
+ let output: (string | undefined)[] = [];
+
+ for (let chunk of text.split('\n')) {
+ if (output.length > 0) {
+ output.push(undefined);
+ } else {
+ output.push(chunk);
+ }
+ }
+
+ return output;
+ }
+
+ // string | [string, string] | null
+ $: modified = [
+ ...lints
+ .toSorted((a, b) => a.span.start - b.span.end)
+ .map((lint, index, arr) => {
+ let prev = arr[index - 1];
+
+ let prevStart = prev?.span.end ?? 0;
+ let prevEnd = lint.span.start;
+
+ let prevContent = [];
+
+ if (prevStart != prevEnd) {
+ prevContent.push(reOrgString(content.substring(prevStart, prevEnd)));
+ }
+
+ let lintContent = [spanContent(lint.span, content), 'red'];
+
+ return [...prevContent.flat(), lintContent];
+ })
+ .flat(),
+ reOrgString(content.substring(lints.at(-1)?.span.end ?? 0))
+ ];
+
+ $: console.log(modified);
+</script>
+
+<div class="grid">
+ <div class="p-0 m-0 indent-0" style="grid-row: 1; grid-column: 1">
+ {#each modified as chunk}
+ {#if chunk == null}
+ <br />
+ {:else if typeof chunk == 'string'}
+ <p class="inline">{chunk}</p>
+ {:else}
+ <p class="inline" style={`border-bottom: 1px solid ${chunk[1]}`}>{chunk[0]}</p>
+ {/if}
+ {/each}
+ </div>
+</div>
diff --git a/web/src/lib/analysis.ts b/web/src/lib/analysis.ts
index b3ce8e56a..ef3f870f8 100644
--- a/web/src/lib/analysis.ts
+++ b/web/src/lib/analysis.ts
@@ -67,6 +67,10 @@ export interface Span {
end: number;
}
+export function spanContent(span: Span, source: string): string {
+ return source.substring(span.start, span.end);
+}
+
export async function lintText(text: string): Promise<Lint[]> {
const req = await fetch(`/lint`, {
method: 'POST',
diff --git a/web/src/routes/+page.svelte b/web/src/routes/+page.svelte
index 38acd6592..8f20157e9 100644
--- a/web/src/routes/+page.svelte
+++ b/web/src/routes/+page.svelte
@@ -2,6 +2,7 @@
import Suggestion from '$lib/Suggestion.svelte';
import alice from '../../../alice.txt?raw';
import Highlights from '$lib/Highlights.svelte';
+ import Underlines from '$lib/Underlines.svelte';
import { Button } from 'flowbite-svelte';
import { lintText, applySuggestion } from '$lib/analysis';
import type { Lint } from '$lib/analysis';
@@ -23,11 +24,15 @@
<div class="flex flex-row w-full h-screen">
<div class="flex-auto h-full p-5 grid z-10">
+ <div class="overflow-auto p-0" style="grid-row: 1; grid-column: 1">
+ <Underlines {content}></Underlines>
+ </div>
<div class="overflow-auto p-0" style="grid-row: 1; grid-column: 1">
<Highlights {content}></Highlights>
</div>
<textarea
class="w-full h-full m-0 rounded-none p-0 z-0 bg-transparent border-none"
+ spellcheck="false"
style="grid-row: 1; grid-column: 1"
bind:value={content}
bind:this={editor}