editor.ts

  1import { with_opacity } from "../theme/color"
  2import { Layer, StyleSets } from "../theme/create_theme"
  3import {
  4    background,
  5    border,
  6    border_color,
  7    foreground,
  8    text,
  9} from "./components"
 10import hover_popover from "./hover_popover"
 11
 12import { build_syntax } from "../theme/syntax"
 13import { interactive, toggleable } from "../element"
 14import { useTheme } from "../theme"
 15
 16export default function editor(): any {
 17    const theme = useTheme()
 18
 19    const { is_light } = theme
 20
 21    const layer = theme.highest
 22
 23    const autocomplete_item = {
 24        corner_radius: 6,
 25        padding: {
 26            bottom: 2,
 27            left: 6,
 28            right: 6,
 29            top: 2,
 30        },
 31    }
 32
 33    function diagnostic(layer: Layer, style_set: StyleSets) {
 34        return {
 35            text_scale_factor: 0.857,
 36            header: {
 37                border: border(layer, {
 38                    top: true,
 39                }),
 40            },
 41            message: {
 42                text: text(layer, "sans", style_set, "default", { size: "sm" }),
 43                highlight_text: text(layer, "sans", style_set, "default", {
 44                    size: "sm",
 45                    weight: "bold",
 46                }),
 47            },
 48        }
 49    }
 50
 51    const syntax = build_syntax()
 52
 53    return {
 54        text_color: syntax.primary.color,
 55        background: background(layer),
 56        active_line_background: with_opacity(background(layer, "on"), 0.75),
 57        highlighted_line_background: background(layer, "on"),
 58        // Inline autocomplete suggestions, Co-pilot suggestions, etc.
 59        hint: syntax.hint,
 60        suggestion: syntax.predictive,
 61        code_actions: {
 62            indicator: toggleable({
 63                base: interactive({
 64                    base: {
 65                        color: foreground(layer, "variant"),
 66                    },
 67                    state: {
 68                        hovered: {
 69                            color: foreground(layer, "variant", "hovered"),
 70                        },
 71                        clicked: {
 72                            color: foreground(layer, "variant", "pressed"),
 73                        },
 74                    },
 75                }),
 76                state: {
 77                    active: {
 78                        default: {
 79                            color: foreground(layer, "accent"),
 80                        },
 81                        hovered: {
 82                            color: foreground(layer, "accent", "hovered"),
 83                        },
 84                        clicked: {
 85                            color: foreground(layer, "accent", "pressed"),
 86                        },
 87                    },
 88                },
 89            }),
 90
 91            vertical_scale: 0.55,
 92        },
 93        folds: {
 94            icon_margin_scale: 2.5,
 95            folded_icon: "icons/chevron_right_8.svg",
 96            foldable_icon: "icons/chevron_down_8.svg",
 97            indicator: toggleable({
 98                base: interactive({
 99                    base: {
100                        color: foreground(layer, "variant"),
101                    },
102                    state: {
103                        hovered: {
104                            color: foreground(layer, "on"),
105                        },
106                        clicked: {
107                            color: foreground(layer, "base"),
108                        },
109                    },
110                }),
111                state: {
112                    active: {
113                        default: {
114                            color: foreground(layer, "default"),
115                        },
116                        hovered: {
117                            color: foreground(layer, "variant"),
118                        },
119                    },
120                },
121            }),
122            ellipses: {
123                text_color: theme.ramps.neutral(0.71).hex(),
124                corner_radius_factor: 0.15,
125                background: {
126                    // Copied from hover_popover highlight
127                    default: {
128                        color: theme.ramps.neutral(0.5).alpha(0.0).hex(),
129                    },
130
131                    hovered: {
132                        color: theme.ramps.neutral(0.5).alpha(0.5).hex(),
133                    },
134
135                    clicked: {
136                        color: theme.ramps.neutral(0.5).alpha(0.7).hex(),
137                    },
138                },
139            },
140            fold_background: foreground(layer, "variant"),
141        },
142        diff: {
143            deleted: is_light
144                ? theme.ramps.red(0.5).hex()
145                : theme.ramps.red(0.4).hex(),
146            modified: is_light
147                ? theme.ramps.yellow(0.5).hex()
148                : theme.ramps.yellow(0.5).hex(),
149            inserted: is_light
150                ? theme.ramps.green(0.4).hex()
151                : theme.ramps.green(0.5).hex(),
152            removed_width_em: 0.275,
153            width_em: 0.15,
154            corner_radius: 0.05,
155        },
156        /** Highlights matching occurrences of what is under the cursor
157         * as well as matched brackets
158         */
159        document_highlight_read_background: with_opacity(
160            foreground(layer, "accent"),
161            0.1
162        ),
163        document_highlight_write_background: theme.ramps
164            .neutral(0.5)
165            .alpha(0.4)
166            .hex(), // TODO: This was blend * 2
167        error_color: background(layer, "negative"),
168        gutter_background: background(layer),
169        gutter_padding_factor: 3.5,
170        line_number: with_opacity(foreground(layer), 0.35),
171        line_number_active: foreground(layer),
172        rename_fade: 0.6,
173        unnecessary_code_fade: 0.5,
174        selection: theme.players[0],
175        whitespace: theme.ramps.neutral(0.5).hex(),
176        guest_selections: [
177            theme.players[1],
178            theme.players[2],
179            theme.players[3],
180            theme.players[4],
181            theme.players[5],
182            theme.players[6],
183            theme.players[7],
184        ],
185        autocomplete: {
186            background: background(theme.middle),
187            corner_radius: 8,
188            padding: 4,
189            margin: {
190                left: -14,
191            },
192            border: border(theme.middle),
193            shadow: theme.popover_shadow,
194            match_highlight: foreground(theme.middle, "accent"),
195            item: autocomplete_item,
196            hovered_item: {
197                ...autocomplete_item,
198                match_highlight: foreground(theme.middle, "accent", "hovered"),
199                background: background(theme.middle, "hovered"),
200            },
201            selected_item: {
202                ...autocomplete_item,
203                match_highlight: foreground(theme.middle, "accent", "active"),
204                background: background(theme.middle, "active"),
205            },
206        },
207        diagnostic_header: {
208            background: background(theme.middle),
209            icon_width_factor: 1.5,
210            text_scale_factor: 0.857,
211            border: border(theme.middle, {
212                bottom: true,
213                top: true,
214            }),
215            code: {
216                ...text(theme.middle, "mono", { size: "sm" }),
217                margin: {
218                    left: 10,
219                },
220            },
221            source: {
222                text: text(theme.middle, "sans", {
223                    size: "sm",
224                    weight: "bold",
225                }),
226            },
227            message: {
228                highlight_text: text(theme.middle, "sans", {
229                    size: "sm",
230                    weight: "bold",
231                }),
232                text: text(theme.middle, "sans", { size: "sm" }),
233            },
234        },
235        diagnostic_path_header: {
236            background: background(theme.middle),
237            text_scale_factor: 0.857,
238            filename: text(theme.middle, "mono", { size: "sm" }),
239            path: {
240                ...text(theme.middle, "mono", { size: "sm" }),
241                margin: {
242                    left: 12,
243                },
244            },
245        },
246        error_diagnostic: diagnostic(theme.middle, "negative"),
247        warning_diagnostic: diagnostic(theme.middle, "warning"),
248        information_diagnostic: diagnostic(theme.middle, "accent"),
249        hint_diagnostic: diagnostic(theme.middle, "warning"),
250        invalid_error_diagnostic: diagnostic(theme.middle, "base"),
251        invalid_hint_diagnostic: diagnostic(theme.middle, "base"),
252        invalid_information_diagnostic: diagnostic(theme.middle, "base"),
253        invalid_warning_diagnostic: diagnostic(theme.middle, "base"),
254        hover_popover: hover_popover(),
255        link_definition: {
256            color: syntax.link_uri.color,
257            underline: syntax.link_uri.underline,
258        },
259        jump_icon: interactive({
260            base: {
261                color: foreground(layer, "on"),
262                icon_width: 20,
263                button_width: 20,
264                corner_radius: 6,
265                padding: {
266                    top: 6,
267                    bottom: 6,
268                    left: 6,
269                    right: 6,
270                },
271            },
272            state: {
273                hovered: {
274                    background: background(layer, "on", "hovered"),
275                },
276            },
277        }),
278
279        scrollbar: {
280            width: 12,
281            min_height_factor: 1.0,
282            track: {
283                border: border(layer, "variant", { left: true }),
284            },
285            thumb: {
286                background: with_opacity(background(layer, "inverted"), 0.3),
287                border: {
288                    width: 1,
289                    color: border_color(layer, "variant"),
290                    top: false,
291                    right: true,
292                    left: true,
293                    bottom: false,
294                },
295            },
296            git: {
297                deleted: is_light
298                    ? with_opacity(theme.ramps.red(0.5).hex(), 0.8)
299                    : with_opacity(theme.ramps.red(0.4).hex(), 0.8),
300                modified: is_light
301                    ? with_opacity(theme.ramps.yellow(0.5).hex(), 0.8)
302                    : with_opacity(theme.ramps.yellow(0.4).hex(), 0.8),
303                inserted: is_light
304                    ? with_opacity(theme.ramps.green(0.5).hex(), 0.8)
305                    : with_opacity(theme.ramps.green(0.4).hex(), 0.8),
306            },
307        },
308        composition_mark: {
309            underline: {
310                thickness: 1.0,
311                color: border_color(layer),
312            },
313        },
314        syntax,
315    }
316}