Giter VIP home page Giter VIP logo

Comments (6)

satya164 avatar satya164 commented on July 3, 2024 3

Don't set max height and overflow values on the editor directly. Wrap it in a div and set the overflow and height on that.

from react-simple-code-editor.

devenovil avatar devenovil commented on July 3, 2024 3

@devenovil have the same problem。do you have solve it?

nope, i didn't find any solution for fix this bug, yet @satya164 still not re-open this issue

from react-simple-code-editor.

wulucxy avatar wulucxy commented on July 3, 2024 1

@devenovil have the same problem。do you have solve it?

from react-simple-code-editor.

devenovil avatar devenovil commented on July 3, 2024

Owh thanks, for height it works, but for width it's not work, please re-check again and re-open this issue for horizontal wrap

from react-simple-code-editor.

wulucxy avatar wulucxy commented on July 3, 2024

@satya164 horizontal scrollBar still need to be solved。

from react-simple-code-editor.

SzymonNiemiec avatar SzymonNiemiec commented on July 3, 2024

I found a solution, you have to change textarea width and height dynamically. I'm using styled-components that's why I have variable inside CSS.

Add class to Editor to have the possibility to querySelector (tried with useRef hook but couldn't get scrollHeight from ref)

className="simple-editor"

Make two states (in my case initial width is multiplied by 0.55 because I want to cover 55% screen width by editor).

const [textareaHeight, setTextareaHeight] = useState(window.innerHeight);
const [textareaWidth, setTextareaWidth] = useState(window.innerWidth*0.55);

Each time you change the content, change the width and height of the textarea to the same as the editor itself (you can add deboucing)

    useEffect(() => {
        const editorHeight = document.querySelector('.simple-editor').scrollHeight;
        const editorWidth = document.querySelector('.simple-editor').scrollWidth;
        setTextareaHeight(editorHeight);
        setTextareaWidth(editorWidth);
    },[content])

You have to add following styles to the editor:

overflow: auto !important;  
white-space: pre;  
height: 100vh;

To the "pre" element inside Editor:

height: 100vh;
white-space: pre !important;
word-wrap: normal !important;

To the textarea inside Editor:

white-space: pre !important;
word-wrap: normal !important;
height: ${({ textareaHeight }) => textareaHeight}px!important;
width: ${({ textareaWidth }) => textareaWidth}px!important;

from react-simple-code-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.