From 6a003584e0b5dc1cafcc5a7c5c25425dc9ead6ea Mon Sep 17 00:00:00 2001 From: Elijah Potter Date: Mon, 15 Jan 2024 15:27:03 -0700 Subject: [PATCH] Will now scroll to focused lint --- web/src/lib/Editor.svelte | 92 ++++++++++++++++++++--------------- web/src/lib/Underlines.svelte | 4 ++ 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/web/src/lib/Editor.svelte b/web/src/lib/Editor.svelte index 71b8ca6d..202114e8 100644 --- a/web/src/lib/Editor.svelte +++ b/web/src/lib/Editor.svelte @@ -9,16 +9,22 @@ let content = alice; let lints: Lint[] = []; + let lintCards: HTMLDivElement[] = []; let focused: number | undefined; let editor: HTMLTextAreaElement | null; $: lintText(content).then((newLints) => (lints = newLints)); $: boxHeight = calcHeight(content); + $: if (focused != null && lintCards[focused]) + lintCards[focused].scrollIntoView({ behavior: 'smooth' }); $: if (editor != null && focused != null) { - let p = lints[focused].span.end; - editor.selectionStart = p; - editor.selectionEnd = p; + let lint = lints[focused % lints.length]; + if (lint != null) { + let p = lint.span.end; + editor.selectionStart = p; + editor.selectionEnd = p; + } } function calcHeight(boxContent: string): number { @@ -46,45 +52,51 @@ - +

Suggestions

- {#each lints as lint, i} - (focused = i)}> -
-
-

- {lint.lint_kind} - “ - {spanContent(lint.span, content)} - ” -

-
-
-

{lint.message}

- {#each lint.suggestions as suggestion} -
- -
- {/each} +
+ {#each lints as lint, i} +
(focused = i)} + bind:this={lintCards[i]} + > +
+
+

+ {lint.lint_kind} - “ + {spanContent(lint.span, content)} + ” +

+
+
+

{lint.message}

+ {#each lint.suggestions as suggestion} +
+ +
+ {/each} +
- - {/each} + {/each} +
diff --git a/web/src/lib/Underlines.svelte b/web/src/lib/Underlines.svelte index 3479c5ec..070c0717 100644 --- a/web/src/lib/Underlines.svelte +++ b/web/src/lib/Underlines.svelte @@ -6,6 +6,7 @@ export let focusLintIndex: number | undefined; let lints: [Lint, number][] = []; + let lintHighlights: HTMLSpanElement[] = []; $: lintText(content).then( (newLints) => @@ -13,6 +14,8 @@ .map<[Lint, number]>((lint, index) => [lint, index]) .toSorted(([a], [b]) => a.span.start - b.span.end)) ); + $: if (focusLintIndex != null && lintHighlights[focusLintIndex] != null) + lintHighlights[focusLintIndex].scrollIntoView({ behavior: 'smooth' }); function reOrgString(text: string): (string | undefined)[] { if (text.trim().length == 0) { @@ -90,6 +93,7 @@ (focusLintIndex = chunk[3]) && console.log('hit')} style={`--line-color: ${chunk[1]}; --line-width: ${chunk[2] ? '4px' : '2px'}; --bg-color: ${chunk[2] ? '#8DA9C4' : 'transparent'};`} >