Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(code): adjustable tab width via attribute
Elian Doran6a05288be416
diff --git a/apps/client/src/widgets/type_widgets/code/Code.tsx b/apps/client/src/widgets/type_widgets/code/Code.tsxindex 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_contextimport 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<CodeEditorPropsexport function ReadOnlyCode({ note, viewScope, ntxId, parentComponent }: TypeWidgetProps) {const [ content, setContent ] = useState("");const blob = useNoteBlob(note);+ const [ noteTabWidth ] = useNoteLabelInt(note, "tabWidth");useEffect(() => {if (!blob) return;@@ -55,6 +56,7 @@ export function ReadOnlyCode({ note, viewScope, ntxId, parentComponent }: TypeWicontent={content}mime={note.mime}readOnly+ {...(noteTabWidth != null && { indentSize: noteTabWidth })}/>);}@@ -79,6 +81,7 @@ export function EditableCode({ note, ntxId, noteContext, debounceUpdate, parentCconst editorRef = useRef<VanillaCodeMirror>(null);const containerRef = useRef<HTMLPreElement>(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 })}/><TouchBar>@@ -201,7 +205,7 @@ export function CodeEditor({ parentComponent, ntxId, containerRef: externalContaeditorRef={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.tsindex 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;