|
9 | 9 | let content = alice;
|
10 | 10 |
|
11 | 11 | let lints: Lint[] = [];
|
| 12 | + let lintCards: HTMLDivElement[] = []; |
12 | 13 | let focused: number | undefined;
|
13 | 14 | let editor: HTMLTextAreaElement | null;
|
14 | 15 |
|
15 | 16 | $: lintText(content).then((newLints) => (lints = newLints));
|
16 | 17 | $: boxHeight = calcHeight(content);
|
| 18 | + $: if (focused != null) lintCards[focused].scrollIntoView({ behavior: 'smooth' }); |
17 | 19 |
|
18 | 20 | $: if (editor != null && focused != null) {
|
19 |
| - let p = lints[focused].span.end; |
| 21 | + let p = lints[focused % lints.length].span.end; |
20 | 22 | editor.selectionStart = p;
|
21 | 23 | editor.selectionEnd = p;
|
22 | 24 | }
|
|
46 | 48 | <Underlines {content} bind:focusLintIndex={focused} />
|
47 | 49 | </div>
|
48 | 50 | </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"> |
50 | 52 | <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> |
85 | 93 | </div>
|
86 | 94 | </div>
|
87 |
| - </Card> |
88 |
| - {/each} |
| 95 | + {/each} |
| 96 | + </div> |
89 | 97 | </Card>
|
90 | 98 | </div>
|
0 commit comments