Skip to content

Commit af044d7

Browse files
committed
better decor positioning
1 parent 534c1c0 commit af044d7

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

packages/jsrepl/src/hooks/useReplDecorations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default function useReplDecorations() {
8484

8585
const hoverPayloads: ReplPayload[] = getDisplayedPayloads(
8686
(payload) =>
87-
payload.ctx.filePath === model.uri.path && payload.ctx.lineStart === position.lineNumber
87+
payload.ctx.filePath === model.uri.path && payload.ctx.lineEnd === position.lineNumber
8888
)
8989

9090
if (hoverPayloads.length === 0) {

packages/jsrepl/src/lib/bundler/js-esbuild-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,13 @@ function getCommonWrapperFields(
438438
t.objectProperty(
439439
t.identifier('colStart'),
440440
path.node?.loc?.start?.column != null
441-
? t.numericLiteral(path.node.loc.start.column)
441+
? t.numericLiteral(path.node.loc.start.column + 1)
442442
: t.nullLiteral()
443443
),
444444
t.objectProperty(
445445
t.identifier('colEnd'),
446446
path.node?.loc?.end?.column != null
447-
? t.numericLiteral(path.node.loc.end.column)
447+
? t.numericLiteral(path.node.loc.end.column + 1)
448448
: t.nullLiteral()
449449
),
450450
]

packages/jsrepl/src/lib/repl-payload/decorations.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function getDecorDef(
3636
): monaco.editor.IModelDeltaDecoration | null {
3737
try {
3838
const { /* result, */ ctx } = payload
39-
const { lineStart, kind /* lineEnd, colStart, colEnd, source */ } = ctx
39+
const { lineEnd, kind, lineStart, colStart, colEnd /*, source */ } = ctx
4040

4141
decorationUniqId = (decorationUniqId + 1) % Number.MAX_VALUE
4242
const uniqClassName = `jsrepl-decor-${decorationUniqId}`
@@ -51,8 +51,7 @@ function getDecorDef(
5151

5252
return {
5353
// line starts with 1, column starts with 1
54-
// FIXME: sometimes when editing decors rendered shifted. Check token?
55-
range: new monaco!.Range(lineStart, 1, lineStart, 1),
54+
range: new monaco!.Range(lineStart, colStart, lineEnd, colEnd),
5655
options: {
5756
isWholeLine: true,
5857
afterContentClassName: `${codeEditorStyles.jsreplDecor} ${codeEditorStyles[`jsreplDecor-${kind}`] ?? ''} ${uniqClassName} ${isHighlighted ? codeEditorStyles.jsreplDecorHighlighted : ''}`,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ test('simple expressions', async ({ page }) => {
2727
const f2Val = 2;
2828
const [f1, f2 = f2Val, {x: f3}, [f4 = -1], ...f5] = foo();
2929
30-
foo()
31-
;[window.hhh] = foo();
30+
foo();
31+
foo(); [window.hhh] = foo();
3232
window.hadds = foo();
3333
({ x: hhh } = foo({x: 1}));
3434
let h;
@@ -62,8 +62,8 @@ test('simple expressions', async ({ page }) => {
6262
const f2Val = 2; // → f2Val = 2
6363
const [f1, f2 = f2Val, {x: f3}, [f4 = -1], ...f5] = foo(); // → f1 = 1, f2 = 2, f3 = 3, f4 = 4, f5 = [5, 6]
6464
65-
foo() // → [1, undefined, {…}, Array(1), 5, 6]
66-
;[window.hhh] = foo(); // → window.hhh = 1
65+
foo(); // → [1, undefined, {…}, Array(1), 5, 6]
66+
foo(); [window.hhh] = foo(); // → [1, undefined, {…}, Array(1), 5, 6], window.hhh = 1
6767
window.hadds = foo(); // → window.hadds = [1, undefined, {…}, Array(1), 5, 6]
6868
({ x: hhh } = foo({x: 1})); // → hhh = 1
6969
let h; // → h = undefined

0 commit comments

Comments
 (0)