Skip to content

Commit 70bff5c

Browse files
committed
make tab work in editor
1 parent d8daf98 commit 70bff5c

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎src/lib/code-editor/CodeEditor.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ThemeMode } from 'pane-registry'
22
import { Compartment, EditorState } from '@codemirror/state'
33
import { EditorView, drawSelection, keymap, lineNumbers } from '@codemirror/view'
44
import { defaultHighlightStyle, syntaxHighlighting, StreamLanguage } from '@codemirror/language'
5-
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands'
5+
import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands'
66
import { css } from '@codemirror/lang-css'
77
import { html } from '@codemirror/lang-html'
88
import { javascript } from '@codemirror/lang-javascript'
@@ -55,6 +55,7 @@ export class CodeEditor {
5555
}
5656
}),
5757
keymap.of([
58+
indentWithTab,
5859
...defaultKeymap,
5960
...historyKeymap
6061
])

‎test/unit/codeEditor.test.js‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ vi.mock('@codemirror/language', () => ({
7979
vi.mock('@codemirror/commands', () => ({
8080
defaultKeymap: [{ key: 'default' }],
8181
history: vi.fn(() => ({ type: 'history' })),
82-
historyKeymap: [{ key: 'history' }]
82+
historyKeymap: [{ key: 'history' }],
83+
indentWithTab: { key: 'Tab', run: vi.fn() }
8384
}))
8485

8586
vi.mock('@codemirror/lang-css', () => ({
@@ -187,4 +188,17 @@ describe('CodeEditor', () => {
187188
expect(onDirtyChange).toHaveBeenCalledTimes(1)
188189
expect(onDirtyChange).toHaveBeenCalledWith(true)
189190
})
191+
192+
it('keeps Tab in the editor for indentation', async () => {
193+
const editor = new CodeEditor()
194+
const container = document.createElement('div')
195+
document.body.appendChild(container)
196+
197+
await editor.initialize(container, 'first', 'text/plain')
198+
199+
const keymapExtension = createdViews[0].state.extensions.find(
200+
extension => extension.type === 'keymap'
201+
)
202+
expect(keymapExtension.value[0]).toMatchObject({ key: 'Tab' })
203+
})
190204
})

0 commit comments

Comments
 (0)