Skip to content

Commit c279292

Browse files
Rich-HarrisRich Harris
and
Rich Harris
authored
fix autocomplete styles (#290)
Co-authored-by: Rich Harris <git@rich-harris.dev>
1 parent 8ef8769 commit c279292

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/routes/tutorial/[slug]/Editor.svelte

+11-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { EditorState } from '@codemirror/state';
77
import { indentWithTab } from '@codemirror/commands';
88
import { indentUnit } from '@codemirror/language';
9+
import { acceptCompletion } from '@codemirror/autocomplete';
910
import { setDiagnostics } from '@codemirror/lint';
1011
import { javascript } from '@codemirror/lang-javascript';
1112
import { html } from '@codemirror/lang-html';
@@ -17,16 +18,6 @@
1718
import { files, selected_file, selected_name, update_file, warnings } from './state.js';
1819
import './codemirror.css';
1920
20-
// TODO add more styles (selection ranges, etc)
21-
const highlights = HighlightStyle.define([
22-
{ tag: tags.tagName, color: '#c05726' },
23-
{ tag: tags.keyword, color: 'var(--sk-code-keyword)' },
24-
{ tag: tags.comment, color: 'var(--sk-code-comment)' },
25-
{ tag: tags.string, color: 'var(--sk-code-string)' }
26-
]);
27-
28-
const theme = syntaxHighlighting(highlights);
29-
3021
/** @type {HTMLDivElement} */
3122
let container;
3223
@@ -45,9 +36,17 @@
4536
const extensions = [
4637
basicSetup,
4738
EditorState.tabSize.of(2),
48-
keymap.of([indentWithTab]),
39+
keymap.of([{ key: 'Tab', run: acceptCompletion }, indentWithTab]),
4940
indentUnit.of('\t'),
50-
theme
41+
syntaxHighlighting(
42+
HighlightStyle.define([
43+
// TODO add more styles
44+
{ tag: tags.tagName, color: '#c05726' },
45+
{ tag: tags.keyword, color: 'var(--sk-code-keyword)' },
46+
{ tag: tags.comment, color: 'var(--sk-code-comment)' },
47+
{ tag: tags.string, color: 'var(--sk-code-string)' }
48+
])
49+
)
5150
];
5251
5352
$: reset($files);

src/routes/tutorial/[slug]/codemirror.css

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
}
7878
.cm-editor .cm-diagnosticText {}
7979

80+
.cm-editor .cm-tooltip.cm-tooltip-autocomplete > ul {
81+
font-family: var(--font-mono);
82+
font-size: 1.3rem;
83+
}
84+
8085

8186
@media (prefers-color-scheme: dark) {
8287
.cm-editor .cm-activeLineGutter {

0 commit comments

Comments
 (0)