Skip to content

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

Switched to better highlighting system

Elijah Potterdfeb10e004c6
diff --git a/web/package.json b/web/package.json
index 17f0f34f7..c27c46d12 100644
--- a/web/package.json
+++ b/web/package.json
@@ -35,7 +35,6 @@
},
"type": "module",
"dependencies": {
- "caret-pos": "^2.0.0",
"lodash-es": "^4.17.21"
}
}
diff --git a/web/src/routes/+page.svelte b/web/src/routes/+page.svelte
index a9590a8c4..a4db129df 100644
--- a/web/src/routes/+page.svelte
+++ b/web/src/routes/+page.svelte
@@ -1,53 +1,31 @@
<script lang="ts">
import Suggestion from '$lib/Suggestion.svelte';
import alice from '../../../alice.txt?raw';
- import { position } from 'caret-pos';
import { highlightText } from '$lib/parse';
let content = alice;
- let editor: HTMLDivElement;
+ let highlighted = '';
+ let highlight: HTMLDivElement;
+ let editor: HTMLTextAreaElement;
- function updateContent() {
- if (editor !== null) {
- content = editor.innerText;
- }
- }
-
- function highlight(node: HTMLDivElement, text: string) {
- function action(text: string) {
- if (editor) {
- const pos = position(editor);
- highlightText(text).then((highlighted) => {
- node.innerHTML = highlighted;
- position(editor, pos.pos);
- });
- } else {
- highlightText(text).then((highlighted) => {
- node.innerHTML = highlighted;
- });
- }
- }
- action(text);
- return {
- update(text: string) {
- action(text);
- },
- onchange(text: string) {
- action(text);
- }
- };
- }
+ $: highlightText(content).then((v) => (highlighted = v));
</script>
<div class="flex flex-row w-full h-screen">
- <div
- class="flex-auto h-full p-5"
- contenteditable="true"
- use:highlight={content}
- bind:this={editor}
- placeholder="Tell your story..."
- on:input={updateContent}
- />
+ <div class="flex-auto h-full p-5 grid z-10">
+ <div class="overflow-auto" style="grid-row: 1; grid-column: 1" bind:this={highlight}>
+ <div class="whitespace-pre-wrap break-words">
+ {@html highlighted}
+ </div>
+ </div>
+ <textarea
+ class="w-full h-full m-0 rounded-none p-0 z-0 bg-transparent border-none"
+ style="grid-row: 1; grid-column: 1"
+ bind:value={content}
+ on:scroll={() => highlight.scrollTo(editor.scrollTop)}
+ bind:this={editor}
+ ></textarea>
+ </div>
<div class="flex flex-col flex-none">
<Suggestion category="grammar" title="Word Repeated">
<p>The word "the" was repeated twice</p>
diff --git a/web/yarn.lock b/web/yarn.lock
index 4bb5e1f7d..a74c29a92 100644
--- a/web/yarn.lock
+++ b/web/yarn.lock
@@ -620,11 +620,6 @@ caniuse-lite@^1.0.30001538, caniuse-lite@^1.0.30001541:
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001551.tgz#1f2cfa8820bd97c971a57349d7fd8f6e08664a3e"
integrity sha512-vtBAez47BoGMMzlbYhfXrMV1kvRF2WP/lqiMuDu1Sb4EE4LKEgjopFDSRtZfdVnslNRpOqV/woE+Xgrwj6VQlg==
-caret-pos@^2.0.0:
- version "2.0.0"
- resolved "https://registry.yarnpkg.com/caret-pos/-/caret-pos-2.0.0.tgz#f4a222a14951a1f5fa6543d73f79ec6892223326"
- integrity sha512-cOIiBS1SjzXg+LXSiQAzGg89dHDKq/y4c30+tB5hkVN7GbtXh1BNypOmjti4LwAWQrvP4y+bNG7RJFxLGoL3bA==
-
chalk@^4.0.0:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"