Skip to content

Commit cdec83d

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

4 files changed

Lines changed: 28 additions & 13 deletions

File tree

‎package-lock.json‎

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@
112112
"escape-html": "^1.0.3",
113113
"lit": "^3.3.3",
114114
"mime-types": "^3.0.2",
115-
"pane-registry": "5.0.2-1",
115+
"pane-registry": "5.0.2-2",
116116
"rdflib": "2.4.1",
117-
"solid-logic": "6.0.1-4",
117+
"solid-logic": "6.0.1-5",
118118
"solid-namespace": "^0.5.4",
119119
"uuid": "^14.0.0"
120120
},

‎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)