Skip to content

Commit 2a3d87e

Browse files
committed
Update demo site
1 parent 6fe31ab commit 2a3d87e

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

docs-svelte-kit/src/lib/components/ESLintPlayground.svelte

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
};
2626
let current = 'foo';
2727
let color = 'red';
28+
let active = true;
2829
<` +
2930
`/script>
3031
@@ -77,6 +78,7 @@
7778
preprocess,
7879
postprocess,
7980
}
81+
let editor
8082
8183
$: serializedString = (() => {
8284
const serializeCode = DEFAULT_CODE === code ? undefined : code
@@ -122,6 +124,23 @@
122124
}
123125
return true
124126
}
127+
128+
function onClickMessage(evt, msg) {
129+
evt.stopPropagation()
130+
evt.preventDefault()
131+
if (editor) {
132+
editor.setCursorPosition({
133+
start: {
134+
line: msg.line,
135+
column: msg.column,
136+
},
137+
end: {
138+
line: msg.endLine ?? msg.line,
139+
column: msg.endColumn ?? msg.column,
140+
},
141+
})
142+
}
143+
}
125144
</script>
126145
127146
<svelte:window on:hashchange={onUrlHashChange} />
@@ -134,6 +153,7 @@
134153
<RulesSettings bind:rules />
135154
<div class="editor-content">
136155
<ESLintEditor
156+
bind:this={editor}
137157
{linter}
138158
bind:code
139159
config={{
@@ -155,7 +175,12 @@
155175
<ol>
156176
{#each messages as msg, i (`${msg.line}:${msg.column}:${msg.ruleId}@${i}`)}
157177
<li class="message">
158-
[{msg.line}:{msg.column}]:
178+
<!-- svelte-ignore a11y-invalid-attribute -->
179+
<a
180+
href="#"
181+
on:click={(evt) => onClickMessage(evt, msg)}
182+
class="message-link">[{msg.line}:{msg.column}]</a
183+
>:
159184
{msg.message}
160185
<a
161186
class="rule-link {getRule(msg.ruleId)?.classes}"
@@ -228,4 +253,7 @@
228253
.rule-link.core-rule:hover {
229254
color: #8080f2;
230255
}
256+
.message-link {
257+
color: #40b3ff;
258+
}
231259
</style>

docs-svelte-kit/src/lib/eslint/ESLintEditor.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
let rightMarkers = []
1818
1919
let messageMap = new Map()
20+
let editor
21+
22+
export function setCursorPosition(loc) {
23+
if (editor) {
24+
editor.setCursorPosition(loc)
25+
}
26+
}
2027
2128
$: showApplyFix = fix && fixedValue !== code
2229
$: {
@@ -211,6 +218,7 @@
211218

212219
<div class="eslint-editor">
213220
<MonacoEditor
221+
bind:this={editor}
214222
bind:code
215223
bind:rightCode={fixedValue}
216224
language="html"

docs-svelte-kit/src/lib/eslint/MonacoEditor.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,16 @@
185185
destroy()
186186
})
187187
188-
export function setCursorPosition(loc, { columnOffset = 0 } = {}) {
188+
export function setCursorPosition(loc) {
189189
if (editor) {
190190
const leftEditor = diffEditor ? editor?.getOriginalEditor() : editor
191191
leftEditor.setSelection({
192192
startLineNumber: loc.start.line,
193-
startColumn: loc.start.column + columnOffset,
193+
startColumn: loc.start.column,
194194
endLineNumber: loc.end.line,
195-
endColumn: loc.end.column + columnOffset,
195+
endColumn: loc.end.column,
196196
})
197+
leftEditor.revealLineInCenter(loc.start.line)
197198
}
198199
}
199200
async function updateMarkers(editor, markers) {

0 commit comments

Comments
 (0)