From 695ebdd6856d1c621f994e471166c35779d286ce Mon Sep 17 00:00:00 2001 From: Sharon Stratsianis Date: Sun, 25 Oct 2026 16:02:41 +1100 Subject: [PATCH] make tab work in editor --- src/lib/code-editor/CodeEditor.ts | 3 ++- test/unit/codeEditor.test.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/code-editor/CodeEditor.ts b/src/lib/code-editor/CodeEditor.ts index 8d1cab6a7..20a99a822 100644 --- a/src/lib/code-editor/CodeEditor.ts +++ b/src/lib/code-editor/CodeEditor.ts @@ -2,7 +2,7 @@ import type { ThemeMode } from 'pane-registry' import { Compartment, EditorState } from '@codemirror/state' import { EditorView, drawSelection, keymap, lineNumbers } from '@codemirror/view' import { defaultHighlightStyle, syntaxHighlighting, StreamLanguage } from '@codemirror/language' -import { defaultKeymap, history, historyKeymap } from '@codemirror/commands' +import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands' import { css } from '@codemirror/lang-css' import { html } from '@codemirror/lang-html' import { javascript } from '@codemirror/lang-javascript' @@ -55,6 +55,7 @@ export class CodeEditor { } }), keymap.of([ + indentWithTab, ...defaultKeymap, ...historyKeymap ]) diff --git a/test/unit/codeEditor.test.js b/test/unit/codeEditor.test.js index 872978396..9ba1a1a8e 100644 --- a/test/unit/codeEditor.test.js +++ b/test/unit/codeEditor.test.js @@ -79,7 +79,8 @@ vi.mock('@codemirror/language', () => ({ vi.mock('@codemirror/commands', () => ({ defaultKeymap: [{ key: 'default' }], history: vi.fn(() => ({ type: 'history' })), - historyKeymap: [{ key: 'history' }] + historyKeymap: [{ key: 'history' }], + indentWithTab: { key: 'Tab', run: vi.fn() } })) vi.mock('@codemirror/lang-css', () => ({ @@ -187,4 +188,17 @@ describe('CodeEditor', () => { expect(onDirtyChange).toHaveBeenCalledTimes(1) expect(onDirtyChange).toHaveBeenCalledWith(true) }) + + it('keeps Tab in the editor for indentation', async () => { + const editor = new CodeEditor() + const container = document.createElement('div') + document.body.appendChild(container) + + await editor.initialize(container, 'first', 'text/plain') + + const keymapExtension = createdViews[0].state.extensions.find( + extension => extension.type === 'keymap' + ) + expect(keymapExtension.value[0]).toMatchObject({ key: 'Tab' }) + }) })