import indent with tab into file editor

This commit is contained in:
Sky Mulley
2026-11-10 16:28:05 +00:00
parent e6f1b328f6
commit e7993cb2ef
2 changed files with 22 additions and 0 deletions
@@ -61,6 +61,26 @@ it('runs the latest save handler for Mod-s', () => {
expect(latest).toHaveBeenCalledOnce();
});
it('indents with Tab and outdents with Shift-Tab', () => {
const { container } = render(
<CodemirrorEditor initialContent='alpha' mode='text/plain' onContentSaved={vi.fn()} />
);
const view = viewOf(container);
const content = container.querySelector('.cm-content')!;
act(() => view.dispatch({ selection: { anchor: 0 } }));
act(() => {
content.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', bubbles: true }));
});
expect(view.state.doc.toString()).toBe(' alpha');
act(() => {
content.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', shiftKey: true, bubbles: true }));
});
expect(view.state.doc.toString()).toBe('alpha');
});
it('renders the search and replace panel with theme controls', () => {
const { container } = render(<CodemirrorEditor mode='text/plain' onContentSaved={vi.fn()} />);
@@ -1,5 +1,6 @@
import React, { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
import { basicSetup } from 'codemirror';
import { indentWithTab } from '@codemirror/commands';
import { Compartment, EditorState, Prec } from '@codemirror/state';
import { HighlightStyle, indentUnit, syntaxHighlighting } from '@codemirror/language';
import { EditorView, keymap, type Panel, type ViewUpdate } from '@codemirror/view';
@@ -978,6 +979,7 @@ const createEditorState = (
},
])
),
keymap.of([indentWithTab]),
languageCompartment.of(resolveCodemirrorLanguage(mode)),
EditorView.updateListener.of((update) => {
if (update.docChanged) {