Skip to content

Commit

Permalink
Update demo site
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jan 14, 2022
1 parent 6fe31ab commit 2a3d87e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
30 changes: 29 additions & 1 deletion docs-svelte-kit/src/lib/components/ESLintPlayground.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
};
let current = 'foo';
let color = 'red';
let active = true;
<` +
`/script>
Expand Down Expand Up @@ -77,6 +78,7 @@
preprocess,
postprocess,
}
let editor
$: serializedString = (() => {
const serializeCode = DEFAULT_CODE === code ? undefined : code
Expand Down Expand Up @@ -122,6 +124,23 @@
}
return true
}
function onClickMessage(evt, msg) {
evt.stopPropagation()
evt.preventDefault()
if (editor) {
editor.setCursorPosition({
start: {
line: msg.line,
column: msg.column,
},
end: {
line: msg.endLine ?? msg.line,
column: msg.endColumn ?? msg.column,
},
})
}
}
</script>
<svelte:window on:hashchange={onUrlHashChange} />
Expand All @@ -134,6 +153,7 @@
<RulesSettings bind:rules />
<div class="editor-content">
<ESLintEditor
bind:this={editor}
{linter}
bind:code
config={{
Expand All @@ -155,7 +175,12 @@
<ol>
{#each messages as msg, i (`${msg.line}:${msg.column}:${msg.ruleId}@${i}`)}
<li class="message">
[{msg.line}:{msg.column}]:
<!-- svelte-ignore a11y-invalid-attribute -->
<a
href="#"
on:click={(evt) => onClickMessage(evt, msg)}
class="message-link">[{msg.line}:{msg.column}]</a
>:
{msg.message}
<a
class="rule-link {getRule(msg.ruleId)?.classes}"
Expand Down Expand Up @@ -228,4 +253,7 @@
.rule-link.core-rule:hover {
color: #8080f2;
}
.message-link {
color: #40b3ff;
}
</style>
8 changes: 8 additions & 0 deletions docs-svelte-kit/src/lib/eslint/ESLintEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
let rightMarkers = []
let messageMap = new Map()
let editor
export function setCursorPosition(loc) {
if (editor) {
editor.setCursorPosition(loc)
}
}
$: showApplyFix = fix && fixedValue !== code
$: {
Expand Down Expand Up @@ -211,6 +218,7 @@

<div class="eslint-editor">
<MonacoEditor
bind:this={editor}
bind:code
bind:rightCode={fixedValue}
language="html"
Expand Down
7 changes: 4 additions & 3 deletions docs-svelte-kit/src/lib/eslint/MonacoEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,16 @@
destroy()
})
export function setCursorPosition(loc, { columnOffset = 0 } = {}) {
export function setCursorPosition(loc) {
if (editor) {
const leftEditor = diffEditor ? editor?.getOriginalEditor() : editor
leftEditor.setSelection({
startLineNumber: loc.start.line,
startColumn: loc.start.column + columnOffset,
startColumn: loc.start.column,
endLineNumber: loc.end.line,
endColumn: loc.end.column + columnOffset,
endColumn: loc.end.column,
})
leftEditor.revealLineInCenter(loc.start.line)
}
}
async function updateMarkers(editor, markers) {
Expand Down

0 comments on commit 2a3d87e

Please sign in to comment.