Skip to content

Commit 9111a23

Browse files
authored
Merge pull request #125 from code-hike/selection-color
Selection color from theme
2 parents 5f18de1 + 592f6f1 commit 9111a23

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

packages/smooth-code/src/code-tween.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
map,
88
FocusString,
99
getCodeColors,
10+
getColor,
11+
ColorName,
1012
} from "@code-hike/utils"
1113
import {
1214
useStepParser,
@@ -140,7 +142,15 @@ function AfterDimensions({
140142
return (
141143
<Wrapper
142144
htmlProps={htmlProps}
143-
style={{ opacity: 1, backgroundColor: bg, color: fg }}
145+
style={{
146+
opacity: 1,
147+
backgroundColor: bg,
148+
color: fg,
149+
["--ch-selection-background" as any]: getColor(
150+
theme,
151+
ColorName.SelectionBackground
152+
),
153+
}}
144154
>
145155
<SmoothLines
146156
codeStep={stepInfo}

packages/smooth-code/src/index.scss

+5
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@
1414
line-height: 19px;
1515
letter-spacing: 0px;
1616
}
17+
18+
.ch-code-scroll-parent ::selection {
19+
background-color: var(--ch-selection-background);
20+
color: inherit;
21+
}

packages/utils/src/theme.ts

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export enum ColorName {
4242
InputForeground,
4343
InputBackground,
4444
InputBorder,
45+
SelectionBackground,
4546
}
4647

4748
type Color = string | undefined
@@ -188,6 +189,15 @@ export function getColor(
188189
hc: contrastBorder,
189190
})
190191
)
192+
case ColorName.SelectionBackground:
193+
return (
194+
colors["editor.selectionBackground"] ||
195+
getDefault(theme, {
196+
light: "#ADD6FF",
197+
dark: "#264F78",
198+
hc: "#f3f518",
199+
})
200+
)
191201
default:
192202
return "#f00"
193203
}

0 commit comments

Comments
 (0)