optional indentation guides in the compose/YAML editor
This commit is contained in:
10 files changed
+109
-15
No files matched your search
@@ -9,6 +9,9 @@
|
||||
import { searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
||||
import { autocompletion, completionKeymap, closeBrackets, closeBracketsKeymap, type CompletionContext, type CompletionResult } from '@codemirror/autocomplete';
|
||||
import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';
|
||||
import { indentationMarkers } from '@replit/codemirror-indentation-markers';
|
||||
import { themeStore } from '$lib/stores/theme';
|
||||
import { get } from 'svelte/store';
|
||||
import { shell } from '@codemirror/legacy-modes/mode/shell';
|
||||
import { dockerFile } from '@codemirror/legacy-modes/mode/dockerfile';
|
||||
import { toml } from '@codemirror/legacy-modes/mode/toml';
|
||||
@@ -707,6 +710,19 @@
|
||||
EditorView.lineWrapping,
|
||||
EditorState.tabSize.of(2),
|
||||
getLanguageExtension(language),
|
||||
// Vertical indentation guides, opt-in per user (#1410). Subtle tones for both themes.
|
||||
...(get(themeStore).editorIndentGuides
|
||||
? [indentationMarkers({
|
||||
highlightActiveBlock: true,
|
||||
hideFirstIndent: true,
|
||||
colors: {
|
||||
light: '#e2e8f0',
|
||||
dark: '#3a3f4b',
|
||||
activeLight: '#94a3b8',
|
||||
activeDark: '#5b6472'
|
||||
}
|
||||
})]
|
||||
: []),
|
||||
...(language === 'yaml' ? [Prec.high(keymap.of([{ key: 'Enter', run: yamlNewlineAndIndent }]))] : [])
|
||||
].flat();
|
||||
|
||||
@@ -836,16 +852,18 @@
|
||||
// Track previous values for comparison
|
||||
let prevLanguage = $state(language);
|
||||
let prevTheme = $state(theme);
|
||||
let prevIndentGuides = $state($themeStore.editorIndentGuides);
|
||||
|
||||
// Recreate editor if language or theme changes
|
||||
// Recreate editor if language, theme, or the indent-guides preference changes
|
||||
$effect(() => {
|
||||
const currentLanguage = language;
|
||||
const currentTheme = theme;
|
||||
const currentIndentGuides = $themeStore.editorIndentGuides;
|
||||
|
||||
// Only recreate if language or theme actually changed
|
||||
if (view && (currentLanguage !== prevLanguage || currentTheme !== prevTheme)) {
|
||||
if (view && (currentLanguage !== prevLanguage || currentTheme !== prevTheme || currentIndentGuides !== prevIndentGuides)) {
|
||||
prevLanguage = currentLanguage;
|
||||
prevTheme = currentTheme;
|
||||
prevIndentGuides = currentIndentGuides;
|
||||
const currentContent = view.state.doc.toString();
|
||||
destroyEditor();
|
||||
value = currentContent; // Preserve content
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<script lang="ts">
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import { TogglePill } from '$lib/components/ui/toggle-pill';
|
||||
import { themeStore } from '$lib/stores/theme';
|
||||
import { authStore } from '$lib/stores/auth';
|
||||
import { toast } from 'svelte-sonner';
|
||||
|
||||
interface Props {
|
||||
userId?: number; // omit for global default (login page / auth-disabled)
|
||||
}
|
||||
|
||||
let { userId }: Props = $props();
|
||||
|
||||
// Same "skip applying" rule as ThemeSelector: don't touch the live editor when the
|
||||
// admin is editing the global default while logged in (their own per-user preference
|
||||
// still drives their session).
|
||||
const skipApply = $derived($authStore.loading ? true : ($authStore.authEnabled && !userId));
|
||||
|
||||
let checked = $state(false);
|
||||
$effect(() => {
|
||||
checked = $themeStore.editorIndentGuides;
|
||||
});
|
||||
|
||||
function onToggle(value: boolean) {
|
||||
checked = value;
|
||||
themeStore.setPreference('editorIndentGuides', value, userId, skipApply);
|
||||
toast.success(value ? 'Indentation guides enabled' : 'Indentation guides disabled');
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="space-y-1">
|
||||
<div class="flex items-center gap-3">
|
||||
<Label>Indentation guides</Label>
|
||||
<TogglePill {checked} onchange={onToggle} />
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground">Vertical guides showing nesting depth in the code editor.</p>
|
||||
</div>
|
||||
Reference in new issue
Block a user