Skip to content

Commit fd74332

Browse files
committed
Highlight active line
1 parent e070154 commit fd74332

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

src/components/index-page/how-it-works/how-it-works-list-item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function HowItWorksListItem({
1313
{text}
1414
{icon}
1515
</div>
16-
<div className="mt-px flex-1 bg-neu-0 text-sm/[21px] [--cm-background:transparent] md:pl-2 md:[&_:is(pre,.cm-content)]:!pt-5 max-md:[&_code>span]:!pl-0 [&_pre]:border-none [&_pre]:ring-0">
16+
<div className="mt-px flex-1 bg-neu-0 text-sm/[21px] [--cm-background:transparent] md:[&_:is(.cm-line,.nextra-code>span)]:!pl-5 md:[&_:is(pre,.cm-content)]:!pt-5 max-md:[&_code>span]:!pl-0 [&_pre]:border-none [&_pre]:ring-0">
1717
{code}
1818
</div>
1919
</li>

src/components/index-page/how-it-works/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function HowItWorks() {
3535
<SectionLabel className="mb-6">How it works</SectionLabel>
3636
<h2 className="typography-h2 mb-6 lg:mb-16">A GraphQL Query</h2>
3737
<div className="relative">
38+
{/* eslint-disable-next-line tailwindcss/no-custom-classname*/}
3839
<ol className="gql-radial-gradient list-none gap-px max-md:bg-gradient-to-r max-md:from-transparent max-md:via-neu-400 max-md:to-transparent lg:grid lg:grid-cols-3">
3940
<HowItWorksListItem
4041
text="Describe your data"
@@ -53,7 +54,7 @@ export function HowItWorks() {
5354
{inView && (
5455
<ol
5556
// this is rendered *on top* of the static version to avoid layout shift
56-
className="pointer-events-none absolute inset-0 list-none gap-px *:pointer-events-auto lg:grid lg:grid-cols-3 lg:[&>:first-child]:col-start-2"
57+
className="pointer-events-none absolute inset-0 list-none gap-px [counter-set:list-item_1] *:pointer-events-auto lg:grid lg:grid-cols-3 lg:[&>:first-child]:col-start-2"
5758
>
5859
<InteractiveEditor />
5960
</ol>

src/components/interactive-code-block/query-editor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from "react"
2-
import { EditorView, keymap } from "@codemirror/view"
2+
import { EditorView, keymap, highlightActiveLine } from "@codemirror/view"
33
import { EditorState } from "@codemirror/state"
44
import { history, historyKeymap, defaultKeymap } from "@codemirror/commands"
55
import { bracketMatching } from "@codemirror/language"
@@ -76,6 +76,7 @@ export class QueryEditor extends Component<QueryEditorProps> {
7676
history(),
7777
closeBrackets(),
7878
bracketMatching(),
79+
highlightActiveLine(),
7980
keymap.of([...historyKeymap, ...completionKeymap, ...defaultKeymap]),
8081
runQueryBinding,
8182
codeMirrorThemeExtension,

src/components/interactive-code-block/result-viewer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from "react"
2-
import { EditorView } from "@codemirror/view"
2+
import { EditorView, highlightActiveLine } from "@codemirror/view"
33
import { EditorState } from "@codemirror/state"
44
// todo: perhaps custom grammar to match the shiki highlighting?
55
import { json } from "@codemirror/lang-json"
@@ -36,6 +36,7 @@ export class ResultViewer extends Component<ResultViewerProps> {
3636
EditorState.readOnly.of(true),
3737
json(),
3838
codeMirrorThemeExtension,
39+
highlightActiveLine(),
3940
],
4041
})
4142

src/components/interactive-code-block/syntax-highlighting.css

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,16 @@
298298
}
299299

300300
/* Active line */
301-
.cm-activeLine {
302-
background-color: rgba(0, 0, 0, 0.05);
301+
.cm-editor:not(.cm-focused) .cm-activeLine {
302+
background: none;
303303
}
304304

305-
.dark .cm-activeLine {
306-
background-color: rgba(255, 255, 255, 0.05);
305+
.cm-focused .cm-activeLine {
306+
background-color: hsl(var(--color-neu-100) / 0.575);
307+
}
308+
309+
.dark .cm-focused .cm-activeLine {
310+
background-color: hsl(var(--color-neu-500) / 0.06);
307311
}
308312

309313
.cm-searchMatch {

src/components/interactive-code-block/variable-editor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from "react"
2-
import { EditorView } from "@codemirror/view"
2+
import { EditorView, highlightActiveLine } from "@codemirror/view"
33
import { EditorState } from "@codemirror/state"
44
import { json } from "@codemirror/lang-json"
55
import { history } from "@codemirror/commands"
@@ -48,6 +48,7 @@ export class VariableEditor extends Component<VariableEditorProps> {
4848
extensions: [
4949
history(),
5050
json(),
51+
highlightActiveLine(),
5152
codeMirrorThemeExtension,
5253
EditorView.updateListener.of(update => {
5354
if (update.docChanged && !this.ignoreChangeEvent) {

0 commit comments

Comments
 (0)