Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-monaco-editor text appears in middle of editor despite cursor being at the start of line

I created a simple react app to try and play with react-monaco-editor. Here is my code.

import React, { Component } from 'react';
import MonacoEditor from 'react-monaco-editor';
import './App.css';

const code = `
import React from "react";

class App extends React.Component {
    render() {
        return (
            <span>I mean really come one</span>
        );
    }
}

export default App;
`;

class App extends Component {

  onChange = (value) => {
    console.log(value);
  }

  editorDidMount = (editor, monaco) => {
    console.log('editorDidMount', editor);
    editor.focus();
  }

  render() {
    const options = {
      selectOnLineNumbers: true
    };
    return (
      <div className="App">
        <MonacoEditor
          height="600"
          width="600"
          language="javascript"
          theme="vs-dark"
          value={code}
          onChange={this.onChange}
          editorDidMount={this.editorDidMount}
        />
      </div>
    );
  }
}

export default App;

For some reason tho, the text in the editor is showing up in the middle, and my cursor is as the start of line as expected.

Here is a screenshot of the issue.

editor screenshot

like image 431
Chaim Friedman Avatar asked Jan 18 '19 15:01

Chaim Friedman


1 Answers

This might be an old question but in React in the default App.css there is a line which sets the text-align to center. If it looks similar to this:

.App {
  text-align: center;
}

.App-logo {
  height: 40vmin;
}

.App-header {
  background-color: #282c34;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
  color: white;
}

.App-link {
  color: #09d3ac;
}

you can just delete this part:

.App {
  text-align: center;
}
like image 172
Gergely Tarkó Avatar answered Nov 18 '22 17:11

Gergely Tarkó