Skip to content

Commit 197abcb

Browse files
committed
Will now scroll to focused lint
1 parent 2579476 commit 197abcb

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed

web/src/lib/Editor.svelte

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
let content = alice;
1010
1111
let lints: Lint[] = [];
12+
let lintCards: HTMLDivElement[] = [];
1213
let focused: number | undefined;
1314
let editor: HTMLTextAreaElement | null;
1415
1516
$: lintText(content).then((newLints) => (lints = newLints));
1617
$: boxHeight = calcHeight(content);
18+
$: if (focused != null) lintCards[focused].scrollIntoView({ behavior: 'smooth' });
1719
1820
$: if (editor != null && focused != null) {
19-
let p = lints[focused].span.end;
21+
let p = lints[focused % lints.length].span.end;
2022
editor.selectionStart = p;
2123
editor.selectionEnd = p;
2224
}
@@ -46,45 +48,51 @@
4648
<Underlines {content} bind:focusLintIndex={focused} />
4749
</div>
4850
</Card>
49-
<Card class="flex flex-col flex-none basis-[400px] overflow-auto h-full">
51+
<Card class="flex-none basis-[400px] h-full p-0">
5052
<h2 class="text-2xl font-bold m-1">Suggestions</h2>
51-
{#each lints as lint, i}
52-
<Card class="m-1 hover:translate-x-3 transition-all" on:click={() => (focused = i)}>
53-
<div class="pl-2 border-l-[3px] border-l-primary-500">
54-
<div class="flex flex-row">
55-
<h3 class="font-bold">
56-
{lint.lint_kind} - “<span class="italic">
57-
{spanContent(lint.span, content)}
58-
</span> ”
59-
</h3>
60-
</div>
61-
<div
62-
class="transition-all overflow-hidden flex flex-col justify-evenly"
63-
style={`height: ${
64-
focused === i ? `calc(55px * ${lint.suggestions.length + 1})` : '0px'
65-
}`}
66-
>
67-
<p style="height: 50px">{lint.message}</p>
68-
{#each lint.suggestions as suggestion}
69-
<div class="w-full p-[4px]">
70-
<Button
71-
color="primary"
72-
class="w-full"
73-
style="height: 40px; margin: 5px 0px;"
74-
on:click={() =>
75-
applySuggestion(content, suggestion, lint.span).then(
76-
(edited) => (content = edited)
77-
)}
78-
>
79-
Replace "{content.substring(lint.span.start, lint.span.end)}" with "{suggestion.ReplaceWith.reduce(
80-
(p, c) => p + c
81-
)}"
82-
</Button>
83-
</div>
84-
{/each}
53+
<div class="flex flex-col overflow-y-scroll overflow-x-hidden m-0 p-0">
54+
{#each lints as lint, i}
55+
<div
56+
class="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow m-1 hover:translate-x-1 transition-all"
57+
on:click={() => (focused = i)}
58+
bind:this={lintCards[i]}
59+
>
60+
<div class="pl-2 border-l-[3px] border-l-primary-500">
61+
<div class="flex flex-row">
62+
<h3 class="font-bold">
63+
{lint.lint_kind} - “<span class="italic">
64+
{spanContent(lint.span, content)}
65+
</span> ”
66+
</h3>
67+
</div>
68+
<div
69+
class="transition-all overflow-hidden flex flex-col justify-evenly"
70+
style={`height: ${
71+
focused === i ? `calc(55px * ${lint.suggestions.length + 1})` : '0px'
72+
}`}
73+
>
74+
<p style="height: 50px">{lint.message}</p>
75+
{#each lint.suggestions as suggestion}
76+
<div class="w-full p-[4px]">
77+
<Button
78+
color="primary"
79+
class="w-full"
80+
style="height: 40px; margin: 5px 0px;"
81+
on:click={() =>
82+
applySuggestion(content, suggestion, lint.span).then(
83+
(edited) => (content = edited)
84+
)}
85+
>
86+
Replace "{content.substring(lint.span.start, lint.span.end)}" with "{suggestion.ReplaceWith.reduce(
87+
(p, c) => p + c
88+
)}"
89+
</Button>
90+
</div>
91+
{/each}
92+
</div>
8593
</div>
8694
</div>
87-
</Card>
88-
{/each}
95+
{/each}
96+
</div>
8997
</Card>
9098
</div>

0 commit comments

Comments
 (0)