Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

[Panel] onResize does not work with panel addon and height 100% #5995

Closed

Description

@nkappler

we have a div in our webapplication inside which we render codemirror with 100% height.

When not using panels the resize works fine but with a top panel we show for additional script information we face the following issue:

  1. Assuming the browser window is so large that 50 lines fit in the editor without a scroll bar.
  2. Resizing the window -> only 30 lines fit in the remaining space for codemirror

Expected behaviour: Codemirror should resize and show a scroll bar -> all 50 lines can be accessed

Actual behaviour: Codemirror does not resize, last 20 lines are cropped, no scrollbar appears and when you try scrolling to them the whole editor shifts inside its parent container, where it is stuck forever, even after resizing to original window size.

Additional things I observed:
The additional wrapper div that panel.js adds has no height restriction.
It will overflow the parent div (outermost div of codemirror) thus the height comparison doesn't trigger resize event.

I fiddled around with setting this wrapper to 100% height and codemirror to 100% and it made things better, but I couldn't get it to work reliably and exactly as it should.

The codemirror document in the screenshot actually contains 54 lines, but as you can see, you cannot scroll further and 18 lines are cropped of.

image

Activity

  1. nkappler commented on Sep 6, 2019

    @nkappler
    ContributorAuthor

    You can see it here:

    https://jsfiddle.net/xt64L72a/

    When you uncomment the line with myCodeMirror.addPanel(...) it works,
    with the line not commented out, it doesn't work.

    (Just add a few lines and start resizing the height of the viewport)

  2. nkappler commented on Sep 6, 2019

    @nkappler
    ContributorAuthor

    found out that uncommenting this two lines in panel.js fixes it in my case,
    however I am not sure if it might break something else.

      function initPanels(cm) {
        var wrap = cm.getWrapperElement();
        var style = window.getComputedStyle ? window.getComputedStyle(wrap) : wrap.currentStyle;
        var height = parseInt(style.height);
        var info = cm.state.panels = {
          setHeight: wrap.style.height,
          heightLeft: height,
          panels: 0,
          wrapper: document.createElement("div")
        };
        wrap.parentNode.insertBefore(info.wrapper, wrap);
        var hasFocus = cm.hasFocus();
        info.wrapper.appendChild(wrap);
        if (hasFocus) cm.focus();
    
        cm._setSize = cm.setSize;
        if (height != null) cm.setSize = function(width, newHeight) {
          // if (newHeight == null) return this._setSize(width, newHeight);    <----
          info.setHeight = newHeight;
          if (typeof newHeight != "number") {
            var px = /^(\d+\.?\d*)px$/.exec(newHeight);
            if (px) {
              newHeight = Number(px[1]);
            } else {
              info.wrapper.style.height = newHeight;
              newHeight = info.wrapper.offsetHeight;
              // info.wrapper.style.height = "";      <---------------------------------
            }
          }
          cm._setSize(width, info.heightLeft += (newHeight - height));
          height = newHeight;
        };
      }
  3. nkappler commented on Oct 14, 2019

    @nkappler
    ContributorAuthor

    Is the issue not clear or why is this getting no attention?

  4. marijnh commented on Oct 14, 2019

    @marijnh
    Member

    The software doesn't come with a guarantee that all issues will get attention. I'm not very invested in the panel addon, so if you want progress on this, your best bet is to investigate it yourself.

  5. added a commit that references this issue on Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions