diff --git a/apps/client/src/widgets/type_widgets/code/Code.tsx b/apps/client/src/widgets/type_widgets/code/Code.tsx index ec91a4f836..f5bbc02da6 100644 --- a/apps/client/src/widgets/type_widgets/code/Code.tsx +++ b/apps/client/src/widgets/type_widgets/code/Code.tsx @@ -8,7 +8,7 @@ import appContext, { CommandListenerData } from "../../../components/app_context import FNote from "../../../entities/fnote"; import { t } from "../../../services/i18n"; import utils from "../../../services/utils"; -import { useEditorSpacedUpdate, useKeyboardShortcuts, useLegacyImperativeHandlers, useNoteBlob, useNoteProperty, useSyncedRef, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks"; +import { useEditorSpacedUpdate, useKeyboardShortcuts, useLegacyImperativeHandlers, useNoteBlob, useNoteLabelInt, useNoteProperty, useSyncedRef, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks"; import { refToJQuerySelector } from "../../react/react_utils"; import TouchBar, { TouchBarButton } from "../../react/TouchBar"; import { CODE_THEME_DEFAULT_PREFIX as DEFAULT_PREFIX } from "../constants"; @@ -36,6 +36,7 @@ export interface EditableCodeProps extends TypeWidgetProps, Omit { if (!blob) return; @@ -55,6 +56,7 @@ export function ReadOnlyCode({ note, viewScope, ntxId, parentComponent }: TypeWi content={content} mime={note.mime} readOnly + {...(noteTabWidth != null && { indentSize: noteTabWidth })} /> ); } @@ -79,6 +81,7 @@ export function EditableCode({ note, ntxId, noteContext, debounceUpdate, parentC const editorRef = useRef(null); const containerRef = useRef(null); const [ vimKeymapEnabled ] = useTriliumOptionBool("vimKeymapEnabled"); + const [ noteTabWidth ] = useNoteLabelInt(note, "tabWidth"); const mime = useNoteProperty(note, "mime"); const spacedUpdate = useEditorSpacedUpdate({ note, @@ -129,6 +132,7 @@ export function EditableCode({ note, ntxId, noteContext, debounceUpdate, parentC } }} {...editorProps} + {...(noteTabWidth != null && { indentSize: noteTabWidth })} /> @@ -201,7 +205,7 @@ export function CodeEditor({ parentComponent, ntxId, containerRef: externalConta editorRef={codeEditorRef} containerRef={containerRef} lineWrapping={lineWrapping ?? codeLineWrapEnabled} - indentSize={parseInt(codeNoteTabWidth) || 4} + indentSize={editorProps.indentSize ?? (parseInt(codeNoteTabWidth) || 4)} onInitialized={() => { if (externalContainerRef && containerRef.current) { externalContainerRef.current = containerRef.current; diff --git a/packages/commons/src/lib/attribute_names.ts b/packages/commons/src/lib/attribute_names.ts index 30f65faefe..0442031831 100644 --- a/packages/commons/src/lib/attribute_names.ts +++ b/packages/commons/src/lib/attribute_names.ts @@ -69,6 +69,7 @@ type Labels = { webViewSrc: string; "disabled:webViewSrc": string; readOnly: boolean; + tabWidth: number; mapType: string; mapRootNoteId: string;