Skip to content

Commit 53ae28f

Browse files
committed
fix getEditorContentsWithReplDecors for multiline decors
1 parent af044d7 commit 53ae28f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/jsrepl/src/lib/code-editor-utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ export function getEditorContentsWithReplDecors(editor: monaco.editor.ICodeEdito
4242
const lines = contents.split('\n')
4343

4444
const linesWithDecors: string[] = lines.map((line, lineIndex) => {
45-
const lineDecors = editor.getLineDecorations(startLineNumber + lineIndex) ?? []
45+
const lineNumber = startLineNumber + lineIndex
46+
const lineDecors = editor.getLineDecorations(lineNumber) ?? []
4647
const decorValues: string[] = lineDecors
48+
.filter((decor) => decor.range.endLineNumber === lineNumber)
4749
.map((decor) => {
4850
const decorId = decor.options.afterContentClassName?.match(/jsrepl-decor-([0-9]+)/)?.[1]
4951
return decorId ? decorValuesMap[decorId] : null

packages/jsrepl/tests/playwright/repl-eval.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,31 @@ test('stuff', async ({ page }) => {
308308
`
309309
)
310310
})
311+
312+
test('multiline decor', async ({ page }) => {
313+
await visitPlayground(page, {
314+
openedModels: ['/test.ts'],
315+
activeModel: '/test.ts',
316+
showPreview: false,
317+
fs: new ReplFS.FS({
318+
kind: ReplFS.Kind.Directory,
319+
children: {
320+
'test.ts': {
321+
kind: ReplFS.Kind.File,
322+
content: dedent`
323+
console.log(1, 2,
324+
3);
325+
`,
326+
},
327+
},
328+
}),
329+
})
330+
331+
await assertMonacoContentsWithDecors(
332+
page,
333+
dedent`
334+
console.log(1, 2,
335+
3); // → 1 2 3
336+
`
337+
)
338+
})

0 commit comments

Comments
 (0)