microsoft / microsoft/monaco-editor

[Bug] Re-focusing editor on blur scrolls to the editor on Safari

Open
#4,042 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug editor-core safari
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 example.

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:

  1. Focus the editor
  2. Scroll to the bottom of the preview page
  3. 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.