(completion, data)
| 13597 | } |
| 13598 | |
| 13599 | function Widget(completion, data) { |
| 13600 | this.completion = completion |
| 13601 | this.data = data |
| 13602 | this.picked = false |
| 13603 | var widget = this, |
| 13604 | cm = completion.cm |
| 13605 | var ownerDocument = cm.getInputField().ownerDocument |
| 13606 | var parentWindow = ownerDocument.defaultView || ownerDocument.parentWindow |
| 13607 | |
| 13608 | var hints = (this.hints = ownerDocument.createElement("ul")) |
| 13609 | var theme = completion.cm.options.theme |
| 13610 | hints.className = "CodeMirror-hints " + theme |
| 13611 | this.selectedHint = data.selectedHint || 0 |
| 13612 | |
| 13613 | var completions = data.list |
| 13614 | for (var i = 0; i < completions.length; ++i) { |
| 13615 | var elt = hints.appendChild(ownerDocument.createElement("li")), |
| 13616 | cur = completions[i] |
| 13617 | var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS) |
| 13618 | if (cur.className != null) className = cur.className + " " + className |
| 13619 | elt.className = className |
| 13620 | if (cur.render) cur.render(elt, data, cur) |
| 13621 | else elt.appendChild(ownerDocument.createTextNode(cur.displayText || getText(cur))) |
| 13622 | elt.hintId = i |
| 13623 | } |
| 13624 | |
| 13625 | var pos = cm.cursorCoords(completion.options.alignWithAtom ? data.from : null) |
| 13626 | var left = pos.left, |
| 13627 | top = pos.bottom, |
| 13628 | below = true |
| 13629 | hints.style.left = left + "px" |
| 13630 | hints.style.top = top + "px" |
| 13631 | // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor. |
| 13632 | var winW = parentWindow.innerWidth || Math.max(ownerDocument.body.offsetWidth, ownerDocument.documentElement.offsetWidth) |
| 13633 | var winH = parentWindow.innerHeight || Math.max(ownerDocument.body.offsetHeight, ownerDocument.documentElement.offsetHeight) |
| 13634 | ;(completion.options.container || ownerDocument.body).appendChild(hints) |
| 13635 | var box = hints.getBoundingClientRect(), |
| 13636 | overlapY = box.bottom - winH |
| 13637 | var scrolls = hints.scrollHeight > hints.clientHeight + 1 |
| 13638 | var startScroll = cm.getScrollInfo() |
| 13639 | |
| 13640 | if (overlapY > 0) { |
| 13641 | var height = box.bottom - box.top, |
| 13642 | curTop = pos.top - (pos.bottom - box.top) |
| 13643 | if (curTop - height > 0) { |
| 13644 | // Fits above cursor |
| 13645 | hints.style.top = (top = pos.top - height) + "px" |
| 13646 | below = false |
| 13647 | } else if (height > winH) { |
| 13648 | hints.style.height = winH - 5 + "px" |
| 13649 | hints.style.top = (top = pos.bottom - box.top) + "px" |
| 13650 | var cursor = cm.getCursor() |
| 13651 | if (data.from.ch != cursor.ch) { |
| 13652 | pos = cm.cursorCoords(cursor) |
| 13653 | hints.style.left = (left = pos.left) + "px" |
| 13654 | box = hints.getBoundingClientRect() |
| 13655 | } |
| 13656 | } |
nothing calls this directly
no test coverage detected