microsoft / microsoft/monaco-editor

[Bug] Wrong cursor position if editor has `transform: scale(0.4);`

Open
#4,468 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

Playground Link

Monaco Editor Playground Code
JS:
const value = `'''
Try to click in the area 
between the lines.
The cursor might appear in the wrong 
place
'''

def main():
    print("Hello World!")

if __name__ == "__main__":
    main()
`;

const myEditor = monaco.editor.create(document.getElementById("container"), {
	value,
	language: "python",
	automaticLayout: true,
	fontSize: 30
});

// remeasureFonts() doesn't help
setTimeout(() => {
	console.log('remeasure fonts');
	monaco.editor.remeasureFonts();
}, 1000);
HTML:
<div class="scaled">
    <div id="container" style="height: 100%"></div>
</div>
CSS:
.scaled {
    height: 100%;
    transform: scale(0.4);
}
Reproduction Steps
  1. Apply transform: scale(0.4); to the container with monaco-editor
  2. Click the area BETWEEN any code lines
Actual (Problematic) Behavior
  1. The cursor is placed in an unexpected place 2 lines away from the click
Expected Behavior
  1. The cursor is placed in the line directly above or below the clicked area
Additional Context

https://github.com/microsoft/monaco-editor/assets/2017344/90f90f94-e704-41c3-89fc-7ccd1bbde096

The problem doesn't appear if clicked directly on the line.

Possibly related to https://github.com/microsoft/monaco-editor/issues/2347

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Monaco Editor Playground and reproduce the issue using the provided JavaScript, HTML, and CSS, especially the transform: scale(0.4) container. Investigate cursor placement when clicking between code lines, compare it with clicks directly on a line, and use the expected adjacent-line placement as the completion criterion.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.