@pyreon/code 0.11.4 → 0.11.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -18
- package/lib/analysis/index.js.html +1 -1
- package/lib/index.js +42 -20
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +7 -4
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +28 -28
- package/src/components/code-editor.tsx +4 -4
- package/src/components/diff-editor.tsx +61 -48
- package/src/components/tabbed-editor.tsx +8 -8
- package/src/editor.ts +38 -38
- package/src/index.ts +8 -8
- package/src/languages.ts +19 -19
- package/src/minimap.ts +16 -16
- package/src/tabbed-editor.ts +11 -11
- package/src/tests/code.test.ts +193 -193
- package/src/themes.ts +48 -48
- package/src/types.ts +27 -27
package/src/tests/code.test.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { effect } from
|
|
2
|
-
import { describe, expect, it } from
|
|
3
|
-
import { createEditor } from
|
|
4
|
-
import { getAvailableLanguages } from
|
|
5
|
-
import { createTabbedEditor } from
|
|
6
|
-
|
|
7
|
-
describe(
|
|
8
|
-
describe(
|
|
9
|
-
it(
|
|
1
|
+
import { effect } from '@pyreon/reactivity'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
import { createEditor } from '../editor'
|
|
4
|
+
import { getAvailableLanguages } from '../languages'
|
|
5
|
+
import { createTabbedEditor } from '../tabbed-editor'
|
|
6
|
+
|
|
7
|
+
describe('createEditor', () => {
|
|
8
|
+
describe('initialization', () => {
|
|
9
|
+
it('creates with default values', () => {
|
|
10
10
|
const editor = createEditor()
|
|
11
|
-
expect(editor.value()).toBe(
|
|
12
|
-
expect(editor.language()).toBe(
|
|
11
|
+
expect(editor.value()).toBe('')
|
|
12
|
+
expect(editor.language()).toBe('plain')
|
|
13
13
|
expect(editor.readOnly()).toBe(false)
|
|
14
14
|
expect(editor.focused()).toBe(false)
|
|
15
15
|
expect(editor.view()).toBeNull()
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
it(
|
|
19
|
-
const editor = createEditor({ value:
|
|
20
|
-
expect(editor.value()).toBe(
|
|
18
|
+
it('creates with initial value', () => {
|
|
19
|
+
const editor = createEditor({ value: 'hello world' })
|
|
20
|
+
expect(editor.value()).toBe('hello world')
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
it(
|
|
24
|
-
const editor = createEditor({ language:
|
|
25
|
-
expect(editor.language()).toBe(
|
|
23
|
+
it('creates with language', () => {
|
|
24
|
+
const editor = createEditor({ language: 'typescript' })
|
|
25
|
+
expect(editor.language()).toBe('typescript')
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
it(
|
|
29
|
-
const editor = createEditor({ theme:
|
|
30
|
-
expect(editor.theme()).toBe(
|
|
28
|
+
it('creates with theme', () => {
|
|
29
|
+
const editor = createEditor({ theme: 'dark' })
|
|
30
|
+
expect(editor.theme()).toBe('dark')
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
it(
|
|
33
|
+
it('creates with readOnly', () => {
|
|
34
34
|
const editor = createEditor({ readOnly: true })
|
|
35
35
|
expect(editor.readOnly()).toBe(true)
|
|
36
36
|
})
|
|
37
37
|
|
|
38
|
-
it(
|
|
38
|
+
it('stores config', () => {
|
|
39
39
|
const config = {
|
|
40
|
-
value:
|
|
41
|
-
language:
|
|
42
|
-
theme:
|
|
40
|
+
value: 'test',
|
|
41
|
+
language: 'json' as const,
|
|
42
|
+
theme: 'dark' as const,
|
|
43
43
|
lineNumbers: true,
|
|
44
44
|
tabSize: 4,
|
|
45
45
|
}
|
|
@@ -48,124 +48,124 @@ describe("createEditor", () => {
|
|
|
48
48
|
})
|
|
49
49
|
})
|
|
50
50
|
|
|
51
|
-
describe(
|
|
52
|
-
it(
|
|
53
|
-
const editor = createEditor({ value:
|
|
54
|
-
expect(editor.value()).toBe(
|
|
51
|
+
describe('signal reactivity', () => {
|
|
52
|
+
it('value is a writable signal', () => {
|
|
53
|
+
const editor = createEditor({ value: 'initial' })
|
|
54
|
+
expect(editor.value()).toBe('initial')
|
|
55
55
|
|
|
56
|
-
editor.value.set(
|
|
57
|
-
expect(editor.value()).toBe(
|
|
56
|
+
editor.value.set('updated')
|
|
57
|
+
expect(editor.value()).toBe('updated')
|
|
58
58
|
})
|
|
59
59
|
|
|
60
|
-
it(
|
|
61
|
-
const editor = createEditor({ language:
|
|
62
|
-
editor.language.set(
|
|
63
|
-
expect(editor.language()).toBe(
|
|
60
|
+
it('language is a writable signal', () => {
|
|
61
|
+
const editor = createEditor({ language: 'javascript' })
|
|
62
|
+
editor.language.set('python')
|
|
63
|
+
expect(editor.language()).toBe('python')
|
|
64
64
|
})
|
|
65
65
|
|
|
66
|
-
it(
|
|
67
|
-
const editor = createEditor({ theme:
|
|
68
|
-
editor.theme.set(
|
|
69
|
-
expect(editor.theme()).toBe(
|
|
66
|
+
it('theme is a writable signal', () => {
|
|
67
|
+
const editor = createEditor({ theme: 'light' })
|
|
68
|
+
editor.theme.set('dark')
|
|
69
|
+
expect(editor.theme()).toBe('dark')
|
|
70
70
|
})
|
|
71
71
|
|
|
72
|
-
it(
|
|
72
|
+
it('readOnly is a writable signal', () => {
|
|
73
73
|
const editor = createEditor({ readOnly: false })
|
|
74
74
|
editor.readOnly.set(true)
|
|
75
75
|
expect(editor.readOnly()).toBe(true)
|
|
76
76
|
})
|
|
77
77
|
|
|
78
|
-
it(
|
|
79
|
-
const editor = createEditor({ value:
|
|
78
|
+
it('value is reactive in effects', () => {
|
|
79
|
+
const editor = createEditor({ value: 'a' })
|
|
80
80
|
const values: string[] = []
|
|
81
81
|
|
|
82
82
|
effect(() => {
|
|
83
83
|
values.push(editor.value())
|
|
84
84
|
})
|
|
85
85
|
|
|
86
|
-
editor.value.set(
|
|
87
|
-
editor.value.set(
|
|
86
|
+
editor.value.set('b')
|
|
87
|
+
editor.value.set('c')
|
|
88
88
|
|
|
89
|
-
expect(values).toEqual([
|
|
89
|
+
expect(values).toEqual(['a', 'b', 'c'])
|
|
90
90
|
})
|
|
91
91
|
})
|
|
92
92
|
|
|
93
|
-
describe(
|
|
94
|
-
it(
|
|
93
|
+
describe('computed properties (before mount)', () => {
|
|
94
|
+
it('cursor returns default before mount', () => {
|
|
95
95
|
const editor = createEditor()
|
|
96
96
|
expect(editor.cursor()).toEqual({ line: 1, col: 1 })
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
it(
|
|
99
|
+
it('selection returns default before mount', () => {
|
|
100
100
|
const editor = createEditor()
|
|
101
|
-
expect(editor.selection()).toEqual({ from: 0, to: 0, text:
|
|
101
|
+
expect(editor.selection()).toEqual({ from: 0, to: 0, text: '' })
|
|
102
102
|
})
|
|
103
103
|
|
|
104
|
-
it(
|
|
105
|
-
const editor = createEditor({ value:
|
|
104
|
+
it('lineCount returns initial line count', () => {
|
|
105
|
+
const editor = createEditor({ value: 'line1\nline2\nline3' })
|
|
106
106
|
expect(editor.lineCount()).toBe(3)
|
|
107
107
|
})
|
|
108
108
|
|
|
109
|
-
it(
|
|
110
|
-
const editor = createEditor({ value:
|
|
109
|
+
it('lineCount for single line', () => {
|
|
110
|
+
const editor = createEditor({ value: 'hello' })
|
|
111
111
|
expect(editor.lineCount()).toBe(1)
|
|
112
112
|
})
|
|
113
113
|
|
|
114
|
-
it(
|
|
115
|
-
const editor = createEditor({ value:
|
|
114
|
+
it('lineCount for empty', () => {
|
|
115
|
+
const editor = createEditor({ value: '' })
|
|
116
116
|
expect(editor.lineCount()).toBe(1)
|
|
117
117
|
})
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
-
describe(
|
|
121
|
-
it(
|
|
120
|
+
describe('actions (before mount)', () => {
|
|
121
|
+
it('focus does not throw before mount', () => {
|
|
122
122
|
const editor = createEditor()
|
|
123
123
|
expect(() => editor.focus()).not.toThrow()
|
|
124
124
|
})
|
|
125
125
|
|
|
126
|
-
it(
|
|
126
|
+
it('insert does not throw before mount', () => {
|
|
127
127
|
const editor = createEditor()
|
|
128
|
-
expect(() => editor.insert(
|
|
128
|
+
expect(() => editor.insert('text')).not.toThrow()
|
|
129
129
|
})
|
|
130
130
|
|
|
131
|
-
it(
|
|
131
|
+
it('replaceSelection does not throw before mount', () => {
|
|
132
132
|
const editor = createEditor()
|
|
133
|
-
expect(() => editor.replaceSelection(
|
|
133
|
+
expect(() => editor.replaceSelection('text')).not.toThrow()
|
|
134
134
|
})
|
|
135
135
|
|
|
136
|
-
it(
|
|
136
|
+
it('select does not throw before mount', () => {
|
|
137
137
|
const editor = createEditor()
|
|
138
138
|
expect(() => editor.select(0, 5)).not.toThrow()
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
-
it(
|
|
141
|
+
it('selectAll does not throw before mount', () => {
|
|
142
142
|
const editor = createEditor()
|
|
143
143
|
expect(() => editor.selectAll()).not.toThrow()
|
|
144
144
|
})
|
|
145
145
|
|
|
146
|
-
it(
|
|
146
|
+
it('goToLine does not throw before mount', () => {
|
|
147
147
|
const editor = createEditor()
|
|
148
148
|
expect(() => editor.goToLine(5)).not.toThrow()
|
|
149
149
|
})
|
|
150
150
|
|
|
151
|
-
it(
|
|
151
|
+
it('undo does not throw before mount', () => {
|
|
152
152
|
const editor = createEditor()
|
|
153
153
|
expect(() => editor.undo()).not.toThrow()
|
|
154
154
|
})
|
|
155
155
|
|
|
156
|
-
it(
|
|
156
|
+
it('redo does not throw before mount', () => {
|
|
157
157
|
const editor = createEditor()
|
|
158
158
|
expect(() => editor.redo()).not.toThrow()
|
|
159
159
|
})
|
|
160
160
|
|
|
161
|
-
it(
|
|
161
|
+
it('dispose does not throw before mount', () => {
|
|
162
162
|
const editor = createEditor()
|
|
163
163
|
expect(() => editor.dispose()).not.toThrow()
|
|
164
164
|
})
|
|
165
165
|
})
|
|
166
166
|
|
|
167
|
-
describe(
|
|
168
|
-
it(
|
|
167
|
+
describe('onChange callback', () => {
|
|
168
|
+
it('config stores onChange', () => {
|
|
169
169
|
const onChange = () => {
|
|
170
170
|
/* noop */
|
|
171
171
|
}
|
|
@@ -174,86 +174,86 @@ describe("createEditor", () => {
|
|
|
174
174
|
})
|
|
175
175
|
})
|
|
176
176
|
|
|
177
|
-
describe(
|
|
178
|
-
it(
|
|
177
|
+
describe('new actions (before mount)', () => {
|
|
178
|
+
it('setDiagnostics does not throw before mount', () => {
|
|
179
179
|
const editor = createEditor()
|
|
180
180
|
expect(() =>
|
|
181
|
-
editor.setDiagnostics([{ from: 0, to: 5, severity:
|
|
181
|
+
editor.setDiagnostics([{ from: 0, to: 5, severity: 'error', message: 'test' }]),
|
|
182
182
|
).not.toThrow()
|
|
183
183
|
})
|
|
184
184
|
|
|
185
|
-
it(
|
|
185
|
+
it('clearDiagnostics does not throw before mount', () => {
|
|
186
186
|
const editor = createEditor()
|
|
187
187
|
expect(() => editor.clearDiagnostics()).not.toThrow()
|
|
188
188
|
})
|
|
189
189
|
|
|
190
|
-
it(
|
|
190
|
+
it('highlightLine does not throw before mount', () => {
|
|
191
191
|
const editor = createEditor()
|
|
192
|
-
expect(() => editor.highlightLine(1,
|
|
192
|
+
expect(() => editor.highlightLine(1, 'error-line')).not.toThrow()
|
|
193
193
|
})
|
|
194
194
|
|
|
195
|
-
it(
|
|
195
|
+
it('clearLineHighlights does not throw before mount', () => {
|
|
196
196
|
const editor = createEditor()
|
|
197
197
|
expect(() => editor.clearLineHighlights()).not.toThrow()
|
|
198
198
|
})
|
|
199
199
|
|
|
200
|
-
it(
|
|
200
|
+
it('setGutterMarker does not throw before mount', () => {
|
|
201
201
|
const editor = createEditor()
|
|
202
|
-
expect(() => editor.setGutterMarker(1, { text:
|
|
202
|
+
expect(() => editor.setGutterMarker(1, { text: '🔴', title: 'Breakpoint' })).not.toThrow()
|
|
203
203
|
})
|
|
204
204
|
|
|
205
|
-
it(
|
|
205
|
+
it('clearGutterMarkers does not throw before mount', () => {
|
|
206
206
|
const editor = createEditor()
|
|
207
207
|
expect(() => editor.clearGutterMarkers()).not.toThrow()
|
|
208
208
|
})
|
|
209
209
|
|
|
210
|
-
it(
|
|
210
|
+
it('addKeybinding does not throw before mount', () => {
|
|
211
211
|
const editor = createEditor()
|
|
212
|
-
expect(() => editor.addKeybinding(
|
|
212
|
+
expect(() => editor.addKeybinding('Ctrl-Shift-L', () => true)).not.toThrow()
|
|
213
213
|
})
|
|
214
214
|
|
|
215
|
-
it(
|
|
215
|
+
it('getLine returns empty string before mount', () => {
|
|
216
216
|
const editor = createEditor()
|
|
217
|
-
expect(editor.getLine(1)).toBe(
|
|
217
|
+
expect(editor.getLine(1)).toBe('')
|
|
218
218
|
})
|
|
219
219
|
|
|
220
|
-
it(
|
|
220
|
+
it('getWordAtCursor returns empty string before mount', () => {
|
|
221
221
|
const editor = createEditor()
|
|
222
|
-
expect(editor.getWordAtCursor()).toBe(
|
|
222
|
+
expect(editor.getWordAtCursor()).toBe('')
|
|
223
223
|
})
|
|
224
224
|
|
|
225
|
-
it(
|
|
225
|
+
it('scrollTo does not throw before mount', () => {
|
|
226
226
|
const editor = createEditor()
|
|
227
227
|
expect(() => editor.scrollTo(0)).not.toThrow()
|
|
228
228
|
})
|
|
229
229
|
})
|
|
230
230
|
|
|
231
|
-
describe(
|
|
232
|
-
it(
|
|
231
|
+
describe('config options', () => {
|
|
232
|
+
it('highlightIndentGuides defaults to true', () => {
|
|
233
233
|
const editor = createEditor()
|
|
234
234
|
expect(editor.config.highlightIndentGuides).toBeUndefined() // uses default
|
|
235
235
|
})
|
|
236
236
|
|
|
237
|
-
it(
|
|
237
|
+
it('vim mode can be enabled', () => {
|
|
238
238
|
const editor = createEditor({ vim: true })
|
|
239
239
|
expect(editor.config.vim).toBe(true)
|
|
240
240
|
})
|
|
241
241
|
|
|
242
|
-
it(
|
|
242
|
+
it('emacs mode can be enabled', () => {
|
|
243
243
|
const editor = createEditor({ emacs: true })
|
|
244
244
|
expect(editor.config.emacs).toBe(true)
|
|
245
245
|
})
|
|
246
246
|
|
|
247
|
-
it(
|
|
247
|
+
it('minimap can be enabled', () => {
|
|
248
248
|
const editor = createEditor({ minimap: true })
|
|
249
249
|
expect(editor.config.minimap).toBe(true)
|
|
250
250
|
})
|
|
251
251
|
|
|
252
|
-
it(
|
|
252
|
+
it('all config options are stored', () => {
|
|
253
253
|
const editor = createEditor({
|
|
254
|
-
value:
|
|
255
|
-
language:
|
|
256
|
-
theme:
|
|
254
|
+
value: 'test',
|
|
255
|
+
language: 'typescript',
|
|
256
|
+
theme: 'dark',
|
|
257
257
|
lineNumbers: false,
|
|
258
258
|
readOnly: true,
|
|
259
259
|
foldGutter: false,
|
|
@@ -264,236 +264,236 @@ describe("createEditor", () => {
|
|
|
264
264
|
highlightIndentGuides: false,
|
|
265
265
|
tabSize: 4,
|
|
266
266
|
lineWrapping: true,
|
|
267
|
-
placeholder:
|
|
267
|
+
placeholder: 'Type here...',
|
|
268
268
|
})
|
|
269
269
|
expect(editor.config.tabSize).toBe(4)
|
|
270
270
|
expect(editor.config.lineWrapping).toBe(true)
|
|
271
|
-
expect(editor.config.placeholder).toBe(
|
|
271
|
+
expect(editor.config.placeholder).toBe('Type here...')
|
|
272
272
|
})
|
|
273
273
|
})
|
|
274
274
|
})
|
|
275
275
|
|
|
276
|
-
describe(
|
|
277
|
-
it(
|
|
276
|
+
describe('createTabbedEditor', () => {
|
|
277
|
+
it('creates with initial tabs', () => {
|
|
278
278
|
const te = createTabbedEditor({
|
|
279
279
|
tabs: [
|
|
280
|
-
{ name:
|
|
281
|
-
{ name:
|
|
280
|
+
{ name: 'index.ts', language: 'typescript', value: 'const x = 1' },
|
|
281
|
+
{ name: 'style.css', language: 'css', value: '.app {}' },
|
|
282
282
|
],
|
|
283
283
|
})
|
|
284
284
|
expect(te.tabs()).toHaveLength(2)
|
|
285
|
-
expect(te.activeTabId()).toBe(
|
|
286
|
-
expect(te.activeTab()?.name).toBe(
|
|
287
|
-
expect(te.editor.value()).toBe(
|
|
285
|
+
expect(te.activeTabId()).toBe('index.ts')
|
|
286
|
+
expect(te.activeTab()?.name).toBe('index.ts')
|
|
287
|
+
expect(te.editor.value()).toBe('const x = 1')
|
|
288
288
|
})
|
|
289
289
|
|
|
290
|
-
it(
|
|
290
|
+
it('creates with no tabs', () => {
|
|
291
291
|
const te = createTabbedEditor()
|
|
292
292
|
expect(te.tabs()).toHaveLength(0)
|
|
293
|
-
expect(te.activeTabId()).toBe(
|
|
293
|
+
expect(te.activeTabId()).toBe('')
|
|
294
294
|
expect(te.activeTab()).toBeNull()
|
|
295
295
|
})
|
|
296
296
|
|
|
297
|
-
it(
|
|
297
|
+
it('switchTab changes active tab and editor content', () => {
|
|
298
298
|
const te = createTabbedEditor({
|
|
299
299
|
tabs: [
|
|
300
|
-
{ name:
|
|
301
|
-
{ name:
|
|
300
|
+
{ name: 'a.ts', value: 'aaa' },
|
|
301
|
+
{ name: 'b.ts', value: 'bbb' },
|
|
302
302
|
],
|
|
303
303
|
})
|
|
304
|
-
expect(te.editor.value()).toBe(
|
|
304
|
+
expect(te.editor.value()).toBe('aaa')
|
|
305
305
|
|
|
306
|
-
te.switchTab(
|
|
307
|
-
expect(te.activeTabId()).toBe(
|
|
308
|
-
expect(te.editor.value()).toBe(
|
|
306
|
+
te.switchTab('b.ts')
|
|
307
|
+
expect(te.activeTabId()).toBe('b.ts')
|
|
308
|
+
expect(te.editor.value()).toBe('bbb')
|
|
309
309
|
|
|
310
|
-
te.switchTab(
|
|
311
|
-
expect(te.editor.value()).toBe(
|
|
310
|
+
te.switchTab('a.ts')
|
|
311
|
+
expect(te.editor.value()).toBe('aaa')
|
|
312
312
|
})
|
|
313
313
|
|
|
314
|
-
it(
|
|
314
|
+
it('openTab adds and switches to new tab', () => {
|
|
315
315
|
const te = createTabbedEditor({
|
|
316
|
-
tabs: [{ name:
|
|
316
|
+
tabs: [{ name: 'a.ts', value: 'aaa' }],
|
|
317
317
|
})
|
|
318
318
|
|
|
319
|
-
te.openTab({ name:
|
|
319
|
+
te.openTab({ name: 'b.ts', language: 'typescript', value: 'bbb' })
|
|
320
320
|
expect(te.tabs()).toHaveLength(2)
|
|
321
|
-
expect(te.activeTabId()).toBe(
|
|
322
|
-
expect(te.editor.value()).toBe(
|
|
321
|
+
expect(te.activeTabId()).toBe('b.ts')
|
|
322
|
+
expect(te.editor.value()).toBe('bbb')
|
|
323
323
|
})
|
|
324
324
|
|
|
325
|
-
it(
|
|
325
|
+
it('openTab switches to existing tab', () => {
|
|
326
326
|
const te = createTabbedEditor({
|
|
327
327
|
tabs: [
|
|
328
|
-
{ name:
|
|
329
|
-
{ name:
|
|
328
|
+
{ name: 'a.ts', value: 'aaa' },
|
|
329
|
+
{ name: 'b.ts', value: 'bbb' },
|
|
330
330
|
],
|
|
331
331
|
})
|
|
332
332
|
|
|
333
|
-
te.openTab({ name:
|
|
333
|
+
te.openTab({ name: 'b.ts', value: 'bbb' })
|
|
334
334
|
expect(te.tabs()).toHaveLength(2) // not duplicated
|
|
335
|
-
expect(te.activeTabId()).toBe(
|
|
335
|
+
expect(te.activeTabId()).toBe('b.ts')
|
|
336
336
|
})
|
|
337
337
|
|
|
338
|
-
it(
|
|
338
|
+
it('closeTab removes tab', () => {
|
|
339
339
|
const te = createTabbedEditor({
|
|
340
340
|
tabs: [
|
|
341
|
-
{ name:
|
|
342
|
-
{ name:
|
|
341
|
+
{ name: 'a.ts', value: 'aaa' },
|
|
342
|
+
{ name: 'b.ts', value: 'bbb' },
|
|
343
343
|
],
|
|
344
344
|
})
|
|
345
345
|
|
|
346
|
-
te.closeTab(
|
|
346
|
+
te.closeTab('b.ts')
|
|
347
347
|
expect(te.tabs()).toHaveLength(1)
|
|
348
|
-
expect(te.tabs()[0]!.name).toBe(
|
|
348
|
+
expect(te.tabs()[0]!.name).toBe('a.ts')
|
|
349
349
|
})
|
|
350
350
|
|
|
351
|
-
it(
|
|
351
|
+
it('closeTab switches to adjacent when closing active', () => {
|
|
352
352
|
const te = createTabbedEditor({
|
|
353
353
|
tabs: [
|
|
354
|
-
{ name:
|
|
355
|
-
{ name:
|
|
356
|
-
{ name:
|
|
354
|
+
{ name: 'a.ts', value: 'aaa' },
|
|
355
|
+
{ name: 'b.ts', value: 'bbb' },
|
|
356
|
+
{ name: 'c.ts', value: 'ccc' },
|
|
357
357
|
],
|
|
358
358
|
})
|
|
359
359
|
|
|
360
|
-
te.switchTab(
|
|
361
|
-
te.closeTab(
|
|
360
|
+
te.switchTab('b.ts')
|
|
361
|
+
te.closeTab('b.ts')
|
|
362
362
|
// Should switch to c.ts (next) or a.ts
|
|
363
|
-
expect(te.activeTabId()).not.toBe(
|
|
363
|
+
expect(te.activeTabId()).not.toBe('b.ts')
|
|
364
364
|
expect(te.tabs()).toHaveLength(2)
|
|
365
365
|
})
|
|
366
366
|
|
|
367
|
-
it(
|
|
367
|
+
it('closeTab respects closable: false', () => {
|
|
368
368
|
const te = createTabbedEditor({
|
|
369
|
-
tabs: [{ name:
|
|
369
|
+
tabs: [{ name: 'main.ts', value: 'main', closable: false }],
|
|
370
370
|
})
|
|
371
371
|
|
|
372
|
-
te.closeTab(
|
|
372
|
+
te.closeTab('main.ts')
|
|
373
373
|
expect(te.tabs()).toHaveLength(1) // not closed
|
|
374
374
|
})
|
|
375
375
|
|
|
376
|
-
it(
|
|
376
|
+
it('renameTab changes tab name', () => {
|
|
377
377
|
const te = createTabbedEditor({
|
|
378
|
-
tabs: [{ name:
|
|
378
|
+
tabs: [{ name: 'old.ts', value: '' }],
|
|
379
379
|
})
|
|
380
380
|
|
|
381
|
-
te.renameTab(
|
|
382
|
-
expect(te.tabs()[0]!.name).toBe(
|
|
381
|
+
te.renameTab('old.ts', 'new.ts')
|
|
382
|
+
expect(te.tabs()[0]!.name).toBe('new.ts')
|
|
383
383
|
})
|
|
384
384
|
|
|
385
|
-
it(
|
|
385
|
+
it('setModified marks tab', () => {
|
|
386
386
|
const te = createTabbedEditor({
|
|
387
|
-
tabs: [{ name:
|
|
387
|
+
tabs: [{ name: 'a.ts', value: '' }],
|
|
388
388
|
})
|
|
389
389
|
|
|
390
|
-
te.setModified(
|
|
390
|
+
te.setModified('a.ts', true)
|
|
391
391
|
expect(te.tabs()[0]!.modified).toBe(true)
|
|
392
392
|
|
|
393
|
-
te.setModified(
|
|
393
|
+
te.setModified('a.ts', false)
|
|
394
394
|
expect(te.tabs()[0]!.modified).toBe(false)
|
|
395
395
|
})
|
|
396
396
|
|
|
397
|
-
it(
|
|
397
|
+
it('moveTab reorders tabs', () => {
|
|
398
398
|
const te = createTabbedEditor({
|
|
399
399
|
tabs: [
|
|
400
|
-
{ name:
|
|
401
|
-
{ name:
|
|
402
|
-
{ name:
|
|
400
|
+
{ name: 'a.ts', value: '' },
|
|
401
|
+
{ name: 'b.ts', value: '' },
|
|
402
|
+
{ name: 'c.ts', value: '' },
|
|
403
403
|
],
|
|
404
404
|
})
|
|
405
405
|
|
|
406
406
|
te.moveTab(0, 2)
|
|
407
|
-
expect(te.tabs().map((t: any) => t.name)).toEqual([
|
|
407
|
+
expect(te.tabs().map((t: any) => t.name)).toEqual(['b.ts', 'c.ts', 'a.ts'])
|
|
408
408
|
})
|
|
409
409
|
|
|
410
|
-
it(
|
|
410
|
+
it('getTab returns tab by id', () => {
|
|
411
411
|
const te = createTabbedEditor({
|
|
412
|
-
tabs: [{ name:
|
|
412
|
+
tabs: [{ name: 'a.ts', value: 'content' }],
|
|
413
413
|
})
|
|
414
414
|
|
|
415
|
-
expect(te.getTab(
|
|
416
|
-
expect(te.getTab(
|
|
415
|
+
expect(te.getTab('a.ts')?.value).toBe('content')
|
|
416
|
+
expect(te.getTab('missing')).toBeUndefined()
|
|
417
417
|
})
|
|
418
418
|
|
|
419
|
-
it(
|
|
419
|
+
it('closeAll closes all closable tabs', () => {
|
|
420
420
|
const te = createTabbedEditor({
|
|
421
421
|
tabs: [
|
|
422
|
-
{ name:
|
|
423
|
-
{ name:
|
|
424
|
-
{ name:
|
|
422
|
+
{ name: 'a.ts', value: '', closable: false },
|
|
423
|
+
{ name: 'b.ts', value: '' },
|
|
424
|
+
{ name: 'c.ts', value: '' },
|
|
425
425
|
],
|
|
426
426
|
})
|
|
427
427
|
|
|
428
428
|
te.closeAll()
|
|
429
429
|
expect(te.tabs()).toHaveLength(1)
|
|
430
|
-
expect(te.tabs()[0]!.name).toBe(
|
|
430
|
+
expect(te.tabs()[0]!.name).toBe('a.ts')
|
|
431
431
|
})
|
|
432
432
|
|
|
433
|
-
it(
|
|
433
|
+
it('closeOthers closes all except specified', () => {
|
|
434
434
|
const te = createTabbedEditor({
|
|
435
435
|
tabs: [
|
|
436
|
-
{ name:
|
|
437
|
-
{ name:
|
|
438
|
-
{ name:
|
|
436
|
+
{ name: 'a.ts', value: '' },
|
|
437
|
+
{ name: 'b.ts', value: '' },
|
|
438
|
+
{ name: 'c.ts', value: '' },
|
|
439
439
|
],
|
|
440
440
|
})
|
|
441
441
|
|
|
442
|
-
te.closeOthers(
|
|
442
|
+
te.closeOthers('b.ts')
|
|
443
443
|
expect(te.tabs()).toHaveLength(1)
|
|
444
|
-
expect(te.tabs()[0]!.name).toBe(
|
|
444
|
+
expect(te.tabs()[0]!.name).toBe('b.ts')
|
|
445
445
|
})
|
|
446
446
|
|
|
447
|
-
it(
|
|
447
|
+
it('preserves content when switching tabs', () => {
|
|
448
448
|
const te = createTabbedEditor({
|
|
449
449
|
tabs: [
|
|
450
|
-
{ name:
|
|
451
|
-
{ name:
|
|
450
|
+
{ name: 'a.ts', value: 'original-a' },
|
|
451
|
+
{ name: 'b.ts', value: 'original-b' },
|
|
452
452
|
],
|
|
453
453
|
})
|
|
454
454
|
|
|
455
455
|
// Modify a.ts via signal
|
|
456
|
-
te.editor.value.set(
|
|
456
|
+
te.editor.value.set('modified-a')
|
|
457
457
|
|
|
458
458
|
// Switch to b.ts
|
|
459
|
-
te.switchTab(
|
|
460
|
-
expect(te.editor.value()).toBe(
|
|
459
|
+
te.switchTab('b.ts')
|
|
460
|
+
expect(te.editor.value()).toBe('original-b')
|
|
461
461
|
|
|
462
462
|
// Switch back — should have the modified content
|
|
463
|
-
te.switchTab(
|
|
464
|
-
expect(te.editor.value()).toBe(
|
|
463
|
+
te.switchTab('a.ts')
|
|
464
|
+
expect(te.editor.value()).toBe('modified-a')
|
|
465
465
|
})
|
|
466
466
|
|
|
467
|
-
it(
|
|
467
|
+
it('dispose cleans up', () => {
|
|
468
468
|
const te = createTabbedEditor({
|
|
469
|
-
tabs: [{ name:
|
|
469
|
+
tabs: [{ name: 'a.ts', value: '' }],
|
|
470
470
|
})
|
|
471
471
|
expect(() => te.dispose()).not.toThrow()
|
|
472
472
|
})
|
|
473
473
|
|
|
474
|
-
it(
|
|
474
|
+
it('close last tab clears editor', () => {
|
|
475
475
|
const te = createTabbedEditor({
|
|
476
|
-
tabs: [{ name:
|
|
476
|
+
tabs: [{ name: 'a.ts', value: 'content' }],
|
|
477
477
|
})
|
|
478
478
|
|
|
479
|
-
te.closeTab(
|
|
479
|
+
te.closeTab('a.ts')
|
|
480
480
|
expect(te.tabs()).toHaveLength(0)
|
|
481
|
-
expect(te.activeTabId()).toBe(
|
|
482
|
-
expect(te.editor.value()).toBe(
|
|
481
|
+
expect(te.activeTabId()).toBe('')
|
|
482
|
+
expect(te.editor.value()).toBe('')
|
|
483
483
|
})
|
|
484
484
|
})
|
|
485
485
|
|
|
486
|
-
describe(
|
|
487
|
-
it(
|
|
486
|
+
describe('getAvailableLanguages', () => {
|
|
487
|
+
it('returns all supported languages', () => {
|
|
488
488
|
const langs = getAvailableLanguages()
|
|
489
|
-
expect(langs).toContain(
|
|
490
|
-
expect(langs).toContain(
|
|
491
|
-
expect(langs).toContain(
|
|
492
|
-
expect(langs).toContain(
|
|
493
|
-
expect(langs).toContain(
|
|
494
|
-
expect(langs).toContain(
|
|
495
|
-
expect(langs).toContain(
|
|
496
|
-
expect(langs).toContain(
|
|
489
|
+
expect(langs).toContain('javascript')
|
|
490
|
+
expect(langs).toContain('typescript')
|
|
491
|
+
expect(langs).toContain('html')
|
|
492
|
+
expect(langs).toContain('css')
|
|
493
|
+
expect(langs).toContain('json')
|
|
494
|
+
expect(langs).toContain('python')
|
|
495
|
+
expect(langs).toContain('markdown')
|
|
496
|
+
expect(langs).toContain('plain')
|
|
497
497
|
expect(langs.length).toBeGreaterThanOrEqual(15)
|
|
498
498
|
})
|
|
499
499
|
})
|