microsoft / microsoft/monaco-editor
[Bug] Re-focusing editor on blur scrolls to the editor on Safari
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?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
Monaco Editor Playground Code
const editor = monaco.editor.create(document.getElementById("container"), {
value: "Hello",
language: "markdown",
});
editor.onDidBlurEditorWidget(() => {
editor.focus();
});
<div id="container"></div>
<div id="page"></div>
<button>Click</button>
body {
overflow: auto;
}
#container {
height: 100px;
}
#page {
height: 2000px;
background: dodgerblue;
}
Reproduction Steps
In Safari:
- Focus the editor
- Scroll to the bottom of the preview page
- Click the button
Actual (Problematic) Behavior
On Safari, clicking the button causes the page to jump to the editor. This is not the case neither in Chrome nor in Firefox.
Expected Behavior
Re-focusing the editor should keep the page position unchanged.
Additional Context
In a local project affected by this behaviour, changing this line to textArea.focus({ preventScroll: true }); fixes the behaviour.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Monaco playground example and inspect the editor focus path corresponding to the referenced textAreaInput.ts line in VS Code. Reproduce the behavior in Safari by clicking the button after scrolling, then verify that refocusing the editor leaves the page position unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100