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

getContentHeight in @monaco-editor/react does not look correct #442

Open
MatrixFun opened this issue Jan 13, 2023 · 2 comments
Open

getContentHeight in @monaco-editor/react does not look correct #442

MatrixFun opened this issue Jan 13, 2023 · 2 comments

Comments

@MatrixFun
Copy link

MatrixFun commented Jan 13, 2023

I'm trying to use https://github.com/suren-atoyan/monaco-react. But I realize that its getContentHeight does not match the behavior described here.

Here is an example: https://stackblitz.com/edit/react-ts-en8wpm?file=EditorBasic.tsx,App.tsx,index.html. It starts with 500px, once we enter a newline, it becomes 518px, then another newline leads to 536px, etc. From what I understand, getContentHeight should not include the height of the editor.

import * as React from 'react';
import MonacoEditor from '@monaco-editor/react';

export default class EditorBasic extends React.Component<{}, {}> {
  editor: any;

  _handleEditorDidMount(editor, monaco) {
    this.editor = editor;
    this.editor.onDidContentSizeChange(this.handleResize.bind(this));
  }

  updateHeight = () => {
    console.log(
      'this.editor.getContentHeight()',
      this.editor.getContentHeight()
    );
  };

  handleResize() {
    if (this.editor && this.editor !== undefined) {
      this.updateHeight();
    }
  }

  render() {
    return (
      <MonacoEditor
        width="400px"
        height="500px"
        options={{ minimap: { enabled: false }, lineNumbers: 'off' }}
        defaultLanguage="javascript"
        defaultValue="content"
        onMount={this._handleEditorDidMount.bind(this)}
        theme="vs-dark"
      />
    );
  }
}

Does anyone know if it's a bug of @monaco-editor/react? Is there any other API to get the real content height?

(* Link in StackOverflow: https://stackoverflow.com/questions/75105858/getcontentheight-in-monaco-editor-react-does-not-look-correct *)

@danbtl
Copy link

danbtl commented Aug 8, 2023

@MatrixFun did you ever find a workaround for this?

@trm217
Copy link

trm217 commented Oct 3, 2023

same issue here, the value getContentHeight seems to increment whenever you enter a new line, no matter if you delete lines…

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

3 participants