Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Font size changes after I destroy and create editor instance #4746

Open
1 of 2 tasks
dubrova-ivan opened this issue Nov 11, 2024 · 0 comments
Open
1 of 2 tasks

Comments

@dubrova-ivan
Copy link

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

https://microsoft.github.io/monaco-editor/playground.html?source=v0.52.0#XQAAAAJqBAAAAAAAAABBqQkHQ5NjdVKIfkDi6SE6eJIbQyteFotciG7lKwh8wfIZ36OGD47nBRTK6zV7toIBs2O5GCJoRJ17GWu3dzLMrVeQg8lDNo5C5IsGbN5X3yVU_goa8kylb35AgX74t8fhMsaN38UxRlwliqsgRHk8DKKEdEFxy49_9oP8-yYptg-YyxPV3HkgXmYD4GCxG7xOT0Fl2GSHFKfVgCika6sWhJNLchhy2FKthrpxv8q-oGs9RoVe-fzST8bhsxCMZIaYN3sU_eOkQ0uVAM4K4K5JEZDqfe00scutsdHdg67Y8znXuXetLU7CoWmy10Gc-W5jv0UzVvrAjD_VY_0nBdRJRiL6l8AsBhBSg2OsPLgzgAxyYopcdu5GNtobz7hopLs2tCZL7IlxPujK_pv_NNrKE1KngzKT3FzpuHrf5zUkS5WlH9MoJ2l0bSMSBvN7GT_psjGJjO9p3kE3lkVsRMJyBRrB8mmEHsY_LKVTTOatXVoPokJI7y_qYaGRBQR7BHVfpcVkHF-lkomo0Ujz6O8ZLHQUl3sOMK4n09YJszoHq4lqLbftFmTrXdcN6M-NnSfjxfD5-dDIUS13e7FIIYnHidXqRcRwv1vVDjnviRFLn3F1beuOBhjHsxy5GOTGVNhoa7K99Zu6RRkbbFKFjffhz8DsNJsxqTg1PbbLe0P8DG6iVxTaVSf6pdqYWAHMhy_-_3T7wjg

Monaco Editor Playground Code

let localStorage_fontSize = '';

function createEditor() {
  const options = {
    value: '<div>Some text goes here</div>',
    language: "html",
    fontSize: 12,
  };

  const fontSize = localStorage_fontSize;
  if (fontSize && /\d+(\.\d+)?/.test(fontSize)) {
    options.fontSize = parseFloat(fontSize);
  }

  const editor = monaco.editor.create(document.getElementById("editor"), options);

  // listen font size change and save new value in local storage
  editor.onDidChangeConfiguration((e) => {
    if (!e.hasChanged(monaco.editor.EditorOption.fontSize)) {
      return;
    }

    localStorage_fontSize = editor.getOption(monaco.editor.EditorOption.fontSize).toString();
  });

  return editor;
}

let editor = createEditor();

document.getElementById('create').addEventListener('click', function () {
  editor = createEditor();
});

document.getElementById('destroy').addEventListener('click', function () {
  editor.dispose();
});

Reproduction Steps

  1. Open playground
  2. Increate/decrease font size once
    Image
  3. Click destroy button
  4. Click create button

Actual (Problematic) Behavior

Font size changes twice. Instead of 13.2px (lets assume we are increasing font size and default value was 12px) it becomes 14.52px.
Image

Expected Behavior

The font size does not change after instance re-creation.

Additional Context

It's easy to reproduce when you use any client router and monaco editor at the same time. In my case it's react-router. When I change font size, navigate away from the page and come back - font size changes one more time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant