monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

[Bug] editor width is not recalculated after formatting (wrong horizontal scrollbar)

Open ttionya opened this issue 2 years ago • 3 comments

Reproducible in vscode.dev or in VS Code Desktop?

  • [X] Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Code

const editor = monaco.editor.create(document.getElementById('container'), {
	value: "",
	language: 'json',
        scrollBeyondLastLine: false,
});

editor.onDidPaste(() => {
    // I want to do something here, and then
    editor.getAction('editor.action.formatDocument').run()
})

Reproduction Steps

  1. Use the above code and run it
  2. Paste the following code and it will be automatically formatted
{"code":0,"message":"success","data":{"domains":[{"a":1,"b":2,"c":3},{"a":1,"b":2,"c":3},{"a":1,"b":2,"c":3},{"a":1,"b":2,"c":3},{"a":1,"b":2,"c":3},{"a":1,"b":2,"c":3}],"routes":{}}}

The key to reproducing the problem: ensure that the number of rows exceeds one screen after formatting, i.e., a vertical scroll bar appears.

Actual (Problematic) Behavior

Looking at the horizontal scrollbar, even though the horizontal scrollbar should no longer be displayed after formatting, it stays as it was when the json was pasted, with a lot of white space on the right side.

image

Expected Behavior

The width after formatting does not exceed the container width and no horizontal scroll bar should appear.

Even if the content exceeds the container width, the editor width should be shortened to the length of the longest content.

Additional Context

The key to reproducing the problem: ensure that the number of rows exceeds one screen after formatting, i.e., a vertical scroll bar appears.

ttionya avatar Nov 29 '22 16:11 ttionya