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

It takes more space than its contrainer #29

Closed
tylerlong opened this issue Jun 25, 2016 · 19 comments
Closed

It takes more space than its contrainer #29

tylerlong opened this issue Jun 25, 2016 · 19 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug
Milestone

Comments

@tylerlong
Copy link

html,body {
  margin: 0;
  padding: 0;
  border: 0;
  height:100%;
}

#container {
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
  height: 100%;
}

When I run a demo, I can see both horizontal and vertical scroll bars. Which means it takes more space than its container which is not ideal.

@alexdima
Copy link
Member

@tylerlong

The editor uses container.clientWidth and container.clientHeight as the size. Here is the code for reference: https://github.com/Microsoft/vscode/blob/master/src/vs/editor/browser/config/elementSizeObserver.ts#L66

As mentioned in #28 you can call editor.layout() to set the editor to the size you desire:

export interface IDimension {
    width:number;
    height:number;
}

export interface ICodeEditor {
    //...
    /**
     * Instructs the editor to remeasure its container. This method should
     * be called when the container of the editor gets resized.
     */
    layout(dimension?:IDimension): void;
    //...
}

This could also be a bug (maybe the assumption to use clientWidth and clientHeight is wrong?), in which case I would appreciate a full HTML example so I can try running it and checking what happens.

@alexdima alexdima self-assigned this Jun 25, 2016
@tylerlong
Copy link
Author

tylerlong commented Jun 25, 2016

@alexandrudima Here is a full example: https://tylerlong.github.io/monaco-test/editor/ . Source code: https://github.com/tylerlong/monaco-test/tree/gh-pages/editor

I think it should contain no scrollbars out-of-box without I call editor.layout(). It is a bug if it can't layout itself properly during initialization.

I don't see any issues to use clientWidth and clientHeight. But maybe the editor has margins.

@ptyork
Copy link

ptyork commented Jun 25, 2016

@tylerlong, it's a bunch of hidden (but not quite invisible) stuff in their "overflowingContentWidgets" div. The actual editor is the correct height, though. Just set your #container to overflow: hidden and it fixes the problem (I think). I had the same issue with trying to do the 100% height bit with Ace, as well.

@alexandrudima, any reason for the overflow: visible in the .monaco-editor container? Changing that to hidden also fixes the issue, but I'm not sure what other repercussions that might entail.

@MatthewOverall
Copy link

MatthewOverall commented Jul 26, 2016

I ran into this problem and it decided to see how VSCode handles it and found the following style

.monaco-workbench>.editor>.content .editor-container {
  height: calc(100% - 35px);
}

So, try adding this to your container, it resolved my problem. You can obviously drop the leading selectors...

.editor-container {
  height: calc(100% - 35px);
}

or 

#container {
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
  height: calc(100% - 35px);
}

@alexdima alexdima added the bug Issue identified by VS Code Team member as probable bug label Aug 16, 2016
@alexdima alexdima added this to the Backlog milestone Aug 16, 2016
@boljen
Copy link

boljen commented Oct 27, 2016

I've come across a similar bug. The first step was to hide overflow on the editor, as suggested in this thread (.monaco-editor { overflow: hidden; }) There was another issue though; the vertical scroll-bar handle was misaligned.

For some reason the misalignment disappeared after I excluded the foundation-sites css library. It didn't matter in which order this library was loaded, only that it was. (I'm using the most recent one, 6.1.4.)

I also tried including normalize (version shipped with foundation) but that didn't cause any misalignment.

Edit: I narrowed it down to these two rules applied to the global .slider class; https://github.com/zurb/foundation-sites/blob/develop/scss/components/_slider.scss#L24-L25

If you are using foundation-sites, then simply exclude foundation-slider or manually overwrite the slider class for monaco-editor;

.monaco-editor .slider { margin: 0; }

@jannisch
Copy link

It seems like the height: calc(100% - 35px) trick from @MatthewOverall doesn't even work any more (I tested it both in Firefox and Chromium).

Numerous elements in .overflowingContentWidgets are causing the issue, deleting the whole node from dom proves this but breaks all dialogs.

monaco-bug

I inspected all elements which have any height and found these rules to resize them/ position them diffently so that the gap is removed:

.monaco-editor .parameter-hints-widget {
  border: 0px;
}
.monaco-editor .parameter-hints-widget .signature {
  padding: 0px;
}
.monaco-editor .suggest-widget {
  border: 0px;
}
.monaco-editor.vs-dark .suggest-widget {
  border: 0px;
}
.monaco-editor .rename-box {
  top: 0;
}

With those applied, everything seems to work except that obviously some borders are missing in dialogs. Unfortunately I don't know monacos internals (how the whole positioning works) and can't find a connection between the rules at this point to fix the issue.

@jonnermut
Copy link

I couldn't get rid of superflous internal scrolling with any of these workarounds - is this ever likely to be fixed?

@tomdale
Copy link

tomdale commented Jul 2, 2017

@jonnermut Is the issue with superfluous internal scrolling caused by the (on-by-default) scrollBeyondLastLine option? I was also confused about why I couldn't get rid of the scrollbar but I just had to disable this option and I got the auto-expanding-no-scroll behavior I wanted.

    let editor = this.editor = monaco.editor.create(this.element as HTMLElement, {
      model,
      scrollBeyondLastLine: false
    });

@andreujuanc
Copy link

andreujuanc commented Jul 11, 2017

scrollBeyondLastLine: false fixed it. But Should it do that?

EDIT: NOPE, did't fix it. Had to overflow: hidden;

@jonnermut
Copy link

@tomdale that fixed it for me, thank you very much.

@cloverich
Copy link

I think most people here have issue with the vertical scrolling, but my issue was mostly with horizontal scrolling. No matter what size I made the container, it always had a horizontal scrollbar (and was wider than its container). Turned out it was incorrect font-size measurements. This is known and tracked in #392

Using a default font fixed the issue for me. I imagine pre-loading the font would similarly fix the issue but have not tested yet.

@joshmenden
Copy link

This is happening for me too on the vertical scroll when in readonly mode -- when I try to type in the editor, the Cannot edit in Readonly mode dialog pops up adding this additional space at the bottom.

@alexdima alexdima modified the milestones: Backlog, Backlog Candidates Dec 11, 2019
@Micka33
Copy link

Micka33 commented May 12, 2020

Is the issue with superfluous internal scrolling caused by the (on-by-default) scrollBeyondLastLine option?
For me, scrollBeyondLastLine: false didn't fix anything. Monaco is still taller than its container.

I applied overflow: hidden; to the target container in order to get rid of this scroll.
No idea of the repercussion, It must be a difficult bug as it hasn't been fixed since 2016...

@alelevinas
Copy link

+1

@zraineri
Copy link

zraineri commented Sep 7, 2020

@jannisch Life saver, thanks!

@cyberbeast
Copy link

Any fixes for this? I am running into a similar issue with a Flexbox container and the monaco editor takes up more width than the container.

@troy351
Copy link
Contributor

troy351 commented Jan 4, 2021

Works for me.

.monaco-editor.rename-box,
.monaco-hover {
  top: 0;
}

@ghost
Copy link

ghost commented Oct 23, 2021

The following solution avoids modifying the editor using its class names (which aren't guaranteed to be stable) while respecting the contract that the editor will completely fill the node it mounts on,

<div class="editorContainer">
    <div id="editorMountNode" class="editorMountNode" />
</div>

<style>
  .editorContainer {
    overflow: hidden;
    /* add any necessary sizing, like height/width/flex */
  }
  .editorMountNode {
    height: 100%;
  }
</style>

arlosi pushed a commit to arlosi/monaco-editor that referenced this issue Oct 29, 2021
Add HEALTHCHECK as a Dockerfile keyword
alexdima added a commit that referenced this issue Nov 5, 2021
more safe extra lib filePath generation
CGNonofr pushed a commit to CodinGame/monaco-editor that referenced this issue Nov 10, 2021
@hediet
Copy link
Member

hediet commented Feb 24, 2023

Closing due to inactivity.

If this bug still applies, please create a new issue. Make sure to select the form for bugs and include a minimal reproducible example. Thanks!

@hediet hediet closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests