Widget is cut off at end of editor

I’ve added a popup widget that I want to show when text is selected. The code for the widget looks like this:

#selection-popup {
  display: block;
  z-index: 1000;
<div id="selection-popup" cm-ignore-events="true" style="position: absolute; top: 26px; left: 81px;">
    <div class="btn-group">
        <button type="button" class="btn btn-primary">
            <span class="glyphicon glyphicon-comment"></span>
        <button type="button" class="btn btn-primary"></button>
        <button type="button" class="btn btn-primary"></button>

I’m using code like this to attach the widget to a point:

selectionPopup = document.getElementById('selection-popup');
c.addWidget({line: anchor.line, ch: anchor.ch}, selectionPopup);

When I select a line with plenty of space under it, the popup shows just fine, like in this screenshot:

But then, when I select the last line, the popup is cut off:

I assume this has something to do with the div overflowing out of the parent. Any advice on how to handle this?

addWidget will put the DOM node inside of the editor, which is apparently not what you are looking for. You’ll have to overlay it on the editor yourself then, using charCoords to find the proper position.

Rats, thats what I was concerned about. The problem with that, then, is
that when the window is resized, I have to re-calculate the coordinates.
Any advice on that?