optional indentation guides in the compose/YAML editor

This commit is contained in:
jarek committed 2026-08-16 08:15:30 +02:00
1 parent cda446a232
commit 0a08c94287
10 files changed
+109 -15

No files matched your search

+21 -3
View File
@@ -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>
+11 -4
View File
@@ -536,8 +536,9 @@ export async function getUserThemePreferences(userId: number): Promise<{
animateIcons: boolean;
coloredActionButtons: boolean;
actionIconSize: string;
editorIndentGuides: boolean;
}> {
const [lightTheme, darkTheme, font, fontSize, gridFontSize, terminalFont, editorFont, animateIcons, coloredActionButtons, actionIconSize] = await Promise.all([
const [lightTheme, darkTheme, font, fontSize, gridFontSize, terminalFont, editorFont, animateIcons, coloredActionButtons, actionIconSize, editorIndentGuides] = await Promise.all([
getUserSetting(userId, 'light_theme'),
getUserSetting(userId, 'dark_theme'),
getUserSetting(userId, 'font'),
@@ -547,7 +548,8 @@ export async function getUserThemePreferences(userId: number): Promise<{
getUserSetting(userId, 'editor_font'),
getUserSetting(userId, 'animate_icons'),
getUserSetting(userId, 'colored_action_buttons'),
getUserSetting(userId, 'action_icon_size')
getUserSetting(userId, 'action_icon_size'),
getUserSetting(userId, 'editor_indent_guides')
]);
return {
lightTheme: lightTheme || 'default',
@@ -561,13 +563,15 @@ export async function getUserThemePreferences(userId: number): Promise<{
animateIcons: animateIcons === 'false' ? false : true,
// Default OFF — only true when explicitly stored
coloredActionButtons: coloredActionButtons === 'true',
actionIconSize: actionIconSize || 'normal'
actionIconSize: actionIconSize || 'normal',
// Default OFF — only true when explicitly stored (#1410)
editorIndentGuides: editorIndentGuides === 'true'
};
}
export async function setUserThemePreferences(
userId: number,
prefs: { lightTheme?: string; darkTheme?: string; font?: string; fontSize?: string; gridFontSize?: string; terminalFont?: string; editorFont?: string; animateIcons?: boolean; coloredActionButtons?: boolean; actionIconSize?: string }
prefs: { lightTheme?: string; darkTheme?: string; font?: string; fontSize?: string; gridFontSize?: string; terminalFont?: string; editorFont?: string; animateIcons?: boolean; coloredActionButtons?: boolean; actionIconSize?: string; editorIndentGuides?: boolean }
): Promise<void> {
const updates: Promise<void>[] = [];
if (prefs.lightTheme !== undefined) {
@@ -600,6 +604,9 @@ export async function setUserThemePreferences(
if (prefs.actionIconSize !== undefined) {
updates.push(setUserSetting(userId, 'action_icon_size', prefs.actionIconSize));
}
if (prefs.editorIndentGuides !== undefined) {
updates.push(setUserSetting(userId, 'editor_indent_guides', prefs.editorIndentGuides ? 'true' : 'false'));
}
await Promise.all(updates);
}
+6 -2
View File
@@ -34,6 +34,7 @@ export interface ThemePreferences {
animateIcons: boolean;
coloredActionButtons: boolean;
actionIconSize: ActionIconSize;
editorIndentGuides: boolean;
}
const STORAGE_KEY = 'dockhand-theme';
@@ -48,7 +49,8 @@ const defaultPrefs: ThemePreferences = {
editorFont: 'system-mono',
animateIcons: true,
coloredActionButtons: false,
actionIconSize: 'normal'
actionIconSize: 'normal',
editorIndentGuides: false
};
// Font size scale mapping
@@ -125,7 +127,9 @@ function createThemeStore() {
: !!(data.animateIcons ?? data.animate_icons),
// Default OFF (#1072)
coloredActionButtons: !!(data.coloredActionButtons ?? data.colored_action_buttons ?? false),
actionIconSize: (data.actionIconSize || data.action_icon_size || 'normal') as ActionIconSize
actionIconSize: (data.actionIconSize || data.action_icon_size || 'normal') as ActionIconSize,
// Default OFF (#1410)
editorIndentGuides: !!(data.editorIndentGuides ?? data.editor_indent_guides ?? false)
};
set(prefs);
saveToStorage(prefs);